@@ -16,19 +16,27 @@ const eslintPluginTestsRecommendedConfig = require("eslint-plugin-eslint-plugin/
16
16
const globals = require ( "globals" ) ;
17
17
const eslintConfigESLintCJS = require ( "eslint-config-eslint/cjs" ) ;
18
18
const eslintConfigESLintFormatting = require ( "eslint-config-eslint/formatting" ) ;
19
+ const json = require ( "@eslint/json" ) ;
19
20
20
21
//-----------------------------------------------------------------------------
21
22
// Helpers
22
23
//-----------------------------------------------------------------------------
23
24
24
- const INTERNAL_FILES = {
25
+ const INTERNAL_PATHS = {
25
26
CLI_ENGINE_PATTERN : "lib/cli-engine/**/*" ,
26
27
LINTER_PATTERN : "lib/linter/**/*" ,
27
28
RULE_TESTER_PATTERN : "lib/rule-tester/**/*" ,
28
29
RULES_PATTERN : "lib/rules/**/*" ,
29
30
SOURCE_CODE_PATTERN : "lib/source-code/**/*"
30
31
} ;
31
32
33
+ // same paths but with `.js` at the end
34
+ const INTERNAL_FILES = Object . fromEntries (
35
+ Object . entries ( INTERNAL_PATHS ) . map ( ( [ key , value ] ) => [ key , `${ value } .js` ] )
36
+ ) ;
37
+
38
+ const ALL_JS_FILES = "**/*.js" ;
39
+
32
40
/**
33
41
* Resolve an absolute path or glob pattern.
34
42
* @param {string } pathOrPattern the path or glob pattern.
@@ -44,7 +52,7 @@ function resolveAbsolutePath(pathOrPattern) {
44
52
* @returns {Object[] } The array of `no-restricted-require` entries.
45
53
*/
46
54
function createInternalFilesPatterns ( pattern = null ) {
47
- return Object . values ( INTERNAL_FILES )
55
+ return Object . values ( INTERNAL_PATHS )
48
56
. filter ( p => p !== pattern )
49
57
. map ( p => ( {
50
58
name : [
@@ -59,8 +67,16 @@ function createInternalFilesPatterns(pattern = null) {
59
67
}
60
68
61
69
module . exports = [
62
- ...eslintConfigESLintCJS ,
63
- eslintConfigESLintFormatting ,
70
+ ...eslintConfigESLintCJS . map ( config => ( {
71
+ ...config ,
72
+ name : `eslint/${ config . name } ` ,
73
+ files : [ ALL_JS_FILES ]
74
+ } ) ) ,
75
+ {
76
+ ...eslintConfigESLintFormatting ,
77
+ name : "eslint/formatting" ,
78
+ files : [ ALL_JS_FILES ]
79
+ } ,
64
80
{
65
81
name : "eslint/global-ignores" ,
66
82
ignores : [
@@ -74,11 +90,13 @@ module.exports = [
74
90
"tests/fixtures/**" ,
75
91
"tests/performance/**" ,
76
92
"tmp/**" ,
77
- "**/test.js"
93
+ "**/test.js" ,
94
+ ".vscode"
78
95
]
79
96
} ,
80
97
{
81
98
name : "eslint/internal-rules" ,
99
+ files : [ ALL_JS_FILES ] ,
82
100
plugins : {
83
101
"internal-rules" : internalPlugin
84
102
} ,
@@ -99,7 +117,7 @@ module.exports = [
99
117
} ,
100
118
{
101
119
name : "eslint/rules" ,
102
- files : [ "lib/rules/*" , "tools/internal-rules/*" ] ,
120
+ files : [ "lib/rules/*.js " , "tools/internal-rules/*.js " ] ,
103
121
ignores : [ "**/index.js" ] ,
104
122
...eslintPluginRulesRecommendedConfig ,
105
123
rules : {
@@ -113,15 +131,15 @@ module.exports = [
113
131
} ,
114
132
{
115
133
name : "eslint/core-rules" ,
116
- files : [ "lib/rules/*" ] ,
134
+ files : [ "lib/rules/*.js " ] ,
117
135
ignores : [ "**/index.js" ] ,
118
136
rules : {
119
137
"eslint-plugin/require-meta-docs-url" : [ "error" , { pattern : "https://eslint.org/docs/latest/rules/{{name}}" } ]
120
138
}
121
139
} ,
122
140
{
123
141
name : "eslint/rules-tests" ,
124
- files : [ "tests/lib/rules/*" , "tests/tools/internal-rules/*" ] ,
142
+ files : [ "tests/lib/rules/*.js " , "tests/tools/internal-rules/*.js " ] ,
125
143
...eslintPluginTestsRecommendedConfig ,
126
144
rules : {
127
145
...eslintPluginTestsRecommendedConfig . rules ,
@@ -156,10 +174,27 @@ module.exports = [
156
174
}
157
175
} ,
158
176
177
+ // JSON files
178
+ {
179
+ name : "eslint/json" ,
180
+ files : [ "**/*.json" , ".c8rc" ] ,
181
+ ignores : [ "**/package-lock.json" ] ,
182
+ language : "json/json" ,
183
+ ...json . configs . recommended
184
+ } ,
185
+
186
+ // JSONC files
187
+ {
188
+ name : "eslint/jsonc" ,
189
+ files : [ "knip.jsonc" ] ,
190
+ language : "json/jsonc" ,
191
+ ...json . configs . recommended
192
+ } ,
193
+
159
194
// Restrict relative path imports
160
195
{
161
196
name : "eslint/lib" ,
162
- files : [ "lib/*" ] ,
197
+ files : [ "lib/*.js " ] ,
163
198
ignores : [ "lib/unsupported-api.js" ] ,
164
199
rules : {
165
200
"n/no-restricted-require" : [ "error" , [
@@ -172,7 +207,7 @@ module.exports = [
172
207
files : [ INTERNAL_FILES . CLI_ENGINE_PATTERN ] ,
173
208
rules : {
174
209
"n/no-restricted-require" : [ "error" , [
175
- ...createInternalFilesPatterns ( INTERNAL_FILES . CLI_ENGINE_PATTERN )
210
+ ...createInternalFilesPatterns ( INTERNAL_PATHS . CLI_ENGINE_PATTERN )
176
211
] ]
177
212
}
178
213
} ,
@@ -181,7 +216,7 @@ module.exports = [
181
216
files : [ INTERNAL_FILES . LINTER_PATTERN ] ,
182
217
rules : {
183
218
"n/no-restricted-require" : [ "error" , [
184
- ...createInternalFilesPatterns ( INTERNAL_FILES . LINTER_PATTERN ) ,
219
+ ...createInternalFilesPatterns ( INTERNAL_PATHS . LINTER_PATTERN ) ,
185
220
"fs" ,
186
221
resolveAbsolutePath ( "lib/cli-engine/index.js" ) ,
187
222
resolveAbsolutePath ( "lib/rule-tester/index.js" )
@@ -193,7 +228,7 @@ module.exports = [
193
228
files : [ INTERNAL_FILES . RULES_PATTERN ] ,
194
229
rules : {
195
230
"n/no-restricted-require" : [ "error" , [
196
- ...createInternalFilesPatterns ( INTERNAL_FILES . RULES_PATTERN ) ,
231
+ ...createInternalFilesPatterns ( INTERNAL_PATHS . RULES_PATTERN ) ,
197
232
"fs" ,
198
233
resolveAbsolutePath ( "lib/cli-engine/index.js" ) ,
199
234
resolveAbsolutePath ( "lib/linter/index.js" ) ,
@@ -204,7 +239,7 @@ module.exports = [
204
239
} ,
205
240
{
206
241
name : "eslint/shared" ,
207
- files : [ "lib/shared/**/*" ] ,
242
+ files : [ "lib/shared/**/*.js " ] ,
208
243
rules : {
209
244
"n/no-restricted-require" : [ "error" , [
210
245
...createInternalFilesPatterns ( ) ,
@@ -220,7 +255,7 @@ module.exports = [
220
255
files : [ INTERNAL_FILES . SOURCE_CODE_PATTERN ] ,
221
256
rules : {
222
257
"n/no-restricted-require" : [ "error" , [
223
- ...createInternalFilesPatterns ( INTERNAL_FILES . SOURCE_CODE_PATTERN ) ,
258
+ ...createInternalFilesPatterns ( INTERNAL_PATHS . SOURCE_CODE_PATTERN ) ,
224
259
"fs" ,
225
260
resolveAbsolutePath ( "lib/cli-engine/index.js" ) ,
226
261
resolveAbsolutePath ( "lib/linter/index.js" ) ,
0 commit comments