eslint 9.14.0 → 9.16.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 (99) hide show
  1. package/README.md +1 -1
  2. package/lib/cli-engine/formatters/stylish.js +3 -3
  3. package/lib/cli-engine/lint-result-cache.js +1 -1
  4. package/lib/config/config.js +40 -24
  5. package/lib/eslint/eslint-helpers.js +9 -13
  6. package/lib/languages/js/index.js +76 -0
  7. package/lib/languages/js/source-code/token-store/index.js +1 -1
  8. package/lib/linter/code-path-analysis/code-path-analyzer.js +1 -1
  9. package/lib/linter/code-path-analysis/fork-context.js +1 -1
  10. package/lib/linter/linter.js +36 -35
  11. package/lib/linter/report-translator.js +1 -1
  12. package/lib/rule-tester/rule-tester.js +1 -1
  13. package/lib/rules/accessor-pairs.js +14 -10
  14. package/lib/rules/array-callback-return.js +10 -8
  15. package/lib/rules/arrow-body-style.js +3 -1
  16. package/lib/rules/camelcase.js +18 -12
  17. package/lib/rules/class-methods-use-this.js +9 -5
  18. package/lib/rules/complexity.js +9 -5
  19. package/lib/rules/consistent-return.js +4 -4
  20. package/lib/rules/consistent-this.js +3 -7
  21. package/lib/rules/curly.js +3 -140
  22. package/lib/rules/default-case.js +3 -1
  23. package/lib/rules/dot-notation.js +9 -6
  24. package/lib/rules/func-names.js +3 -3
  25. package/lib/rules/func-style.js +10 -8
  26. package/lib/rules/getter-return.js +7 -5
  27. package/lib/rules/grouped-accessor-pairs.js +3 -1
  28. package/lib/rules/id-denylist.js +2 -1
  29. package/lib/rules/id-length.js +11 -6
  30. package/lib/rules/id-match.js +18 -16
  31. package/lib/rules/new-cap.js +16 -35
  32. package/lib/rules/no-bitwise.js +7 -5
  33. package/lib/rules/no-compare-neg-zero.js +1 -1
  34. package/lib/rules/no-cond-assign.js +3 -3
  35. package/lib/rules/no-console.js +3 -2
  36. package/lib/rules/no-constant-condition.js +5 -4
  37. package/lib/rules/no-duplicate-imports.js +7 -4
  38. package/lib/rules/no-else-return.js +4 -5
  39. package/lib/rules/no-empty-function.js +4 -4
  40. package/lib/rules/no-empty-pattern.js +6 -4
  41. package/lib/rules/no-empty.js +6 -5
  42. package/lib/rules/no-eval.js +6 -5
  43. package/lib/rules/no-extend-native.js +3 -3
  44. package/lib/rules/no-extra-boolean-cast.js +3 -3
  45. package/lib/rules/no-fallthrough.js +12 -15
  46. package/lib/rules/no-global-assign.js +3 -2
  47. package/lib/rules/no-implicit-coercion.js +13 -24
  48. package/lib/rules/no-implicit-globals.js +6 -4
  49. package/lib/rules/no-inline-comments.js +4 -6
  50. package/lib/rules/no-inner-declarations.js +5 -3
  51. package/lib/rules/no-invalid-regexp.js +5 -4
  52. package/lib/rules/no-invalid-this.js +4 -4
  53. package/lib/rules/no-irregular-whitespace.js +24 -22
  54. package/lib/rules/no-labels.js +8 -7
  55. package/lib/rules/no-lonely-if.js +8 -2
  56. package/lib/rules/no-multi-assign.js +7 -10
  57. package/lib/rules/no-plusplus.js +6 -9
  58. package/lib/rules/no-promise-executor-return.js +6 -6
  59. package/lib/rules/no-redeclare.js +5 -8
  60. package/lib/rules/no-return-assign.js +3 -1
  61. package/lib/rules/no-self-assign.js +4 -3
  62. package/lib/rules/no-sequences.js +7 -7
  63. package/lib/rules/no-shadow.js +21 -15
  64. package/lib/rules/no-undef.js +6 -4
  65. package/lib/rules/no-underscore-dangle.js +32 -28
  66. package/lib/rules/no-unneeded-ternary.js +4 -4
  67. package/lib/rules/no-unreachable-loop.js +4 -2
  68. package/lib/rules/no-unsafe-negation.js +6 -4
  69. package/lib/rules/no-unsafe-optional-chaining.js +6 -4
  70. package/lib/rules/no-unused-expressions.js +17 -13
  71. package/lib/rules/no-use-before-define.js +15 -13
  72. package/lib/rules/no-useless-computed-key.js +10 -4
  73. package/lib/rules/no-useless-rename.js +11 -8
  74. package/lib/rules/no-void.js +6 -4
  75. package/lib/rules/no-warning-comments.js +9 -7
  76. package/lib/rules/operator-assignment.js +4 -2
  77. package/lib/rules/prefer-arrow-callback.js +5 -8
  78. package/lib/rules/prefer-const.js +9 -5
  79. package/lib/rules/prefer-promise-reject-errors.js +7 -3
  80. package/lib/rules/prefer-regex-literals.js +6 -3
  81. package/lib/rules/radix.js +3 -1
  82. package/lib/rules/require-atomic-updates.js +6 -3
  83. package/lib/rules/sort-imports.js +20 -16
  84. package/lib/rules/sort-keys.js +22 -16
  85. package/lib/rules/sort-vars.js +7 -6
  86. package/lib/rules/strict.js +3 -2
  87. package/lib/rules/unicode-bom.js +4 -2
  88. package/lib/rules/use-isnan.js +8 -6
  89. package/lib/rules/utils/ast-utils.js +141 -0
  90. package/lib/rules/valid-typeof.js +6 -4
  91. package/lib/rules/yoda.js +9 -12
  92. package/lib/shared/assert.js +22 -0
  93. package/lib/shared/deep-merge-arrays.js +60 -0
  94. package/lib/shared/text-table.js +67 -0
  95. package/lib/shared/types.js +1 -0
  96. package/lib/types/index.d.ts +3 -0
  97. package/lib/types/rules/ecmascript-6.d.ts +36 -16
  98. package/lib/types/rules/stylistic-issues.d.ts +7 -0
  99. package/package.json +11 -12
@@ -29,23 +29,6 @@ const CAPS_ALLOWED = [
29
29
  "BigInt"
30
30
  ];
31
31
 
32
- /**
33
- * Ensure that if the key is provided, it must be an array.
34
- * @param {Object} obj Object to check with `key`.
35
- * @param {string} key Object key to check on `obj`.
36
- * @param {any} fallback If obj[key] is not present, this will be returned.
37
- * @throws {TypeError} If key is not an own array type property of `obj`.
38
- * @returns {string[]} Returns obj[key] if it's an Array, otherwise `fallback`
39
- */
40
- function checkArray(obj, key, fallback) {
41
-
42
- /* c8 ignore start */
43
- if (Object.hasOwn(obj, key) && !Array.isArray(obj[key])) {
44
- throw new TypeError(`${key}, if provided, must be an Array`);
45
- }/* c8 ignore stop */
46
- return obj[key] || fallback;
47
- }
48
-
49
32
  /**
50
33
  * A reducer function to invert an array to an Object mapping the string form of the key, to `true`.
51
34
  * @param {Object} map Accumulator object for the reduce.
@@ -63,11 +46,7 @@ function invert(map, key) {
63
46
  * @returns {Object} Object with cap is new exceptions.
64
47
  */
65
48
  function calculateCapIsNewExceptions(config) {
66
- let capIsNewExceptions = checkArray(config, "capIsNewExceptions", CAPS_ALLOWED);
67
-
68
- if (capIsNewExceptions !== CAPS_ALLOWED) {
69
- capIsNewExceptions = capIsNewExceptions.concat(CAPS_ALLOWED);
70
- }
49
+ const capIsNewExceptions = Array.from(new Set([...config.capIsNewExceptions, ...CAPS_ALLOWED]));
71
50
 
72
51
  return capIsNewExceptions.reduce(invert, {});
73
52
  }
@@ -92,12 +71,10 @@ module.exports = {
92
71
  type: "object",
93
72
  properties: {
94
73
  newIsCap: {
95
- type: "boolean",
96
- default: true
74
+ type: "boolean"
97
75
  },
98
76
  capIsNew: {
99
- type: "boolean",
100
- default: true
77
+ type: "boolean"
101
78
  },
102
79
  newIsCapExceptions: {
103
80
  type: "array",
@@ -118,13 +95,21 @@ module.exports = {
118
95
  type: "string"
119
96
  },
120
97
  properties: {
121
- type: "boolean",
122
- default: true
98
+ type: "boolean"
123
99
  }
124
100
  },
125
101
  additionalProperties: false
126
102
  }
127
103
  ],
104
+
105
+ defaultOptions: [{
106
+ capIsNew: true,
107
+ capIsNewExceptions: CAPS_ALLOWED,
108
+ newIsCap: true,
109
+ newIsCapExceptions: [],
110
+ properties: true
111
+ }],
112
+
128
113
  messages: {
129
114
  upper: "A function with a name starting with an uppercase letter should only be used as a constructor.",
130
115
  lower: "A constructor name should not start with a lowercase letter."
@@ -132,14 +117,10 @@ module.exports = {
132
117
  },
133
118
 
134
119
  create(context) {
120
+ const [config] = context.options;
121
+ const skipProperties = !config.properties;
135
122
 
136
- const config = Object.assign({}, context.options[0]);
137
-
138
- config.newIsCap = config.newIsCap !== false;
139
- config.capIsNew = config.capIsNew !== false;
140
- const skipProperties = config.properties === false;
141
-
142
- const newIsCapExceptions = checkArray(config, "newIsCapExceptions", []).reduce(invert, {});
123
+ const newIsCapExceptions = config.newIsCapExceptions.reduce(invert, {});
143
124
  const newIsCapExceptionPattern = config.newIsCapExceptionPattern ? new RegExp(config.newIsCapExceptionPattern, "u") : null;
144
125
 
145
126
  const capIsNewExceptions = calculateCapIsNewExceptions(config);
@@ -25,6 +25,11 @@ module.exports = {
25
25
  meta: {
26
26
  type: "suggestion",
27
27
 
28
+ defaultOptions: [{
29
+ allow: [],
30
+ int32Hint: false
31
+ }],
32
+
28
33
  docs: {
29
34
  description: "Disallow bitwise operators",
30
35
  recommended: false,
@@ -43,8 +48,7 @@ module.exports = {
43
48
  uniqueItems: true
44
49
  },
45
50
  int32Hint: {
46
- type: "boolean",
47
- default: false
51
+ type: "boolean"
48
52
  }
49
53
  },
50
54
  additionalProperties: false
@@ -57,9 +61,7 @@ module.exports = {
57
61
  },
58
62
 
59
63
  create(context) {
60
- const options = context.options[0] || {};
61
- const allowed = options.allow || [];
62
- const int32Hint = options.int32Hint === true;
64
+ const [{ allow: allowed, int32Hint }] = context.options;
63
65
 
64
66
  /**
65
67
  * Reports an unexpected use of a bitwise operator.
@@ -14,7 +14,7 @@ module.exports = {
14
14
  type: "problem",
15
15
 
16
16
  docs: {
17
- description: "Disallow comparing against -0",
17
+ description: "Disallow comparing against `-0`",
18
18
  recommended: true,
19
19
  url: "https://eslint.org/docs/latest/rules/no-compare-neg-zero"
20
20
  },
@@ -33,6 +33,8 @@ module.exports = {
33
33
  meta: {
34
34
  type: "problem",
35
35
 
36
+ defaultOptions: ["except-parens"],
37
+
36
38
  docs: {
37
39
  description: "Disallow assignment operators in conditional expressions",
38
40
  recommended: true,
@@ -54,9 +56,7 @@ module.exports = {
54
56
  },
55
57
 
56
58
  create(context) {
57
-
58
- const prohibitAssign = (context.options[0] || "except-parens");
59
-
59
+ const [prohibitAssign] = context.options;
60
60
  const sourceCode = context.sourceCode;
61
61
 
62
62
  /**
@@ -20,6 +20,8 @@ module.exports = {
20
20
  meta: {
21
21
  type: "suggestion",
22
22
 
23
+ defaultOptions: [{}],
24
+
23
25
  docs: {
24
26
  description: "Disallow the use of `console`",
25
27
  recommended: false,
@@ -52,8 +54,7 @@ module.exports = {
52
54
  },
53
55
 
54
56
  create(context) {
55
- const options = context.options[0] || {};
56
- const allowed = options.allow || [];
57
+ const [{ allow: allowed = [] }] = context.options;
57
58
  const sourceCode = context.sourceCode;
58
59
 
59
60
  /**
@@ -20,6 +20,8 @@ module.exports = {
20
20
  meta: {
21
21
  type: "problem",
22
22
 
23
+ defaultOptions: [{ checkLoops: "allExceptWhileTrue" }],
24
+
23
25
  docs: {
24
26
  description: "Disallow constant expressions in conditions",
25
27
  recommended: true,
@@ -44,14 +46,13 @@ module.exports = {
44
46
  },
45
47
 
46
48
  create(context) {
47
- const options = context.options[0] || {};
48
- let checkLoops = options.checkLoops ?? "allExceptWhileTrue";
49
49
  const loopSetStack = [];
50
50
  const sourceCode = context.sourceCode;
51
+ let [{ checkLoops }] = context.options;
51
52
 
52
- if (options.checkLoops === true) {
53
+ if (checkLoops === true) {
53
54
  checkLoops = "all";
54
- } else if (options.checkLoops === false) {
55
+ } else if (checkLoops === false) {
55
56
  checkLoops = "none";
56
57
  }
57
58
 
@@ -232,6 +232,10 @@ module.exports = {
232
232
  meta: {
233
233
  type: "problem",
234
234
 
235
+ defaultOptions: [{
236
+ includeExports: false
237
+ }],
238
+
235
239
  docs: {
236
240
  description: "Disallow duplicate module imports",
237
241
  recommended: false,
@@ -243,8 +247,7 @@ module.exports = {
243
247
  type: "object",
244
248
  properties: {
245
249
  includeExports: {
246
- type: "boolean",
247
- default: false
250
+ type: "boolean"
248
251
  }
249
252
  },
250
253
  additionalProperties: false
@@ -260,8 +263,8 @@ module.exports = {
260
263
  },
261
264
 
262
265
  create(context) {
263
- const includeExports = (context.options[0] || {}).includeExports,
264
- modules = new Map();
266
+ const [{ includeExports }] = context.options;
267
+ const modules = new Map();
265
268
  const handlers = {
266
269
  ImportDeclaration: handleImportsExports(
267
270
  context,
@@ -21,6 +21,8 @@ module.exports = {
21
21
  meta: {
22
22
  type: "suggestion",
23
23
 
24
+ defaultOptions: [{ allowElseIf: true }],
25
+
24
26
  docs: {
25
27
  description: "Disallow `else` blocks after `return` statements in `if` statements",
26
28
  recommended: false,
@@ -31,8 +33,7 @@ module.exports = {
31
33
  type: "object",
32
34
  properties: {
33
35
  allowElseIf: {
34
- type: "boolean",
35
- default: true
36
+ type: "boolean"
36
37
  }
37
38
  },
38
39
  additionalProperties: false
@@ -46,7 +47,7 @@ module.exports = {
46
47
  },
47
48
 
48
49
  create(context) {
49
-
50
+ const [{ allowElseIf }] = context.options;
50
51
  const sourceCode = context.sourceCode;
51
52
 
52
53
  //--------------------------------------------------------------------------
@@ -389,8 +390,6 @@ module.exports = {
389
390
  }
390
391
  }
391
392
 
392
- const allowElseIf = !(context.options[0] && context.options[0].allowElseIf === false);
393
-
394
393
  //--------------------------------------------------------------------------
395
394
  // Public API
396
395
  //--------------------------------------------------------------------------
@@ -94,6 +94,8 @@ module.exports = {
94
94
  meta: {
95
95
  type: "suggestion",
96
96
 
97
+ defaultOptions: [{ allow: [] }],
98
+
97
99
  docs: {
98
100
  description: "Disallow empty functions",
99
101
  recommended: false,
@@ -120,9 +122,7 @@ module.exports = {
120
122
  },
121
123
 
122
124
  create(context) {
123
- const options = context.options[0] || {};
124
- const allowed = options.allow || [];
125
-
125
+ const [{ allow }] = context.options;
126
126
  const sourceCode = context.sourceCode;
127
127
 
128
128
  /**
@@ -144,7 +144,7 @@ module.exports = {
144
144
  filter: astUtils.isCommentToken
145
145
  });
146
146
 
147
- if (!allowed.includes(kind) &&
147
+ if (!allow.includes(kind) &&
148
148
  node.body.type === "BlockStatement" &&
149
149
  node.body.body.length === 0 &&
150
150
  innerComments.length === 0
@@ -15,6 +15,10 @@ module.exports = {
15
15
  meta: {
16
16
  type: "problem",
17
17
 
18
+ defaultOptions: [{
19
+ allowObjectPatternsAsParameters: false
20
+ }],
21
+
18
22
  docs: {
19
23
  description: "Disallow empty destructuring patterns",
20
24
  recommended: true,
@@ -26,8 +30,7 @@ module.exports = {
26
30
  type: "object",
27
31
  properties: {
28
32
  allowObjectPatternsAsParameters: {
29
- type: "boolean",
30
- default: false
33
+ type: "boolean"
31
34
  }
32
35
  },
33
36
  additionalProperties: false
@@ -40,8 +43,7 @@ module.exports = {
40
43
  },
41
44
 
42
45
  create(context) {
43
- const options = context.options[0] || {},
44
- allowObjectPatternsAsParameters = options.allowObjectPatternsAsParameters || false;
46
+ const [{ allowObjectPatternsAsParameters }] = context.options;
45
47
 
46
48
  return {
47
49
  ObjectPattern(node) {
@@ -20,6 +20,10 @@ module.exports = {
20
20
  hasSuggestions: true,
21
21
  type: "suggestion",
22
22
 
23
+ defaultOptions: [{
24
+ allowEmptyCatch: false
25
+ }],
26
+
23
27
  docs: {
24
28
  description: "Disallow empty block statements",
25
29
  recommended: true,
@@ -31,8 +35,7 @@ module.exports = {
31
35
  type: "object",
32
36
  properties: {
33
37
  allowEmptyCatch: {
34
- type: "boolean",
35
- default: false
38
+ type: "boolean"
36
39
  }
37
40
  },
38
41
  additionalProperties: false
@@ -46,9 +49,7 @@ module.exports = {
46
49
  },
47
50
 
48
51
  create(context) {
49
- const options = context.options[0] || {},
50
- allowEmptyCatch = options.allowEmptyCatch || false;
51
-
52
+ const [{ allowEmptyCatch }] = context.options;
52
53
  const sourceCode = context.sourceCode;
53
54
 
54
55
  return {
@@ -42,6 +42,10 @@ module.exports = {
42
42
  meta: {
43
43
  type: "suggestion",
44
44
 
45
+ defaultOptions: [{
46
+ allowIndirect: false
47
+ }],
48
+
45
49
  docs: {
46
50
  description: "Disallow the use of `eval()`",
47
51
  recommended: false,
@@ -52,7 +56,7 @@ module.exports = {
52
56
  {
53
57
  type: "object",
54
58
  properties: {
55
- allowIndirect: { type: "boolean", default: false }
59
+ allowIndirect: { type: "boolean" }
56
60
  },
57
61
  additionalProperties: false
58
62
  }
@@ -64,10 +68,7 @@ module.exports = {
64
68
  },
65
69
 
66
70
  create(context) {
67
- const allowIndirect = Boolean(
68
- context.options[0] &&
69
- context.options[0].allowIndirect
70
- );
71
+ const [{ allowIndirect }] = context.options;
71
72
  const sourceCode = context.sourceCode;
72
73
  let funcInfo = null;
73
74
 
@@ -20,6 +20,8 @@ module.exports = {
20
20
  meta: {
21
21
  type: "suggestion",
22
22
 
23
+ defaultOptions: [{ exceptions: [] }],
24
+
23
25
  docs: {
24
26
  description: "Disallow extending native types",
25
27
  recommended: false,
@@ -48,10 +50,8 @@ module.exports = {
48
50
  },
49
51
 
50
52
  create(context) {
51
-
52
- const config = context.options[0] || {};
53
53
  const sourceCode = context.sourceCode;
54
- const exceptions = new Set(config.exceptions || []);
54
+ const exceptions = new Set(context.options[0].exceptions);
55
55
  const modifiedBuiltins = new Set(
56
56
  Object.keys(astUtils.ECMASCRIPT_GLOBALS)
57
57
  .filter(builtin => builtin[0].toUpperCase() === builtin[0])
@@ -23,6 +23,8 @@ module.exports = {
23
23
  meta: {
24
24
  type: "suggestion",
25
25
 
26
+ defaultOptions: [{}],
27
+
26
28
  docs: {
27
29
  description: "Disallow unnecessary boolean casts",
28
30
  recommended: true,
@@ -63,9 +65,7 @@ module.exports = {
63
65
 
64
66
  create(context) {
65
67
  const sourceCode = context.sourceCode;
66
- const enforceForLogicalOperands = context.options[0]?.enforceForLogicalOperands === true;
67
- const enforceForInnerExpressions = context.options[0]?.enforceForInnerExpressions === true;
68
-
68
+ const [{ enforceForLogicalOperands, enforceForInnerExpressions }] = context.options;
69
69
 
70
70
  // Node types which have a test which will coerce values to booleans.
71
71
  const BOOLEAN_NODE_TYPES = new Set([
@@ -90,6 +90,11 @@ module.exports = {
90
90
  meta: {
91
91
  type: "problem",
92
92
 
93
+ defaultOptions: [{
94
+ allowEmptyCase: false,
95
+ reportUnusedFallthroughComment: false
96
+ }],
97
+
93
98
  docs: {
94
99
  description: "Disallow fallthrough of `case` statements",
95
100
  recommended: true,
@@ -101,16 +106,13 @@ module.exports = {
101
106
  type: "object",
102
107
  properties: {
103
108
  commentPattern: {
104
- type: "string",
105
- default: ""
109
+ type: "string"
106
110
  },
107
111
  allowEmptyCase: {
108
- type: "boolean",
109
- default: false
112
+ type: "boolean"
110
113
  },
111
114
  reportUnusedFallthroughComment: {
112
- type: "boolean",
113
- default: false
115
+ type: "boolean"
114
116
  }
115
117
  },
116
118
  additionalProperties: false
@@ -124,25 +126,20 @@ module.exports = {
124
126
  },
125
127
 
126
128
  create(context) {
127
- const options = context.options[0] || {};
128
129
  const codePathSegments = [];
129
130
  let currentCodePathSegments = new Set();
130
131
  const sourceCode = context.sourceCode;
131
- const allowEmptyCase = options.allowEmptyCase || false;
132
- const reportUnusedFallthroughComment = options.reportUnusedFallthroughComment || false;
132
+ const [{ allowEmptyCase, commentPattern, reportUnusedFallthroughComment }] = context.options;
133
+ const fallthroughCommentPattern = commentPattern
134
+ ? new RegExp(commentPattern, "u")
135
+ : DEFAULT_FALLTHROUGH_COMMENT;
133
136
 
134
137
  /*
135
138
  * We need to use leading comments of the next SwitchCase node because
136
139
  * trailing comments is wrong if semicolons are omitted.
137
140
  */
138
141
  let previousCase = null;
139
- let fallthroughCommentPattern = null;
140
142
 
141
- if (options.commentPattern) {
142
- fallthroughCommentPattern = new RegExp(options.commentPattern, "u");
143
- } else {
144
- fallthroughCommentPattern = DEFAULT_FALLTHROUGH_COMMENT;
145
- }
146
143
  return {
147
144
 
148
145
  onCodePathStart() {
@@ -14,6 +14,8 @@ module.exports = {
14
14
  meta: {
15
15
  type: "suggestion",
16
16
 
17
+ defaultOptions: [{ exceptions: [] }],
18
+
17
19
  docs: {
18
20
  description: "Disallow assignments to native objects or read-only global variables",
19
21
  recommended: true,
@@ -40,9 +42,8 @@ module.exports = {
40
42
  },
41
43
 
42
44
  create(context) {
43
- const config = context.options[0];
44
45
  const sourceCode = context.sourceCode;
45
- const exceptions = (config && config.exceptions) || [];
46
+ const [{ exceptions }] = context.options;
46
47
 
47
48
  /**
48
49
  * Reports write references.
@@ -14,21 +14,6 @@ const astUtils = require("./utils/ast-utils");
14
14
  const INDEX_OF_PATTERN = /^(?:i|lastI)ndexOf$/u;
15
15
  const ALLOWABLE_OPERATORS = ["~", "!!", "+", "- -", "-", "*"];
16
16
 
17
- /**
18
- * Parses and normalizes an option object.
19
- * @param {Object} options An option object to parse.
20
- * @returns {Object} The parsed and normalized option object.
21
- */
22
- function parseOptions(options) {
23
- return {
24
- boolean: "boolean" in options ? options.boolean : true,
25
- number: "number" in options ? options.number : true,
26
- string: "string" in options ? options.string : true,
27
- disallowTemplateShorthand: "disallowTemplateShorthand" in options ? options.disallowTemplateShorthand : false,
28
- allow: options.allow || []
29
- };
30
- }
31
-
32
17
  /**
33
18
  * Checks whether or not a node is a double logical negating.
34
19
  * @param {ASTNode} node An UnaryExpression node to check.
@@ -203,20 +188,16 @@ module.exports = {
203
188
  type: "object",
204
189
  properties: {
205
190
  boolean: {
206
- type: "boolean",
207
- default: true
191
+ type: "boolean"
208
192
  },
209
193
  number: {
210
- type: "boolean",
211
- default: true
194
+ type: "boolean"
212
195
  },
213
196
  string: {
214
- type: "boolean",
215
- default: true
197
+ type: "boolean"
216
198
  },
217
199
  disallowTemplateShorthand: {
218
- type: "boolean",
219
- default: false
200
+ type: "boolean"
220
201
  },
221
202
  allow: {
222
203
  type: "array",
@@ -229,6 +210,14 @@ module.exports = {
229
210
  additionalProperties: false
230
211
  }],
231
212
 
213
+ defaultOptions: [{
214
+ allow: [],
215
+ boolean: true,
216
+ disallowTemplateShorthand: false,
217
+ number: true,
218
+ string: true
219
+ }],
220
+
232
221
  messages: {
233
222
  implicitCoercion: "Unexpected implicit coercion encountered. Use `{{recommendation}}` instead.",
234
223
  useRecommendation: "Use `{{recommendation}}` instead."
@@ -236,7 +225,7 @@ module.exports = {
236
225
  },
237
226
 
238
227
  create(context) {
239
- const options = parseOptions(context.options[0] || {});
228
+ const [options] = context.options;
240
229
  const sourceCode = context.sourceCode;
241
230
 
242
231
  /**
@@ -14,6 +14,10 @@ module.exports = {
14
14
  meta: {
15
15
  type: "suggestion",
16
16
 
17
+ defaultOptions: [{
18
+ lexicalBindings: false
19
+ }],
20
+
17
21
  docs: {
18
22
  description: "Disallow declarations in the global scope",
19
23
  recommended: false,
@@ -24,8 +28,7 @@ module.exports = {
24
28
  type: "object",
25
29
  properties: {
26
30
  lexicalBindings: {
27
- type: "boolean",
28
- default: false
31
+ type: "boolean"
29
32
  }
30
33
  },
31
34
  additionalProperties: false
@@ -41,8 +44,7 @@ module.exports = {
41
44
  },
42
45
 
43
46
  create(context) {
44
-
45
- const checkLexicalBindings = context.options[0] && context.options[0].lexicalBindings === true;
47
+ const [{ lexicalBindings: checkLexicalBindings }] = context.options;
46
48
  const sourceCode = context.sourceCode;
47
49
 
48
50
  /**
@@ -15,6 +15,8 @@ module.exports = {
15
15
  meta: {
16
16
  type: "suggestion",
17
17
 
18
+ defaultOptions: [{}],
19
+
18
20
  docs: {
19
21
  description: "Disallow inline comments after code",
20
22
  recommended: false,
@@ -40,12 +42,8 @@ module.exports = {
40
42
 
41
43
  create(context) {
42
44
  const sourceCode = context.sourceCode;
43
- const options = context.options[0];
44
- let customIgnoreRegExp;
45
-
46
- if (options && options.ignorePattern) {
47
- customIgnoreRegExp = new RegExp(options.ignorePattern, "u");
48
- }
45
+ const [{ ignorePattern }] = context.options;
46
+ const customIgnoreRegExp = ignorePattern && new RegExp(ignorePattern, "u");
49
47
 
50
48
  /**
51
49
  * Will check that comments are not on lines starting with or ending with code