Last active
September 27, 2021 15:55
-
-
Save exuanbo/79d6fcd2c617f03ec530106bfe46d7a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ESLint } from 'eslint'; | |
declare type CLIOptions = Partial<{ | |
[key in 'cmd' | 'version' | 'tagline' | 'bugs' | 'homepage']: string; | |
}>; | |
declare type ProvidedESLintOptions = Omit<ESLint.Options, 'cwd' | 'resolvePluginsRelativeTo'>; | |
interface ProvidedOptions extends CLIOptions { | |
[key: string]: unknown; | |
ESLint: typeof ESLint; | |
eslintOptions?: Partial<ProvidedESLintOptions>; | |
cwd?: string; | |
extensions?: string[]; | |
ignore?: string[]; | |
configFile?: string; | |
fix?: boolean; | |
} | |
declare type PartiallyRequired<T, K extends keyof T> = Omit<T, K> & Pick<Required<T>, K>; | |
declare type ESLintOptions = PartiallyRequired<ProvidedESLintOptions, 'extensions' | 'baseConfig' | 'useEslintrc' | 'fix' | 'cache' | 'cacheLocation'>; | |
declare class Options { | |
cmd: string; | |
version: string; | |
tagline: string; | |
bugs: string; | |
homepage: string; | |
ESLint: ProvidedOptions['ESLint']; | |
eslintOptions: ESLintOptions; | |
constructor({ cmd, version, tagline, bugs, homepage, ESLint, eslintOptions, cwd, extensions, ignore, configFile, fix }: ProvidedOptions); | |
} | |
declare type LintCallback = (err: unknown, result: ESLint.LintResult[] | null, code?: string) => void; | |
declare class Linter { | |
private readonly ESLint; | |
private readonly eslint; | |
options: ESLintOptions; | |
constructor(ESLint: typeof ESLint, options: ESLintOptions); | |
lintText: (code: string, cb?: string | LintCallback | undefined, filePath?: string | undefined) => Promise<void>; | |
lintFiles: (files: string | string[], cb?: LintCallback | undefined) => Promise<void>; | |
} | |
declare const MINIMIST_OPTS: { | |
string: ("plugins" | "env" | "ext" | "globals" | "parser")[]; | |
boolean: ("version" | "fix" | "disable-gitignore" | "help" | "stdin")[]; | |
alias: { | |
env: string; | |
globals: string; | |
help: string; | |
plugins: string; | |
version: string; | |
}; | |
}; | |
declare type StringArgs = { | |
[s in typeof MINIMIST_OPTS.string[number]]?: string | string[]; | |
}; | |
declare type BooleanArgs = { | |
[b in typeof MINIMIST_OPTS.boolean[number]]?: boolean; | |
}; | |
interface DefaultArgs { | |
_: string[]; | |
} | |
interface ParsedArgs extends BooleanArgs, StringArgs, DefaultArgs { | |
} | |
declare abstract class CLIEngine { | |
linter: Linter; | |
options: Options; | |
onFinish: LintCallback; | |
protected abstract onError(err: unknown): void; | |
protected abstract onResult(res: ESLint.LintResult[], code?: string): void; | |
constructor(linter: Linter, options: Options); | |
} | |
declare class CLI extends CLIEngine { | |
argv: ParsedArgs; | |
constructor(providedOptions: ProvidedOptions); | |
protected onError(err: unknown): void; | |
protected onResult(lintResults: ESLint.LintResult[], code?: string): void; | |
} | |
declare const run: (providedOptions: ProvidedOptions) => Promise<void>; | |
declare const getRootPath: () => string | null; | |
declare const readFileFromRoot: (file: string) => string | null; | |
declare type Obj = Record<string, unknown>; | |
declare const mergeConfig: (target: Obj, ...sources: Array<Obj | undefined>) => any; | |
export { CLI, CLIEngine, ESLintOptions, LintCallback, Linter, Options, ProvidedOptions, getRootPath, mergeConfig, readFileFromRoot, run }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment