forked from eslint/eslint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eslintrc.js
215 lines (204 loc) · 7.27 KB
/
.eslintrc.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
"use strict";
const path = require("path");
const INTERNAL_FILES = {
CLI_ENGINE_PATTERN: "lib/cli-engine/**/*",
INIT_PATTERN: "lib/init/**/*",
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 = {
root: true,
plugins: [
"eslint-plugin",
"internal-rules"
],
extends: [
"eslint",
"plugin:eslint-plugin/recommended"
],
parserOptions: {
ecmaVersion: 2020
},
/*
* it fixes eslint-plugin-jsdoc's reports: "Invalid JSDoc tag name "template" jsdoc/check-tag-names"
* refs: https://github.com/gajus/eslint-plugin-jsdoc#check-tag-names
*/
settings: {
jsdoc: {
mode: "typescript"
}
},
rules: {
"eslint-plugin/consistent-output": "error",
"eslint-plugin/no-deprecated-context-methods": "error",
"eslint-plugin/prefer-output-null": "error",
"eslint-plugin/prefer-placeholders": "error",
"eslint-plugin/report-message-format": ["error", "[^a-z].*\\.$"],
"eslint-plugin/require-meta-docs-description": "error",
"eslint-plugin/require-meta-type": "error",
"eslint-plugin/test-case-property-ordering": [
"error",
// https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/issues/79
[
"filename",
"code",
"output",
"options",
"parser",
"parserOptions",
"globals",
"env",
"errors"
]
],
"eslint-plugin/test-case-shorthand-strings": "error",
"internal-rules/multiline-comment-style": "error"
},
overrides: [
{
files: ["lib/rules/*", "tools/internal-rules/*"],
excludedFiles: ["index.js"],
rules: {
"internal-rules/no-invalid-meta": "error"
/*
* TODO: enable it when all the rules using meta.messages
* "internal-rules/consistent-meta-messages": "error"
*/
}
},
{
files: ["lib/rules/*"],
excludedFiles: ["index.js"],
rules: {
"internal-rules/consistent-docs-url": "error"
}
},
{
files: ["tests/**/*"],
env: { mocha: true },
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/*"],
rules: {
"node/no-restricted-require": ["error", [
...createInternalFilesPatterns()
]]
}
},
{
files: [INTERNAL_FILES.CLI_ENGINE_PATTERN],
rules: {
"node/no-restricted-require": ["error", [
...createInternalFilesPatterns(INTERNAL_FILES.CLI_ENGINE_PATTERN),
resolveAbsolutePath("lib/init/index.js")
]]
}
},
{
files: [INTERNAL_FILES.INIT_PATTERN],
rules: {
"node/no-restricted-require": ["error", [
...createInternalFilesPatterns(INTERNAL_FILES.INIT_PATTERN),
resolveAbsolutePath("lib/rule-tester/index.js")
]]
}
},
{
files: [INTERNAL_FILES.LINTER_PATTERN],
rules: {
"node/no-restricted-require": ["error", [
...createInternalFilesPatterns(INTERNAL_FILES.LINTER_PATTERN),
"fs",
resolveAbsolutePath("lib/cli-engine/index.js"),
resolveAbsolutePath("lib/init/index.js"),
resolveAbsolutePath("lib/rule-tester/index.js")
]]
}
},
{
files: [INTERNAL_FILES.RULES_PATTERN],
rules: {
"node/no-restricted-require": ["error", [
...createInternalFilesPatterns(INTERNAL_FILES.RULES_PATTERN),
"fs",
resolveAbsolutePath("lib/cli-engine/index.js"),
resolveAbsolutePath("lib/init/index.js"),
resolveAbsolutePath("lib/linter/index.js"),
resolveAbsolutePath("lib/rule-tester/index.js"),
resolveAbsolutePath("lib/source-code/index.js")
]]
}
},
{
files: ["lib/shared/**/*"],
rules: {
"node/no-restricted-require": ["error", [
...createInternalFilesPatterns(),
resolveAbsolutePath("lib/cli-engine/index.js"),
resolveAbsolutePath("lib/init/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: {
"node/no-restricted-require": ["error", [
...createInternalFilesPatterns(INTERNAL_FILES.SOURCE_CODE_PATTERN),
"fs",
resolveAbsolutePath("lib/cli-engine/index.js"),
resolveAbsolutePath("lib/init/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: {
"node/no-restricted-require": ["error", [
...createInternalFilesPatterns(INTERNAL_FILES.RULE_TESTER_PATTERN),
resolveAbsolutePath("lib/cli-engine/index.js"),
resolveAbsolutePath("lib/init/index.js")
]]
}
}
]
};