UNPKG

xo

Version:

JavaScript/TypeScript linter (ESLint wrapper) with great defaults

75 lines (71 loc) 3.42 kB
import { ESLint, type Linter } from 'eslint'; import { type XoLintResult, type LinterOptions, type LintTextOptions, type XoConfigOptions } from './types.js'; export declare const ignoredFileWarningMessage = "File ignored because of a matching ignore pattern."; export declare const noFilesFoundErrorMessage = "No files matching the pattern were found."; export declare class Xo { #private; /** 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>; constructor(_linterOptions: LinterOptions, _baseXoConfig?: XoConfigOptions); /** Initializes the ESLint flat config on the XO instance. */ private prepareEslintConfig; private discoverFiles; /** Add unincluded files to the config with a generated tsconfig approach. Passing an empty array removes the generated config entry. This uses `parserOptions.project` rather than an in-memory `parserOptions.programs`. A pre-built program's AST is built once from the original file text and is never updated between ESLint's multiple `--fix` passes, so stale offsets corrupt the output. A file-based project is re-read on each pass, so autofix stays correct. */ private addUnincludedFilesToConfig; private processReport; private getReportStatistics; /** Throws if a suppressions location was provided but the file does not exist. */ private assertSuppressionsFileExists; /** Sets the XO config on the XO instance. */ setXoConfig(): Promise<void>; setEslintConfig(cliIgnores?: string[], shouldStripDefaultIgnores?: boolean): void; /** Ensures the cache directory exists. This needs to run once before both tsconfig handling and running ESLint occur. */ ensureCacheDirectory(): Promise<void>; /** Checks every TS file to ensure it is included in the tsconfig. Any that are not included are routed through a generated tsconfig (`tsconfig.generated.json`) so that autofix works correctly across multiple ESLint passes. @param files - The TypeScript files being linted. */ handleUnincludedTsFiles(files?: string[]): Promise<void>; /** Initializes the ESLint instance on the XO instance. */ initEslint(files?: string[], cliIgnores?: string[], shouldStripDefaultIgnores?: boolean): Promise<void>; /** Create an ESLint flat config for editor integrations using the same XO pipeline as the CLI. */ getProjectEslintConfig(): Promise<Linter.Config[]>; /** 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>; } export default Xo;