eslint-config-webpack 4.14.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 +94 -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 +31 -4
  11. package/configs/{jest.js → test.js} +65 -5
  12. package/configs/typescript.js +77 -55
  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 +34 -27
  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
@@ -0,0 +1,414 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { findVariable } from "@eslint-community/eslint-utils";
4
+
5
+ /** @import { CallExpression, Node } from "estree" */
6
+ /** @typedef {import("eslint").Scope.Scope} Scope */
7
+
8
+ const SCHEMA_UTILS = "schema-utils";
9
+
10
+ /**
11
+ * @typedef {object} ValidationApi
12
+ * @property {string} name how the call is named in the report
13
+ * @property {number} checkIndex position of the check among the arguments
14
+ */
15
+
16
+ /** @type {Record<"plugin" | "loader" | "schemaUtils", ValidationApi>} */
17
+ const APIS = {
18
+ plugin: {
19
+ name: "compiler.validate(schema, options, configuration, check)",
20
+ checkIndex: 3,
21
+ },
22
+ loader: { name: "this.getOptions(schema, check)", checkIndex: 1 },
23
+ schemaUtils: {
24
+ name: "validate(schema, options, configuration, check)",
25
+ checkIndex: 3,
26
+ },
27
+ };
28
+
29
+ /**
30
+ * @param {Node} node node
31
+ * @returns {string | undefined} name of an identifier or of the last property of a member chain
32
+ */
33
+ const lastName = (node) => {
34
+ if (node.type === "Identifier") return node.name;
35
+
36
+ if (
37
+ node.type === "MemberExpression" &&
38
+ !node.computed &&
39
+ node.property.type === "Identifier"
40
+ ) {
41
+ return node.property.name;
42
+ }
43
+
44
+ return undefined;
45
+ };
46
+
47
+ /**
48
+ * @param {Node | null | undefined} node node
49
+ * @returns {string | undefined} the module a `require("…")` call loads
50
+ */
51
+ const requiredModule = (node) => {
52
+ if (
53
+ node?.type === "CallExpression" &&
54
+ node.callee.type === "Identifier" &&
55
+ node.callee.name === "require" &&
56
+ node.arguments.length === 1 &&
57
+ node.arguments[0].type === "Literal" &&
58
+ typeof node.arguments[0].value === "string"
59
+ ) {
60
+ return node.arguments[0].value;
61
+ }
62
+
63
+ return undefined;
64
+ };
65
+
66
+ /**
67
+ * @param {Node | null | undefined} node node
68
+ * @returns {string | undefined} the module an `await import("…")` loads
69
+ */
70
+ const importedModule = (node) => {
71
+ const expression = node?.type === "AwaitExpression" ? node.argument : node;
72
+
73
+ if (
74
+ expression?.type === "ImportExpression" &&
75
+ expression.source.type === "Literal" &&
76
+ typeof expression.source.value === "string"
77
+ ) {
78
+ return expression.source.value;
79
+ }
80
+
81
+ return undefined;
82
+ };
83
+
84
+ /**
85
+ * @param {Node | null | undefined} node node
86
+ * @returns {string | undefined} the module a `require` or dynamic `import` loads
87
+ */
88
+ const loadedModule = (node) => requiredModule(node) ?? importedModule(node);
89
+
90
+ /**
91
+ * @typedef {object} Binding
92
+ * @property {string} source module the binding comes from
93
+ * @property {string | undefined} imported the export it is bound to, `undefined` for the whole module
94
+ */
95
+
96
+ /**
97
+ * Where a variable gets its value from when it is bound to a module or one of its exports.
98
+ * @param {Scope} scope scope
99
+ * @param {import("estree").Identifier} identifier identifier
100
+ * @returns {Binding | undefined} binding
101
+ */
102
+ const resolveBinding = (scope, identifier) => {
103
+ const variable = findVariable(scope, identifier);
104
+
105
+ if (!variable || variable.defs.length !== 1) return undefined;
106
+
107
+ const [definition] = variable.defs;
108
+
109
+ if (definition.type === "ImportBinding") {
110
+ const source = /** @type {import("estree").ImportDeclaration} */ (
111
+ definition.parent
112
+ ).source.value;
113
+
114
+ if (typeof source !== "string") return undefined;
115
+
116
+ const { node } = definition;
117
+
118
+ if (node.type === "ImportSpecifier") {
119
+ return {
120
+ source,
121
+ imported:
122
+ node.imported.type === "Identifier"
123
+ ? node.imported.name
124
+ : String(node.imported.value),
125
+ };
126
+ }
127
+
128
+ // A default import of a CommonJS module is the whole module
129
+ return { source, imported: undefined };
130
+ }
131
+
132
+ if (definition.type !== "Variable") return undefined;
133
+
134
+ const { id, init } = definition.node;
135
+ const source = loadedModule(init);
136
+
137
+ if (source === undefined) {
138
+ // `const { validate } = schemaUtils`
139
+ if (id.type === "ObjectPattern" && init?.type === "Identifier") {
140
+ const parent = resolveBinding(scope, init);
141
+
142
+ if (parent && parent.imported === undefined) {
143
+ const property = id.properties.find(
144
+ (item) =>
145
+ item.type === "Property" &&
146
+ item.value.type === "Identifier" &&
147
+ item.value.name === identifier.name,
148
+ );
149
+
150
+ if (
151
+ property?.type === "Property" &&
152
+ !property.computed &&
153
+ property.key.type === "Identifier"
154
+ ) {
155
+ return { source: parent.source, imported: property.key.name };
156
+ }
157
+ }
158
+ }
159
+
160
+ return undefined;
161
+ }
162
+
163
+ if (id.type === "Identifier") return { source, imported: undefined };
164
+
165
+ if (id.type === "ObjectPattern") {
166
+ const property = id.properties.find(
167
+ (item) =>
168
+ item.type === "Property" &&
169
+ item.value.type === "Identifier" &&
170
+ item.value.name === identifier.name,
171
+ );
172
+
173
+ if (
174
+ property?.type === "Property" &&
175
+ !property.computed &&
176
+ property.key.type === "Identifier"
177
+ ) {
178
+ return { source, imported: property.key.name };
179
+ }
180
+ }
181
+
182
+ return undefined;
183
+ };
184
+
185
+ /**
186
+ * @param {Scope} scope scope
187
+ * @param {Node} node expression
188
+ * @returns {boolean} true when the expression is the `schema-utils` module itself
189
+ */
190
+ const isSchemaUtilsModule = (scope, node) => {
191
+ if (loadedModule(node) === SCHEMA_UTILS) return true;
192
+
193
+ if (node.type === "Identifier") {
194
+ const binding = resolveBinding(scope, node);
195
+
196
+ return (
197
+ binding !== undefined &&
198
+ binding.source === SCHEMA_UTILS &&
199
+ binding.imported === undefined
200
+ );
201
+ }
202
+
203
+ return false;
204
+ };
205
+
206
+ /**
207
+ * Which validation API a call is, if any.
208
+ * @param {Scope} scope scope
209
+ * @param {CallExpression} node call
210
+ * @returns {ValidationApi | undefined} api
211
+ */
212
+ const getApi = (scope, node) => {
213
+ const { callee } = node;
214
+
215
+ if (callee.type === "Identifier") {
216
+ const binding = resolveBinding(scope, callee);
217
+
218
+ return binding?.source === SCHEMA_UTILS && binding.imported === "validate"
219
+ ? APIS.schemaUtils
220
+ : undefined;
221
+ }
222
+
223
+ if (
224
+ callee.type !== "MemberExpression" ||
225
+ callee.computed ||
226
+ callee.property.type !== "Identifier"
227
+ ) {
228
+ return undefined;
229
+ }
230
+
231
+ const { object } = callee;
232
+
233
+ switch (callee.property.name) {
234
+ case "validate": {
235
+ if (isSchemaUtilsModule(scope, object)) return APIS.schemaUtils;
236
+
237
+ const name = lastName(object);
238
+
239
+ // `compiler.validate`, `this.compiler.validate`, `childCompiler.validate`,
240
+ // but not an unrelated `templateCompiler.validate`
241
+ return name !== undefined &&
242
+ /^(?:child|first|parent|webpack)?compiler$/i.test(name)
243
+ ? APIS.plugin
244
+ : undefined;
245
+ }
246
+ case "getOptions": {
247
+ // `this.getOptions` in a loader, or the loader context passed around
248
+ if (object.type === "ThisExpression") return APIS.loader;
249
+
250
+ const name = lastName(object);
251
+
252
+ return name !== undefined &&
253
+ /^(?:loaderContext|loaderCtx|ctx)$/i.test(name)
254
+ ? APIS.loader
255
+ : undefined;
256
+ }
257
+ default:
258
+ return undefined;
259
+ }
260
+ };
261
+
262
+ /**
263
+ * The relative `.json` file a schema argument is loaded from.
264
+ * @param {Scope} scope scope
265
+ * @param {Node} node schema argument
266
+ * @returns {{ request: string, required: boolean } | undefined} request of the schema file and whether it is loaded with `require`
267
+ */
268
+ const getSchemaRequest = (scope, node) => {
269
+ // `() => require("./options.json")`, a schema loaded on demand
270
+ if (
271
+ node.type === "ArrowFunctionExpression" &&
272
+ node.body.type !== "BlockStatement"
273
+ ) {
274
+ return getSchemaRequest(scope, node.body);
275
+ }
276
+
277
+ const required = requiredModule(node);
278
+
279
+ if (required !== undefined) return { request: required, required: true };
280
+
281
+ if (node.type === "Identifier") {
282
+ const variable = findVariable(scope, node);
283
+
284
+ if (!variable || variable.defs.length !== 1) return undefined;
285
+
286
+ const [definition] = variable.defs;
287
+
288
+ if (
289
+ definition.type === "ImportBinding" &&
290
+ definition.node.type === "ImportDefaultSpecifier"
291
+ ) {
292
+ const source = /** @type {import("estree").ImportDeclaration} */ (
293
+ definition.parent
294
+ ).source.value;
295
+
296
+ return typeof source === "string"
297
+ ? { request: source, required: false }
298
+ : undefined;
299
+ }
300
+
301
+ if (
302
+ definition.type === "Variable" &&
303
+ definition.node.id.type === "Identifier"
304
+ ) {
305
+ const request = requiredModule(definition.node.init);
306
+
307
+ return request === undefined ? undefined : { request, required: true };
308
+ }
309
+ }
310
+
311
+ return undefined;
312
+ };
313
+
314
+ /** @type {import("eslint").Rule.RuleModule} */
315
+ export const rule = {
316
+ create(context) {
317
+ const { sourceCode } = context;
318
+
319
+ return {
320
+ CallExpression(node) {
321
+ if (node.arguments.some((item) => item.type === "SpreadElement")) {
322
+ return;
323
+ }
324
+
325
+ const scope = sourceCode.getScope(node);
326
+ const api = getApi(scope, node);
327
+
328
+ // No schema means no validation, `getOptions()` only parses the options
329
+ if (
330
+ !api ||
331
+ node.arguments.length === 0 ||
332
+ node.arguments.length > api.checkIndex
333
+ ) {
334
+ return;
335
+ }
336
+
337
+ const [schemaArgument] = node.arguments;
338
+ const found = getSchemaRequest(
339
+ scope,
340
+ /** @type {Node} */ (schemaArgument),
341
+ );
342
+ // Only a schema file next to the code can be precompiled from here
343
+ const schema =
344
+ found !== undefined &&
345
+ /^\.\.?\//.test(found.request) &&
346
+ found.request.endsWith(".json")
347
+ ? found
348
+ : undefined;
349
+ const command =
350
+ schema === undefined
351
+ ? "npx schema-utils precompile <schema.json>"
352
+ : `npx schema-utils precompile ${path.posix.join(
353
+ path.posix.dirname(
354
+ path
355
+ .relative(context.cwd, context.physicalFilename)
356
+ .replaceAll("\\", "/"),
357
+ ),
358
+ schema.request,
359
+ )}`;
360
+
361
+ /** @type {import("eslint").Rule.SuggestionReportDescriptor[]} */
362
+ const suggest = [];
363
+ const checkRequest =
364
+ schema === undefined
365
+ ? undefined
366
+ : `${schema.request.slice(0, -".json".length)}.check.js`;
367
+
368
+ // An imported schema would need an import of the check added too
369
+ if (
370
+ schema?.required &&
371
+ checkRequest !== undefined &&
372
+ fs.existsSync(
373
+ path.resolve(path.dirname(context.physicalFilename), checkRequest),
374
+ )
375
+ ) {
376
+ const missing = api.checkIndex - node.arguments.length;
377
+ const lastArgument = node.arguments.at(-1);
378
+
379
+ suggest.push({
380
+ messageId: "useCheck",
381
+ data: { check: checkRequest },
382
+ fix: (fixer) =>
383
+ fixer.insertTextAfter(
384
+ lastArgument,
385
+ `${", undefined".repeat(missing)}, require(${JSON.stringify(checkRequest)})`,
386
+ ),
387
+ });
388
+ }
389
+
390
+ context.report({
391
+ node,
392
+ messageId: "missingCheck",
393
+ data: { api: api.name, command },
394
+ suggest,
395
+ });
396
+ },
397
+ };
398
+ },
399
+ meta: {
400
+ docs: {
401
+ description:
402
+ "Require a precompiled check when validating options against a schema",
403
+ recommended: true,
404
+ },
405
+ hasSuggestions: true,
406
+ messages: {
407
+ missingCheck:
408
+ "Validating against a schema without a precompiled check loads `ajv` and compiles the schema on every start, about 150ms for the first one. Precompile it with `{{command}}` and pass the check: `{{api}}`.",
409
+ useCheck: "Pass the precompiled check `{{check}}`.",
410
+ },
411
+ schema: [],
412
+ type: "suggestion",
413
+ },
414
+ };
@@ -1,5 +1,4 @@
1
1
  import { createRequire } from "node:module";
2
- // eslint-disable-next-line import/no-unresolved
3
2
  import * as parserJsonc from "jsonc-eslint-parser";
4
3
  import { allExtensions } from "../../configs/utils/extensions.js";
5
4
  import { rule as commentLength } from "./rules/comment-length.js";
@@ -1,5 +1,4 @@
1
- /** @typedef {import("estree").Comment} Comment */
2
- /** @typedef {import("estree").Program} Program */
1
+ /** @import { Comment, Program } from "estree" */
3
2
  /** @typedef {import("estree").Statement | import("estree").ModuleDeclaration} ProgramEntry */
4
3
  /** @typedef {import("eslint").AST.SourceLocation} SourceLocation */
5
4
  /** @typedef {Comment & { range: [number, number], loc: SourceLocation }} LocatedComment */
@@ -107,7 +106,6 @@ export const rule = {
107
106
  },
108
107
  meta: {
109
108
  docs: {
110
- category: "Stylistic Issues",
111
109
  description: "Limit how many lines a plain comment spans",
112
110
  recommended: false,
113
111
  },
@@ -52,11 +52,13 @@ function processSchema(visitor, json, context) {
52
52
  if (visitor.schema) json = visitor.schema(json, context);
53
53
 
54
54
  for (const name of NESTED_WITH_NAME) {
55
- if (name in json && json[name] && typeof json[name] === "object") {
56
- if (visitor.object) json[name] = visitor.object(json[name], context);
57
- for (const key of Object.keys(json[name])) {
58
- json[name][key] = processSchema(visitor, json[name][key], context);
59
- }
55
+ if (!(name in json && json[name] && typeof json[name] === "object")) {
56
+ continue;
57
+ }
58
+
59
+ if (visitor.object) json[name] = visitor.object(json[name], context);
60
+ for (const key of Object.keys(json[name])) {
61
+ json[name][key] = processSchema(visitor, json[name][key], context);
60
62
  }
61
63
  }
62
64
  for (const name of NESTED_DIRECT) {
@@ -65,13 +67,15 @@ function processSchema(visitor, json, context) {
65
67
  }
66
68
  }
67
69
  for (const name of NESTED_ARRAY) {
68
- if (name in json && Array.isArray(json[name])) {
69
- json[name] = [...json[name]];
70
- for (let i = 0; i < json[name].length; i++) {
71
- json[name][i] = processSchema(visitor, json[name][i], context);
72
- }
73
- if (visitor.array) json[name] = visitor.array(json[name], context);
70
+ if (!(name in json && Array.isArray(json[name]))) {
71
+ continue;
74
72
  }
73
+
74
+ json[name] = [...json[name]];
75
+ for (let i = 0; i < json[name].length; i++) {
76
+ json[name][i] = processSchema(visitor, json[name][i], context);
77
+ }
78
+ if (visitor.array) json[name] = visitor.array(json[name], context);
75
79
  }
76
80
 
77
81
  return json;
@@ -100,10 +104,9 @@ function sortArrayByType(array) {
100
104
  const bType = b.type || b.instanceof || (b.enum && "enum");
101
105
  const aPosition = TYPE_ORDER.indexOf(aType);
102
106
  const bPosition = TYPE_ORDER.indexOf(bType);
103
- if (aPosition === bPosition) {
104
- return array.indexOf(a) - array.indexOf(b);
105
- }
106
- return aPosition - bPosition;
107
+ return aPosition === bPosition
108
+ ? array.indexOf(a) - array.indexOf(b)
109
+ : aPosition - bPosition;
107
110
  });
108
111
  }
109
112
 
@@ -311,7 +314,6 @@ export const rule = {
311
314
  },
312
315
  meta: {
313
316
  docs: {
314
- category: "Stylistic Issues",
315
317
  description:
316
318
  "Keep schema keys ordered and shared definitions in sync with the base schema",
317
319
  recommended: false,
@@ -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
  },