forked from eslint/eslint
-
Notifications
You must be signed in to change notification settings - Fork 1
/
eslint.config.js
233 lines (221 loc) · 7.46 KB
/
eslint.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/**
* @fileoverview ESLint configuration file
* @author Nicholas C. Zakas
*/
"use strict";
/*
* IMPORTANT!
*
* Any changes made to this file must also be made to .eslintrc.js.
*
* Internally, ESLint is using the eslint.config.js file to lint itself.
* The .eslintrc.js file is needed too, because:
*
* 1. There are tests that expect .eslintrc.js to be present to actually run.
* 2. ESLint VS Code extension expects eslintrc config files to be
* present to work correctly.
*
* Once we no longer need to support both eslintrc and flat config, we will
* remove .eslintrc.js.
*/
//-----------------------------------------------------------------------------
// Requirements
//-----------------------------------------------------------------------------
const path = require("path");
const internalPlugin = require("eslint-plugin-internal-rules");
const eslintPluginRulesRecommendedConfig = require("eslint-plugin-eslint-plugin/configs/rules-recommended");
const eslintPluginTestsRecommendedConfig = require("eslint-plugin-eslint-plugin/configs/tests-recommended");
const globals = require("globals");
const merge = require("lodash.merge");
const eslintConfigESLintCJS = require("eslint-config-eslint/cjs");
//-----------------------------------------------------------------------------
// Helpers
//-----------------------------------------------------------------------------
const INTERNAL_FILES = {
CLI_ENGINE_PATTERN: "lib/cli-engine/**/*",
LINTER_PATTERN: "lib/linter/**/*",
RULE_TESTER_PATTERN: "lib/rule-tester/**/*",
RULES_PATTERN: "lib/rules/**/*",
SOURCE_CODE_PATTERN: "lib/source-code/**/*"
};
/**
* Resolve an absolute path or glob pattern.
* @param {string} pathOrPattern the path or glob pattern.
* @returns {string} The resolved path or glob pattern.
*/
function resolveAbsolutePath(pathOrPattern) {
return path.resolve(__dirname, pathOrPattern);
}
/**
* Create an array of `no-restricted-require` entries for ESLint's core files.
* @param {string} [pattern] The glob pattern to create the entries for.
* @returns {Object[]} The array of `no-restricted-require` entries.
*/
function createInternalFilesPatterns(pattern = null) {
return Object.values(INTERNAL_FILES)
.filter(p => p !== pattern)
.map(p => ({
name: [
// Disallow all children modules.
resolveAbsolutePath(p),
// Allow the main `index.js` module.
`!${resolveAbsolutePath(p.replace(/\*\*\/\*$/u, "index.js"))}`
]
}));
}
module.exports = [
...eslintConfigESLintCJS,
{
ignores: [
"build/**",
"coverage/**",
"docs/*",
"!docs/*.js",
"!docs/tools/",
"jsdoc/**",
"templates/**",
"tests/bench/**",
"tests/fixtures/**",
"tests/performance/**",
"tmp/**",
"tools/internal-rules/node_modules/**",
"**/test.js"
]
},
{
plugins: {
"internal-rules": internalPlugin
},
languageOptions: {
ecmaVersion: "latest"
},
rules: {
"internal-rules/multiline-comment-style": "error"
}
},
{
files: ["tools/*.js", "docs/tools/*.js"],
rules: {
"no-console": "off",
"n/no-process-exit": "off"
}
},
{
files: ["lib/rules/*", "tools/internal-rules/*"],
ignores: ["**/index.js"],
...merge({}, eslintPluginRulesRecommendedConfig, {
rules: {
"eslint-plugin/prefer-placeholders": "error",
"eslint-plugin/prefer-replace-text": "error",
"eslint-plugin/report-message-format": ["error", "[^a-z].*\\.$"],
"eslint-plugin/require-meta-docs-description": ["error", { pattern: "^(Enforce|Require|Disallow) .+[^. ]$" }],
"internal-rules/no-invalid-meta": "error"
}
})
},
{
files: ["lib/rules/*"],
ignores: ["**/index.js"],
rules: {
"eslint-plugin/require-meta-docs-url": ["error", { pattern: "https://eslint.org/docs/latest/rules/{{name}}" }]
}
},
{
files: ["tests/lib/rules/*", "tests/tools/internal-rules/*"],
...merge({}, eslintPluginTestsRecommendedConfig, {
rules: {
"eslint-plugin/test-case-property-ordering": "error",
"eslint-plugin/test-case-shorthand-strings": "error"
}
})
},
{
files: ["tests/**/*.js"],
languageOptions: {
globals: {
...globals.mocha
}
},
rules: {
"no-restricted-syntax": ["error", {
selector: "CallExpression[callee.object.name='assert'][callee.property.name='doesNotThrow']",
message: "`assert.doesNotThrow()` should be replaced with a comment next to the code."
}]
}
},
// Restrict relative path imports
{
files: ["lib/*"],
ignores: ["lib/unsupported-api.js"],
rules: {
"n/no-restricted-require": ["error", [
...createInternalFilesPatterns()
]]
}
},
{
files: [INTERNAL_FILES.CLI_ENGINE_PATTERN],
rules: {
"n/no-restricted-require": ["error", [
...createInternalFilesPatterns(INTERNAL_FILES.CLI_ENGINE_PATTERN)
]]
}
},
{
files: [INTERNAL_FILES.LINTER_PATTERN],
rules: {
"n/no-restricted-require": ["error", [
...createInternalFilesPatterns(INTERNAL_FILES.LINTER_PATTERN),
"fs",
resolveAbsolutePath("lib/cli-engine/index.js"),
resolveAbsolutePath("lib/rule-tester/index.js")
]]
}
},
{
files: [INTERNAL_FILES.RULES_PATTERN],
rules: {
"n/no-restricted-require": ["error", [
...createInternalFilesPatterns(INTERNAL_FILES.RULES_PATTERN),
"fs",
resolveAbsolutePath("lib/cli-engine/index.js"),
resolveAbsolutePath("lib/linter/index.js"),
resolveAbsolutePath("lib/rule-tester/index.js"),
resolveAbsolutePath("lib/source-code/index.js")
]]
}
},
{
files: ["lib/shared/**/*"],
rules: {
"n/no-restricted-require": ["error", [
...createInternalFilesPatterns(),
resolveAbsolutePath("lib/cli-engine/index.js"),
resolveAbsolutePath("lib/linter/index.js"),
resolveAbsolutePath("lib/rule-tester/index.js"),
resolveAbsolutePath("lib/source-code/index.js")
]]
}
},
{
files: [INTERNAL_FILES.SOURCE_CODE_PATTERN],
rules: {
"n/no-restricted-require": ["error", [
...createInternalFilesPatterns(INTERNAL_FILES.SOURCE_CODE_PATTERN),
"fs",
resolveAbsolutePath("lib/cli-engine/index.js"),
resolveAbsolutePath("lib/linter/index.js"),
resolveAbsolutePath("lib/rule-tester/index.js"),
resolveAbsolutePath("lib/rules/index.js")
]]
}
},
{
files: [INTERNAL_FILES.RULE_TESTER_PATTERN],
rules: {
"n/no-restricted-require": ["error", [
resolveAbsolutePath("lib/cli-engine/index.js")
]]
}
}
];