]> git.proxmox.com Git - pve-eslint.git/blob - eslint/lib/shared/types.js
ab59207a6b116432a2d86e036e0737b3ce8817ba
[pve-eslint.git] / eslint / lib / shared / types.js
1 /**
2 * @fileoverview Define common types for input completion.
3 * @author Toru Nagashima <https://github.com/mysticatea>
4 */
5 "use strict";
6
7 /** @type {any} */
8 module.exports = {};
9
10 /** @typedef {boolean | "off" | "readable" | "readonly" | "writable" | "writeable"} GlobalConf */
11 /** @typedef {0 | 1 | 2 | "off" | "warn" | "error"} SeverityConf */
12 /** @typedef {SeverityConf | [SeverityConf, ...any[]]} RuleConf */
13
14 /**
15 * @typedef {Object} EcmaFeatures
16 * @property {boolean} [globalReturn] Enabling `return` statements at the top-level.
17 * @property {boolean} [jsx] Enabling JSX syntax.
18 * @property {boolean} [impliedStrict] Enabling strict mode always.
19 */
20
21 /**
22 * @typedef {Object} ParserOptions
23 * @property {EcmaFeatures} [ecmaFeatures] The optional features.
24 * @property {3|5|6|7|8|9|10|11|12|13|2015|2016|2017|2018|2019|2020|2021|2022} [ecmaVersion] The ECMAScript version (or revision number).
25 * @property {"script"|"module"} [sourceType] The source code type.
26 * @property {boolean} [allowReserved] Allowing the use of reserved words as identifiers in ES3.
27 */
28
29 /**
30 * @typedef {Object} LanguageOptions
31 * @property {number|"latest"} [ecmaVersion] The ECMAScript version (or revision number).
32 * @property {Record<string, GlobalConf>} [globals] The global variable settings.
33 * @property {"script"|"module"|"commonjs"} [sourceType] The source code type.
34 * @property {string|Object} [parser] The parser to use.
35 * @property {Object} [parserOptions] The parser options to use.
36 */
37
38 /**
39 * @typedef {Object} ConfigData
40 * @property {Record<string, boolean>} [env] The environment settings.
41 * @property {string | string[]} [extends] The path to other config files or the package name of shareable configs.
42 * @property {Record<string, GlobalConf>} [globals] The global variable settings.
43 * @property {string | string[]} [ignorePatterns] The glob patterns that ignore to lint.
44 * @property {boolean} [noInlineConfig] The flag that disables directive comments.
45 * @property {OverrideConfigData[]} [overrides] The override settings per kind of files.
46 * @property {string} [parser] The path to a parser or the package name of a parser.
47 * @property {ParserOptions} [parserOptions] The parser options.
48 * @property {string[]} [plugins] The plugin specifiers.
49 * @property {string} [processor] The processor specifier.
50 * @property {boolean} [reportUnusedDisableDirectives] The flag to report unused `eslint-disable` comments.
51 * @property {boolean} [root] The root flag.
52 * @property {Record<string, RuleConf>} [rules] The rule settings.
53 * @property {Object} [settings] The shared settings.
54 */
55
56 /**
57 * @typedef {Object} OverrideConfigData
58 * @property {Record<string, boolean>} [env] The environment settings.
59 * @property {string | string[]} [excludedFiles] The glob patterns for excluded files.
60 * @property {string | string[]} [extends] The path to other config files or the package name of shareable configs.
61 * @property {string | string[]} files The glob patterns for target files.
62 * @property {Record<string, GlobalConf>} [globals] The global variable settings.
63 * @property {boolean} [noInlineConfig] The flag that disables directive comments.
64 * @property {OverrideConfigData[]} [overrides] The override settings per kind of files.
65 * @property {string} [parser] The path to a parser or the package name of a parser.
66 * @property {ParserOptions} [parserOptions] The parser options.
67 * @property {string[]} [plugins] The plugin specifiers.
68 * @property {string} [processor] The processor specifier.
69 * @property {boolean} [reportUnusedDisableDirectives] The flag to report unused `eslint-disable` comments.
70 * @property {Record<string, RuleConf>} [rules] The rule settings.
71 * @property {Object} [settings] The shared settings.
72 */
73
74 /**
75 * @typedef {Object} ParseResult
76 * @property {Object} ast The AST.
77 * @property {ScopeManager} [scopeManager] The scope manager of the AST.
78 * @property {Record<string, any>} [services] The services that the parser provides.
79 * @property {Record<string, string[]>} [visitorKeys] The visitor keys of the AST.
80 */
81
82 /**
83 * @typedef {Object} Parser
84 * @property {(text:string, options:ParserOptions) => Object} parse The definition of global variables.
85 * @property {(text:string, options:ParserOptions) => ParseResult} [parseForESLint] The parser options that will be enabled under this environment.
86 */
87
88 /**
89 * @typedef {Object} Environment
90 * @property {Record<string, GlobalConf>} [globals] The definition of global variables.
91 * @property {ParserOptions} [parserOptions] The parser options that will be enabled under this environment.
92 */
93
94 /**
95 * @typedef {Object} LintMessage
96 * @property {number|undefined} column The 1-based column number.
97 * @property {number} [endColumn] The 1-based column number of the end location.
98 * @property {number} [endLine] The 1-based line number of the end location.
99 * @property {boolean} fatal If `true` then this is a fatal error.
100 * @property {{range:[number,number], text:string}} [fix] Information for autofix.
101 * @property {number|undefined} line The 1-based line number.
102 * @property {string} message The error message.
103 * @property {string|null} ruleId The ID of the rule which makes this message.
104 * @property {0|1|2} severity The severity of this message.
105 * @property {Array<{desc?: string, messageId?: string, fix: {range: [number, number], text: string}}>} [suggestions] Information for suggestions.
106 */
107
108 /**
109 * @typedef {Object} SuggestionResult
110 * @property {string} desc A short description.
111 * @property {string} [messageId] Id referencing a message for the description.
112 * @property {{ text: string, range: number[] }} fix fix result info
113 */
114
115 /**
116 * @typedef {Object} Processor
117 * @property {(text:string, filename:string) => Array<string | { text:string, filename:string }>} [preprocess] The function to extract code blocks.
118 * @property {(messagesList:LintMessage[][], filename:string) => LintMessage[]} [postprocess] The function to merge messages.
119 * @property {boolean} [supportsAutofix] If `true` then it means the processor supports autofix.
120 */
121
122 /**
123 * @typedef {Object} RuleMetaDocs
124 * @property {string} category The category of the rule.
125 * @property {string} description The description of the rule.
126 * @property {boolean} recommended If `true` then the rule is included in `eslint:recommended` preset.
127 * @property {string} url The URL of the rule documentation.
128 */
129
130 /**
131 * @typedef {Object} RuleMeta
132 * @property {boolean} [deprecated] If `true` then the rule has been deprecated.
133 * @property {RuleMetaDocs} docs The document information of the rule.
134 * @property {"code"|"whitespace"} [fixable] The autofix type.
135 * @property {Record<string,string>} [messages] The messages the rule reports.
136 * @property {string[]} [replacedBy] The IDs of the alternative rules.
137 * @property {Array|Object} schema The option schema of the rule.
138 * @property {"problem"|"suggestion"|"layout"} type The rule type.
139 */
140
141 /**
142 * @typedef {Object} Rule
143 * @property {Function} create The factory of the rule.
144 * @property {RuleMeta} meta The meta data of the rule.
145 */
146
147 /**
148 * @typedef {Object} Plugin
149 * @property {Record<string, ConfigData>} [configs] The definition of plugin configs.
150 * @property {Record<string, Environment>} [environments] The definition of plugin environments.
151 * @property {Record<string, Processor>} [processors] The definition of plugin processors.
152 * @property {Record<string, Function | Rule>} [rules] The definition of plugin rules.
153 */
154
155 /**
156 * Information of deprecated rules.
157 * @typedef {Object} DeprecatedRuleInfo
158 * @property {string} ruleId The rule ID.
159 * @property {string[]} replacedBy The rule IDs that replace this deprecated rule.
160 */