Skip to content

Instantly share code, notes, and snippets.

@bpmutter
Last active February 16, 2023 02:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bpmutter/e63da743d0eb4099159a2f4b25b936ef to your computer and use it in GitHub Desktop.
Save bpmutter/e63da743d0eb4099159a2f4b25b936ef to your computer and use it in GitHub Desktop.
ESLint shared types (generated)
// Generated with ChatGPT from https://github.com/eslint/eslint/blob/main/lib/shared/types.js
/**
* Boolean, "off", "readable", "readonly", "writable", or "writeable".
*/
type GlobalConf = boolean | "off" | "readable" | "readonly" | "writable" | "writeable";
/**
* 0, 1, 2, "off", "warn", or "error".
*/
type SeverityConf = 0 | 1 | 2 | "off" | "warn" | "error";
/**
* SeverityConf or an array of SeverityConf and unknown values.
*/
type RuleConf = SeverityConf | [SeverityConf, ...unknown[]];
/**
* ECMAScript features.
*/
interface EcmaFeatures {
/** Enabling `return` statements at the top-level. */
globalReturn?: boolean;
/** Enabling JSX syntax. */
jsx?: boolean;
/** Enabling strict mode always. */
impliedStrict?: boolean;
}
/**
* Options for parsing code.
*/
interface ParserOptions {
/** The optional ECMAScript features. */
ecmaFeatures?: EcmaFeatures;
/** The ECMAScript version (or revision number). */
ecmaVersion?: 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | 2023;
/** The source code type. */
sourceType?: "script" | "module";
/** Allowing the use of reserved words as identifiers in ES3. */
allowReserved?: boolean;
}
/**
* Options for parsing language.
*/
interface LanguageOptions {
/** The ECMAScript version (or revision number). */
ecmaVersion?: number | "latest";
/** The global variable settings. */
globals?: Record<string, GlobalConf>;
/** The source code type. */
sourceType?: "script" | "module" | "commonjs";
/** The parser to use. */
parser?: string | object;
/** The parser options to use. */
parserOptions?: ParserOptions;
}
/**
* The configuration for linting.
*/
interface ConfigData {
/** The environment settings. */
env?: Record<string, boolean>;
/** The path to other config files or the package name of shareable configs. */
extends?: string | string[];
/** The global variable settings. */
globals?: Record<string, GlobalConf>;
/** The glob patterns that ignore to lint. */
ignorePatterns?: string | string[];
/** The flag that disables directive comments. */
noInlineConfig?: boolean;
/** The override settings per kind of files. */
overrides?: OverrideConfigData[];
/** The path to a parser or the package name of a parser. */
parser?: string;
/** The parser options. */
parserOptions?: ParserOptions;
/** The plugin specifiers. */
plugins?: string[];
/** The processor specifier. */
processor?: string;
/** The flag to report unused `eslint-disable` comments. */
reportUnusedDisableDirectives?: boolean;
/** The root flag. */
root?: boolean;
/** The rule settings. */
rules?: Record<string, RuleConf>;
/** The shared settings. */
settings?: object;
}
/**
* The configuration data for eslint overrides.
*/
type OverrideConfigData = {
/**
* The environment settings.
*/
env?: Record<string, boolean>;
/**
* The glob patterns for excluded files.
*/
excludedFiles?: string | string[];
/**
* The path to other config files or the package name of shareable configs.
*/
extends?: string | string[];
/**
* The glob patterns for target files.
*/
files: string | string[];
/**
* The global variable settings.
*/
globals?: Record<string, GlobalConf>;
/**
* The flag that disables directive comments.
*/
noInlineConfig?: boolean;
/**
* The override settings per kind of files.
*/
overrides?: OverrideConfigData[];
/**
* The path to a parser or the package name of a parser.
*/
parser?: string;
/**
* The parser options.
*/
parserOptions?: ParserOptions;
/**
* The plugin specifiers.
*/
plugins?: string[];
/**
* The processor specifier.
*/
processor?: string;
/**
* The flag to report unused `eslint-disable` comments.
*/
reportUnusedDisableDirectives?: boolean;
/**
* The rule settings.
*/
rules?: Record<string, RuleConf>;
/**
* The shared settings.
*/
settings?: Record<string, any>;
}
/**
* The parse result of a code snippet.
*/
type ParseResult = {
/**
* The AST.
*/
ast: Object;
/**
* The scope manager of the AST.
*/
scopeManager?: ScopeManager;
/**
* The services that the parser provides.
*/
services?: Record<string, any>;
/**
* The visitor keys of the AST.
*/
visitorKeys?: Record<string, string[]>;
}
/**
* The parser for ESLint.
*/
type Parser = {
/**
* The function to parse a code snippet and return the AST.
*/
parse: (text: string, options: ParserOptions) => Object;
/**
* The function to parse a code snippet and return the parse result.
*/
parseForESLint?: (text: string, options: ParserOptions) => ParseResult;
}
/**
* The environment for ESLint.
*/
type Environment = {
/**
* The definition of global variables.
*/
globals?: Record<string, GlobalConf>;
/**
* The parser options that will be enabled under this environment.
*/
parserOptions?: ParserOptions;
}
/**
* A linting message.
*/
type LintMessage = {
/**
* The 1-based column number.
*/
column?: number;
/**
* The 1-based column number of the end location.
*/
endColumn?: number;
/**
* The 1-based line number of the end location.
*/
endLine?: number;
/**
* If `true` then this is a fatal error.
*/
fatal: boolean;
/**
* Information for autofix.
*/
fix?: {
range: [number, number];
text: string;
};
/**
* The 1-based line number.
*/
line?: number;
/**
* The error message.
*/
message: string;
/**
* The ID of the rule which makes this message.
*/
ruleId: string | null;
/**
* The severity of this message.
*/
severity: 0 | 1 | 2;
/**
* Information for suggestions.
*/
suggestions?: Array<{
desc?: string;
messageId?: string;
fix: {
range: [number, number];
text: string;
};
}>;
};
/**
* A suppressed linting message.
*/
type SuppressedLintMessage = LintMessage & {
/**
* The suppression info.
*/
suppressions: Array<{
kind: string;
justification: string;
}>;
};
/**
* A suggestion result.
*/
type SuggestionResult = {
/**
* A short description.
*/
desc: string;
/**
* Id referencing a message for the description.
*/
messageId?: string;
/**
* Fix result info.
*/
fix: {
text: string;
range: number[];
};
};
/**
* A processor for linting messages.
*/
type Processor = {
/**
* The function to extract code blocks.
*/
preprocess?: (text: string, filename: string) => Array<string | { text: string; filename: string }>;
/**
* The function to merge messages.
*/
postprocess?: (messagesList: LintMessage[][], filename: string) => LintMessage[];
/**
* If `true` then it means the processor supports autofix.
*/
supportsAutofix?: boolean;
};
/**
* Document information of a rule.
*/
type RuleMetaDocs = {
description: string; // The description of the rule.
recommended: boolean; // If `true` then the rule is included in `eslint:recommended` preset.
url: string; // The URL of the rule documentation.
}
/**
* Metadata of a rule.
*/
type RuleMeta = {
deprecated?: boolean; // If `true` then the rule has been deprecated.
docs: RuleMetaDocs; // The document information of the rule.
fixable?: "code" | "whitespace"; // The autofix type.
hasSuggestions?: boolean; // If `true` then the rule provides suggestions.
messages?: Record<string, string>; // The messages the rule reports.
replacedBy?: string[]; // The IDs of the alternative rules.
schema: Array<any> | Record<string, any>; // The option schema of the rule.
type: "problem" | "suggestion" | "layout"; // The rule type.
}
/**
* A rule in ESLint.
*/
type Rule = {
create: Function; // The factory of the rule.
meta: RuleMeta; // The meta data of the rule.
}
/**
* Information about a plugin in ESLint.
*/
type Plugin = {
configs?: Record<string, ConfigData>; // The definition of plugin configs.
environments?: Record<string, Environment>; // The definition of plugin environments.
processors?: Record<string, Processor>; // The definition of plugin processors.
rules?: Record<string, Function | Rule>; // The definition of plugin rules.
}
/**
* Information about a deprecated rule.
*/
type DeprecatedRuleInfo = {
ruleId: string; // The rule ID.
replacedBy: string[]; // The rule IDs that replace this deprecated rule.
}
/**
* A linting result in ESLint.
*/
type LintResult = {
filePath: string; // The path to the file that was linted.
messages: LintMessage[]; // All of the messages for the result.
suppressedMessages: SuppressedLintMessage[]; // All of the suppressed messages for the result.
errorCount: number; // Number of errors for the result.
fatalErrorCount: number; // Number of fatal errors for the result.
warningCount: number; // Number of warnings for the result.
fixableErrorCount: number; // Number of fixable errors for the result.
fixableWarningCount: number; // Number of fixable warnings for the result.
source?: string; // The source code of the file that was linted.
output?: string; // The source code of the file that was linted, with as many fixes applied as possible.
usedDeprecatedRules: DeprecatedRuleInfo[]; // The list of used deprecated rules.
}
/**
* Information provided when the maximum warning threshold is exceeded.
*/
type MaxWarningsExceeded = {
maxWarnings: number; // Number of warnings to trigger nonzero exit code.
foundWarnings: number; // Number of warnings found while linting.
}
/**
* Metadata about results for formatters.
*/
type ResultsMeta = {
maxWarningsExceeded?: MaxWarningsExceeded; // Present if the maxWarnings threshold was exceeded.
}
/**
* A formatter function for ESLint.
*/
type FormatterFunction = (results: LintResult[], context?: {
cwd: string;
maxWarningsExceeded?: MaxWarningsExceeded;
rulesMeta: Record<string, RuleMeta>;
}) => string | Promise<string>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment