UNPKG

xo

Version:

JavaScript/TypeScript linter (ESLint wrapper) with great defaults

104 lines (98 loc) 3.49 kB
import { ESLint, type Linter } from 'eslint'; import prettier from 'prettier'; import { type XoLintResult, type LinterOptions, type LintTextOptions, type XoConfigOptions, type XoConfigItem } from './types.js'; import { xoToEslintConfig } from './xo-to-eslint.js'; export declare class Xo { /** Static helper to convert an XO config to an ESLint config to be used in `eslint.config.js`. */ static xoToEslintConfig: typeof xoToEslintConfig; /** Static helper for backwards compatibility and use in editor extensions and other tools. */ static lintText(code: string, options: LintTextOptions & LinterOptions & XoConfigOptions): Promise<XoLintResult>; /** Static helper for backwards compatibility and use in editor extensions and other tools. */ static lintFiles(globs: string | undefined, options: LinterOptions & XoConfigOptions): Promise<XoLintResult>; /** Write the fixes to disk. */ static outputFixes(results: XoLintResult): Promise<void>; /** Required linter options: `cwd`, `fix`, and `filePath` (in case of `lintText`). */ linterOptions: LinterOptions; /** Base XO config options that allow configuration from CLI or other sources. Not to be confused with the `xoConfig` property which is the resolved XO config from the flat config AND base config. */ baseXoConfig: XoConfigOptions; /** File path to the ESLint cache. */ cacheLocation: string; /** A re-usable ESLint instance configured with options calculated from the XO config. */ eslint?: ESLint; /** XO config derived from both the base config and the resolved flat config. */ xoConfig?: XoConfigItem[]; /** The ESLint config calculated from the resolved XO config. */ eslintConfig?: Linter.Config[]; /** The flat XO config path, if there is one. */ flatConfigPath?: string | undefined; /** If any user configs container Prettier, we will need to fetch the Prettier config. */ prettier?: boolean; /** The Prettier config if it exists and is needed. */ prettierConfig?: prettier.Options; constructor(_linterOptions: LinterOptions, _baseXoConfig?: XoConfigOptions); /** Sets the XO config on the XO instance. @private */ setXoConfig(): Promise<void>; /** Sets the ESLint config on the XO instance. @private */ setEslintConfig(): void; /** Sets the ignores on the XO instance. @private */ setIgnores(): void; /** Checks every TS file to ensure its included in the tsconfig and any that are not included are added to a generated tsconfig for type aware linting. @param files - The TypeScript files being linted. */ handleUnincludedTsFiles(files?: string[]): Promise<void>; /** Initializes the ESLint instance on the XO instance. */ initEslint(files?: string[]): Promise<void>; /** Lints the files on the XO instance. @param globs - Glob pattern to pass to `globby`. @throws Error */ lintFiles(globs?: string | string[]): Promise<XoLintResult>; /** Lints the text on the XO instance. */ lintText(code: string, lintTextOptions: LintTextOptions): Promise<XoLintResult>; calculateConfigForFile(filePath: string): Promise<Linter.Config>; getFormatter(name: string): Promise<ESLint.LoadedFormatter>; private processReport; private getReportStatistics; } export default Xo;