eslint-config-webpack 4.15.0 → 5.0.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.
Files changed (35) hide show
  1. package/README.md +48 -4
  2. package/configs/browser.js +70 -7
  3. package/configs/index.js +7 -6
  4. package/configs/javascript.js +746 -151
  5. package/configs/json.js +72 -0
  6. package/configs/markdown.js +111 -6
  7. package/configs/node.js +78 -23
  8. package/configs/performance.js +8 -0
  9. package/configs/react.js +7 -19
  10. package/configs/stylistic.js +17 -0
  11. package/configs/{jest.js → test.js} +65 -5
  12. package/configs/typescript.js +39 -10
  13. package/configs/utils/code-files.js +20 -0
  14. package/configs/utils/get-es-version-from-node.js +9 -4
  15. package/configs/utils/get-json-file.js +1 -5
  16. package/configs/utils/is-jest-installed.js +20 -0
  17. package/configs/utils/is-typescript-installed.js +3 -3
  18. package/configs.js +47 -31
  19. package/package.json +31 -26
  20. package/plugins/package-json/index.js +0 -5
  21. package/plugins/package-json/rules/order-properties.js +8 -18
  22. package/plugins/performance/index.js +60 -0
  23. package/plugins/performance/rules/no-case-insensitive-unicode-range.js +214 -0
  24. package/plugins/performance/rules/require-precompiled-schema.js +414 -0
  25. package/plugins/webpack/index.js +0 -1
  26. package/plugins/webpack/rules/comment-length.js +1 -3
  27. package/plugins/webpack/rules/format-schema.js +18 -16
  28. package/plugins/webpack/rules/inherit-jsdoc.js +2 -3
  29. package/plugins/webpack/rules/no-duplicate-import-tag.js +3 -4
  30. package/plugins/webpack/rules/no-unused-import-tag.js +8 -11
  31. package/plugins/webpack/rules/prefer-import-tag.js +1 -2
  32. package/plugins/webpack/rules/require-license-comment.js +3 -5
  33. package/plugins/webpack/rules/valid-schema.js +9 -13
  34. package/plugins/webpack/utils/import-tags.js +4 -3
  35. package/configs/package-json.js +0 -8
@@ -1,6 +1,6 @@
1
1
  /** @typedef {import("eslint").Rule.RuleFixer} RuleFixer */
2
2
  /** @typedef {import("eslint").Rule.Fix} Fix */
3
- /** @typedef {import("estree").MethodDefinition} MethodDefinition */
3
+ /** @import { MethodDefinition } from "estree" */
4
4
 
5
5
  // The TypeScript AST is reached through the parser services, which type them as
6
6
  // `unknown` outside a TypeScript-aware parser.
@@ -34,7 +34,7 @@ function rewriteJSDoc(text, indent, stripTags) {
34
34
  return lines
35
35
  .filter(
36
36
  (line, index) =>
37
- index === 0 || ![...stripped].some((regexp) => regexp.test(line)),
37
+ index === 0 || [...stripped].every((regexp) => !regexp.test(line)),
38
38
  )
39
39
  .map((line, index) =>
40
40
  index === 0 ? line : `${indent} ${line.trimStart()}`,
@@ -174,7 +174,6 @@ export const rule = {
174
174
  },
175
175
  meta: {
176
176
  docs: {
177
- category: "Best Practices",
178
177
  description:
179
178
  "Require a method to carry the JSDoc of the method it overrides",
180
179
  recommended: false,
@@ -1,6 +1,6 @@
1
1
  import { collectImportTags } from "../utils/import-tags.js";
2
2
 
3
- /** @typedef {import("../utils/import-tags.js").ImportTag} ImportTag */
3
+ /** @import { ImportTag } from "../utils/import-tags.js" */
4
4
 
5
5
  /**
6
6
  * Whether two tags could be written as one import statement. A namespace binding
@@ -23,7 +23,7 @@ const isMergeable = (first, second) => {
23
23
  }
24
24
 
25
25
  return (
26
- !heads.some((tag) => tag.namespace) ||
26
+ heads.every((tag) => !tag.namespace) ||
27
27
  first.named.length + second.named.length === 0
28
28
  );
29
29
  };
@@ -69,9 +69,8 @@ export const rule = {
69
69
  },
70
70
  meta: {
71
71
  docs: {
72
- category: "Stylistic Issues",
73
72
  description: "Require one `@import` per module in a file",
74
- recommended: true,
73
+ recommended: false,
75
74
  },
76
75
  messages: {
77
76
  duplicateImportTag:
@@ -1,9 +1,8 @@
1
1
  import { collectImportTags } from "../utils/import-tags.js";
2
2
 
3
3
  /** @typedef {import("eslint").Rule.ReportFixer} ReportFixer */
4
- /** @typedef {import("eslint").SourceCode} SourceCode */
5
- /** @typedef {import("../utils/import-tags.js").ImportBinding} ImportBinding */
6
- /** @typedef {import("../utils/import-tags.js").ImportTag} ImportTag */
4
+ /** @import { SourceCode } from "eslint" */
5
+ /** @import { ImportBinding, ImportTag } from "../utils/import-tags.js" */
7
6
 
8
7
  /**
9
8
  * The source with every `@import` tag blanked out, so one import can never keep
@@ -47,11 +46,10 @@ const lineRangeAt = (text, index) => {
47
46
  const removableCommentRange = (text, tag) => {
48
47
  const commentRange = /** @type {[number, number]} */ (tag.comment.range);
49
48
 
50
- if (text.slice(commentRange[0], tag.start).replaceAll(/[/*\s]/g, "") !== "") {
51
- return null;
52
- }
53
-
54
- if (/@\w/.test(text.slice(tag.end, commentRange[1]))) {
49
+ if (
50
+ text.slice(commentRange[0], tag.start).replaceAll(/[/*\s]/g, "") !== "" ||
51
+ /@\w/.test(text.slice(tag.end, commentRange[1]))
52
+ ) {
55
53
  return null;
56
54
  }
57
55
 
@@ -102,7 +100,7 @@ const buildFixer = (sourceCode, tag, binding, bindingCount) => {
102
100
  .toSorted((one, another) => another.end - one.end);
103
101
  const strandedComma =
104
102
  previous !== undefined &&
105
- !tag.named.some((other) => other.start >= binding.end)
103
+ tag.named.every((other) => !(other.start >= binding.end))
106
104
  ? text.indexOf(",", previous.end)
107
105
  : -1;
108
106
 
@@ -178,9 +176,8 @@ export const rule = {
178
176
  },
179
177
  meta: {
180
178
  docs: {
181
- category: "Stylistic Issues",
182
179
  description: "Require every `@import` binding to be referenced",
183
- recommended: true,
180
+ recommended: false,
184
181
  },
185
182
  fixable: "code",
186
183
  messages: {
@@ -72,10 +72,9 @@ export const rule = {
72
72
  },
73
73
  meta: {
74
74
  docs: {
75
- category: "Stylistic Issues",
76
75
  description:
77
76
  "Require `@import` rather than a `@typedef` that only aliases an `import()`",
78
- recommended: true,
77
+ recommended: false,
79
78
  },
80
79
  fixable: "code",
81
80
  messages: {
@@ -1,4 +1,4 @@
1
- /** @typedef {import("estree").Comment} Comment */
1
+ /** @import { Comment } from "estree" */
2
2
  /** @typedef {import("eslint").AST.SourceLocation} SourceLocation */
3
3
 
4
4
  /**
@@ -6,7 +6,7 @@
6
6
  */
7
7
  export const rule = {
8
8
  create(context) {
9
- const sourceCode = context.getSourceCode();
9
+ const { sourceCode } = context;
10
10
 
11
11
  return {
12
12
  "Program:exit"(program) {
@@ -17,7 +17,7 @@ export const rule = {
17
17
  comments.find(
18
18
  (comment) =>
19
19
  comment.type === "Block" &&
20
- /\n\s*MIT License http:\/\/www\.opensource\.org\/licenses\/mit-license\.php\n\s*(?:(Authors? .+)\n)?\s*/g.test(
20
+ /\n\s*MIT License https?:\/\/www\.opensource\.org\/licenses\/mit-license\.php\n\s*(?:(Authors? .+)\n)?\s*/.test(
21
21
  comment.value,
22
22
  ),
23
23
  )
@@ -57,11 +57,9 @@ export const rule = {
57
57
  },
58
58
  meta: {
59
59
  docs: {
60
- category: "Best Practices",
61
60
  description: "Require license comment",
62
61
  recommended: true,
63
62
  },
64
- fixable: "code",
65
63
  type: "layout",
66
64
  },
67
65
  };
@@ -26,11 +26,9 @@ function getKeywordName(property) {
26
26
  * @returns {JSONProperty | undefined} property declaring the keyword
27
27
  */
28
28
  function getKeyword(node, name) {
29
- if (!node || node.type !== "JSONObjectExpression") {
30
- return undefined;
31
- }
32
-
33
- return node.properties.find((property) => getKeywordName(property) === name);
29
+ return !node || node.type !== "JSONObjectExpression"
30
+ ? undefined
31
+ : node.properties.find((property) => getKeywordName(property) === name);
34
32
  }
35
33
 
36
34
  /**
@@ -278,16 +276,15 @@ export const rule = {
278
276
  }
279
277
  }
280
278
 
281
- if (
279
+ if (!(
282
280
  additionalProperties &&
283
281
  additionalProperties.value.type === "JSONObjectExpression"
284
- ) {
285
- validateDescription(
286
- additionalProperties.value,
287
- additionalProperties.key,
288
- );
289
- walk(additionalProperties.value);
282
+ )) {
283
+ return;
290
284
  }
285
+
286
+ validateDescription(additionalProperties.value, additionalProperties.key);
287
+ walk(additionalProperties.value);
291
288
  }
292
289
 
293
290
  return {
@@ -308,7 +305,6 @@ export const rule = {
308
305
  },
309
306
  meta: {
310
307
  docs: {
311
- category: "Possible Errors",
312
308
  description: "Enforce webpack's conventions for JSON schema files",
313
309
  recommended: false,
314
310
  },
@@ -1,5 +1,5 @@
1
- /** @typedef {import("eslint").SourceCode} SourceCode */
2
- /** @typedef {import("estree").Comment} Comment */
1
+ /** @import { SourceCode } from "eslint" */
2
+ /** @import { Comment } from "estree" */
3
3
 
4
4
  /**
5
5
  * @typedef {object} ImportBinding
@@ -39,7 +39,8 @@ export const stripLineMarkers = (text) =>
39
39
  */
40
40
  export const localNameOf = (binding) => {
41
41
  const parts = binding.split(/[ \t\n]+as[ \t\n]+/);
42
- return parts[parts.length - 1].trim();
42
+ // `split()` always returns at least one part
43
+ return /** @type {string} */ (parts.at(-1)).trim();
43
44
  };
44
45
 
45
46
  /**
@@ -1,8 +0,0 @@
1
- import { configs } from "../plugins/package-json/index.js";
2
-
3
- /** @type {import("eslint").Linter.Config} */
4
- const recommendedBrowserConfig = configs.recommended;
5
-
6
- export default {
7
- "package-json/recommended": recommendedBrowserConfig,
8
- };