interface File { type: 'file'; path: string; } interface Folder { type: 'folder'; path: string; children: Array; } type BaseRuleOptions = Record; interface Rule { /** Short code name for the rule. */ name: RuleName; check: (this: Context, root: Folder, ruleOptions: RuleOptions) => RuleResult | Promise; } interface RuleResult { diagnostics: Array; } interface PartialDiagnostic { message: string; fixes?: Array; location: { /** Absolute path to a folder or a file that contains the issue. */ path: string; line?: number; column?: number; }; } interface Diagnostic extends PartialDiagnostic { ruleName: string; severity: Exclude; getRuleDescriptionUrl(ruleName: string): URL; } type Fix = { type: 'rename'; path: string; newName: string; } | { type: 'create-file'; path: string; content: string; } | { type: 'create-folder'; path: string; } | { type: 'delete'; path: string; } | { type: 'modify-file'; path: string; content: string; }; type Config> = Array | Plugin | GlobalIgnore>; type Severity = 'off' | 'warn' | 'error'; /** * Extracts a union of rule names from a given tuple of `Rule` objects. * * @example * type Context = unknown * type Options = BaseRuleOptions * type Result = RuleNames<[Rule, Rule]> * // Result is 'foo' | 'bar' */ type RuleNames> = Rules[number]['name']; type LookUpByName = Union extends { name: Name; } ? Union : never; /** * Looks up a rule in a tuple of rules by name and then extracts that rule's options type. * * @example * type Context = unknown * type Rules = [Rule, Rule] * type Result = OptionsForRule * // Result is { foo: string } */ type OptionsForRule, RuleName extends RuleNames> = LookUpByName extends Rule ? Options : never; interface ConfigObject> { /** Globs of files to check. */ files?: Array; /** Globs of files to ignore. */ ignores?: Array; /** Severity of rules and individual rule options. */ rules: { [key in RuleNames]?: Severity | [Severity, OptionsForRule]; }; } type GlobalIgnore = { ignores: Array; }; interface Plugin> = Array> { meta: { name: string; version: string; }; ruleDefinitions: Rules; } export type { BaseRuleOptions as B, ConfigObject as C, Diagnostic as D, Folder as F, GlobalIgnore as G, OptionsForRule as O, Plugin as P, Rule as R, Severity as S, File as a, Config as b, RuleResult as c, PartialDiagnostic as d, Fix as e, RuleNames as f };