eslint 8.54.0 → 8.55.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -74,6 +74,9 @@ const arrayOfStringsOrObjectPatterns = {
74
74
  minItems: 1,
75
75
  uniqueItems: true
76
76
  },
77
+ importNamePattern: {
78
+ type: "string"
79
+ },
77
80
  message: {
78
81
  type: "string",
79
82
  minLength: 1
@@ -115,8 +118,12 @@ module.exports = {
115
118
  patternAndImportNameWithCustomMessage: "'{{importName}}' import from '{{importSource}}' is restricted from being used by a pattern. {{customMessage}}",
116
119
 
117
120
  patternAndEverything: "* import is invalid because '{{importNames}}' from '{{importSource}}' is restricted from being used by a pattern.",
121
+
122
+ patternAndEverythingWithRegexImportName: "* import is invalid because import name matching '{{importNames}}' pattern from '{{importSource}}' is restricted from being used.",
118
123
  // eslint-disable-next-line eslint-plugin/report-message-format -- Custom message might not end in a period
119
124
  patternAndEverythingWithCustomMessage: "* import is invalid because '{{importNames}}' from '{{importSource}}' is restricted from being used by a pattern. {{customMessage}}",
125
+ // eslint-disable-next-line eslint-plugin/report-message-format -- Custom message might not end in a period
126
+ patternAndEverythingWithRegexImportNameAndCustomMessage: "* import is invalid because import name matching '{{importNames}}' pattern from '{{importSource}}' is restricted from being used. {{customMessage}}",
120
127
 
121
128
  everything: "* import is invalid because '{{importNames}}' from '{{importSource}}' is restricted.",
122
129
  // eslint-disable-next-line eslint-plugin/report-message-format -- Custom message might not end in a period
@@ -175,10 +182,11 @@ module.exports = {
175
182
  }
176
183
 
177
184
  // relative paths are supported for this rule
178
- const restrictedPatternGroups = restrictedPatterns.map(({ group, message, caseSensitive, importNames }) => ({
185
+ const restrictedPatternGroups = restrictedPatterns.map(({ group, message, caseSensitive, importNames, importNamePattern }) => ({
179
186
  matcher: ignore({ allowRelativePaths: true, ignorecase: !caseSensitive }).add(group),
180
187
  customMessage: message,
181
- importNames
188
+ importNames,
189
+ importNamePattern
182
190
  }));
183
191
 
184
192
  // if no imports are restricted we don't need to check
@@ -262,12 +270,13 @@ module.exports = {
262
270
 
263
271
  const customMessage = group.customMessage;
264
272
  const restrictedImportNames = group.importNames;
273
+ const restrictedImportNamePattern = group.importNamePattern ? new RegExp(group.importNamePattern, "u") : null;
265
274
 
266
275
  /*
267
276
  * If we are not restricting to any specific import names and just the pattern itself,
268
277
  * report the error and move on
269
278
  */
270
- if (!restrictedImportNames) {
279
+ if (!restrictedImportNames && !restrictedImportNamePattern) {
271
280
  context.report({
272
281
  node,
273
282
  messageId: customMessage ? "patternWithCustomMessage" : "patterns",
@@ -279,40 +288,54 @@ module.exports = {
279
288
  return;
280
289
  }
281
290
 
282
- if (importNames.has("*")) {
283
- const specifierData = importNames.get("*")[0];
284
-
285
- context.report({
286
- node,
287
- messageId: customMessage ? "patternAndEverythingWithCustomMessage" : "patternAndEverything",
288
- loc: specifierData.loc,
289
- data: {
290
- importSource,
291
- importNames: restrictedImportNames,
292
- customMessage
291
+ importNames.forEach((specifiers, importName) => {
292
+ if (importName === "*") {
293
+ const [specifier] = specifiers;
294
+
295
+ if (restrictedImportNames) {
296
+ context.report({
297
+ node,
298
+ messageId: customMessage ? "patternAndEverythingWithCustomMessage" : "patternAndEverything",
299
+ loc: specifier.loc,
300
+ data: {
301
+ importSource,
302
+ importNames: restrictedImportNames,
303
+ customMessage
304
+ }
305
+ });
306
+ } else {
307
+ context.report({
308
+ node,
309
+ messageId: customMessage ? "patternAndEverythingWithRegexImportNameAndCustomMessage" : "patternAndEverythingWithRegexImportName",
310
+ loc: specifier.loc,
311
+ data: {
312
+ importSource,
313
+ importNames: restrictedImportNamePattern,
314
+ customMessage
315
+ }
316
+ });
293
317
  }
294
- });
295
- }
296
318
 
297
- restrictedImportNames.forEach(importName => {
298
- if (!importNames.has(importName)) {
299
319
  return;
300
320
  }
301
321
 
302
- const specifiers = importNames.get(importName);
303
-
304
- specifiers.forEach(specifier => {
305
- context.report({
306
- node,
307
- messageId: customMessage ? "patternAndImportNameWithCustomMessage" : "patternAndImportName",
308
- loc: specifier.loc,
309
- data: {
310
- importSource,
311
- customMessage,
312
- importName
313
- }
322
+ if (
323
+ (restrictedImportNames && restrictedImportNames.includes(importName)) ||
324
+ (restrictedImportNamePattern && restrictedImportNamePattern.test(importName))
325
+ ) {
326
+ specifiers.forEach(specifier => {
327
+ context.report({
328
+ node,
329
+ messageId: customMessage ? "patternAndImportNameWithCustomMessage" : "patternAndImportName",
330
+ loc: specifier.loc,
331
+ data: {
332
+ importSource,
333
+ customMessage,
334
+ importName
335
+ }
336
+ });
314
337
  });
315
- });
338
+ }
316
339
  });
317
340
  }
318
341
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint",
3
- "version": "8.54.0",
3
+ "version": "8.55.0",
4
4
  "author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
5
5
  "description": "An AST-based pattern checker for JavaScript.",
6
6
  "bin": {
@@ -19,6 +19,7 @@
19
19
  "build:readme": "node tools/update-readme.js",
20
20
  "lint": "node Makefile.js lint",
21
21
  "lint:docs:js": "node Makefile.js lintDocsJS",
22
+ "lint:docs:rule-examples": "node Makefile.js checkRuleExamples",
22
23
  "lint:fix": "node Makefile.js lint -- fix",
23
24
  "lint:fix:docs:js": "node Makefile.js lintDocsJS -- fix",
24
25
  "release:generate:alpha": "node Makefile.js generatePrerelease -- alpha",
@@ -42,6 +43,7 @@
42
43
  "git add packages/js/src/configs/eslint-all.js"
43
44
  ],
44
45
  "docs/src/rules/*.md": [
46
+ "node tools/check-rule-examples.js",
45
47
  "node tools/fetch-docs-links.js",
46
48
  "git add docs/src/_data/further_reading_links.json"
47
49
  ],
@@ -62,8 +64,8 @@
62
64
  "dependencies": {
63
65
  "@eslint-community/eslint-utils": "^4.2.0",
64
66
  "@eslint-community/regexpp": "^4.6.1",
65
- "@eslint/eslintrc": "^2.1.3",
66
- "@eslint/js": "8.54.0",
67
+ "@eslint/eslintrc": "^2.1.4",
68
+ "@eslint/js": "8.55.0",
67
69
  "@humanwhocodes/config-array": "^0.11.13",
68
70
  "@humanwhocodes/module-importer": "^1.0.1",
69
71
  "@nodelib/fs.walk": "^1.2.8",
@@ -132,6 +134,8 @@
132
134
  "gray-matter": "^4.0.3",
133
135
  "lint-staged": "^11.0.0",
134
136
  "load-perf": "^0.2.0",
137
+ "markdown-it": "^12.2.0",
138
+ "markdown-it-container": "^3.0.0",
135
139
  "markdownlint": "^0.31.1",
136
140
  "markdownlint-cli": "^0.37.0",
137
141
  "marked": "^4.0.8",