UNPKG

6.05 kBJavaScriptView Raw
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} */
8module.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|2015|2016|2017|2018|2019} [ecmaVersion] The ECMAScript version (or revision number).
25 * @property {"script"|"module"} [sourceType] The source code type.
26 */
27
28/**
29 * @typedef {Object} ConfigData
30 * @property {Record<string, boolean>} [env] The environment settings.
31 * @property {string | string[]} [extends] The path to other config files or the package name of shareable configs.
32 * @property {Record<string, GlobalConf>} [globals] The global variable settings.
33 * @property {OverrideConfigData[]} [overrides] The override settings per kind of files.
34 * @property {string} [parser] The path to a parser or the package name of a parser.
35 * @property {ParserOptions} [parserOptions] The parser options.
36 * @property {string[]} [plugins] The plugin specifiers.
37 * @property {string} [processor] The processor specifier.
38 * @property {boolean} [root] The root flag.
39 * @property {Record<string, RuleConf>} [rules] The rule settings.
40 * @property {Object} [settings] The shared settings.
41 */
42
43/**
44 * @typedef {Object} OverrideConfigData
45 * @property {Record<string, boolean>} [env] The environment settings.
46 * @property {string | string[]} [excludedFiles] The glob pattarns for excluded files.
47 * @property {string | string[]} [extends] The path to other config files or the package name of shareable configs.
48 * @property {string | string[]} files The glob pattarns for target files.
49 * @property {Record<string, GlobalConf>} [globals] The global variable settings.
50 * @property {OverrideConfigData[]} [overrides] The override settings per kind of files.
51 * @property {string} [parser] The path to a parser or the package name of a parser.
52 * @property {ParserOptions} [parserOptions] The parser options.
53 * @property {string[]} [plugins] The plugin specifiers.
54 * @property {string} [processor] The processor specifier.
55 * @property {Record<string, RuleConf>} [rules] The rule settings.
56 * @property {Object} [settings] The shared settings.
57 */
58
59/**
60 * @typedef {Object} ParseResult
61 * @property {Object} ast The AST.
62 * @property {ScopeManager} [scopeManager] The scope manager of the AST.
63 * @property {Record<string, any>} [services] The services that the parser provides.
64 * @property {Record<string, string[]>} [visitorKeys] The visitor keys of the AST.
65 */
66
67/**
68 * @typedef {Object} Parser
69 * @property {(text:string, options:ParserOptions) => Object} parse The definition of global variables.
70 * @property {(text:string, options:ParserOptions) => ParseResult} [parseForESLint] The parser options that will be enabled under this environment.
71 */
72
73/**
74 * @typedef {Object} Environment
75 * @property {Record<string, GlobalConf>} [globals] The definition of global variables.
76 * @property {ParserOptions} [parserOptions] The parser options that will be enabled under this environment.
77 */
78
79/**
80 * @typedef {Object} LintMessage
81 * @property {number} column The 1-based column number.
82 * @property {number} [endColumn] The 1-based column number of the end location.
83 * @property {number} [endLine] The 1-based line number of the end location.
84 * @property {boolean} fatal If `true` then this is a fatal error.
85 * @property {{range:[number,number], text:string}} [fix] Information for autofix.
86 * @property {number} line The 1-based line number.
87 * @property {string} message The error message.
88 * @property {string|null} ruleId The ID of the rule which makes this message.
89 * @property {0|1|2} severity The severity of this message.
90 */
91
92/**
93 * @typedef {Object} Processor
94 * @property {(text:string, filename:string) => Array<string | { text:string, filename:string }>} [preprocess] The function to extract code blocks.
95 * @property {(messagesList:LintMessage[][], filename:string) => LintMessage[]} [postprocess] The function to merge messages.
96 * @property {boolean} [supportsAutofix] If `true` then it means the processor supports autofix.
97 */
98
99/**
100 * @typedef {Object} RuleMetaDocs
101 * @property {string} category The category of the rule.
102 * @property {string} description The description of the rule.
103 * @property {boolean} recommended If `true` then the rule is included in `eslint:recommended` preset.
104 * @property {string} url The URL of the rule documentation.
105 */
106
107/**
108 * @typedef {Object} RuleMeta
109 * @property {boolean} [deprecated] If `true` then the rule has been deprecated.
110 * @property {RuleMetaDocs} docs The document information of the rule.
111 * @property {"code"|"whitespace"} [fixable] The autofix type.
112 * @property {Record<string,string>} [messages] The messages the rule reports.
113 * @property {string[]} [replacedBy] The IDs of the alternative rules.
114 * @property {Array|Object} schema The option schema of the rule.
115 * @property {"problem"|"suggestion"|"layout"} type The rule type.
116 */
117
118/**
119 * @typedef {Object} Rule
120 * @property {Function} create The factory of the rule.
121 * @property {RuleMeta} meta The meta data of the rule.
122 */
123
124/**
125 * @typedef {Object} Plugin
126 * @property {Record<string, ConfigData>} [configs] The definition of plugin configs.
127 * @property {Record<string, Environment>} [environments] The definition of plugin environments.
128 * @property {Record<string, Processor>} [processors] The definition of plugin processors.
129 * @property {Record<string, Function | Rule>} [rules] The definition of plugin rules.
130 */