eslint 5.13.0 → 5.15.1

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 (148) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/README.md +68 -156
  3. package/lib/built-in-rules-index.js +1 -0
  4. package/lib/cli-engine.js +5 -2
  5. package/lib/config/config-file.js +27 -4
  6. package/lib/config/config-initializer.js +151 -144
  7. package/lib/config/config-ops.js +2 -0
  8. package/lib/config/config-validator.js +1 -1
  9. package/lib/config/plugins.js +1 -1
  10. package/lib/formatters/codeframe.js +1 -1
  11. package/lib/formatters/stylish.js +2 -2
  12. package/lib/linter.js +7 -4
  13. package/lib/rules/accessor-pairs.js +4 -2
  14. package/lib/rules/array-callback-return.js +4 -3
  15. package/lib/rules/arrow-body-style.js +1 -1
  16. package/lib/rules/arrow-parens.js +2 -1
  17. package/lib/rules/arrow-spacing.js +7 -6
  18. package/lib/rules/brace-style.js +2 -1
  19. package/lib/rules/camelcase.js +5 -4
  20. package/lib/rules/capitalized-comments.js +10 -14
  21. package/lib/rules/class-methods-use-this.js +1 -1
  22. package/lib/rules/comma-spacing.js +10 -4
  23. package/lib/rules/complexity.js +6 -7
  24. package/lib/rules/consistent-return.js +2 -1
  25. package/lib/rules/curly.js +1 -1
  26. package/lib/rules/default-case.js +2 -2
  27. package/lib/rules/dot-notation.js +7 -5
  28. package/lib/rules/eol-last.js +1 -1
  29. package/lib/rules/func-call-spacing.js +2 -2
  30. package/lib/rules/func-style.js +3 -2
  31. package/lib/rules/getter-return.js +3 -2
  32. package/lib/rules/handle-callback-err.js +1 -1
  33. package/lib/rules/id-length.js +3 -2
  34. package/lib/rules/id-match.js +7 -4
  35. package/lib/rules/indent-legacy.js +1 -1
  36. package/lib/rules/indent.js +9 -6
  37. package/lib/rules/jsx-quotes.js +2 -2
  38. package/lib/rules/key-spacing.js +1 -1
  39. package/lib/rules/keyword-spacing.js +14 -14
  40. package/lib/rules/line-comment-position.js +5 -4
  41. package/lib/rules/lines-around-comment.js +14 -14
  42. package/lib/rules/lines-between-class-members.js +2 -1
  43. package/lib/rules/max-depth.js +5 -5
  44. package/lib/rules/max-len.js +21 -14
  45. package/lib/rules/max-lines-per-function.js +13 -17
  46. package/lib/rules/max-lines.js +3 -5
  47. package/lib/rules/max-nested-callbacks.js +6 -7
  48. package/lib/rules/max-params.js +5 -5
  49. package/lib/rules/max-statements-per-line.js +3 -2
  50. package/lib/rules/max-statements.js +6 -7
  51. package/lib/rules/multiline-comment-style.js +9 -9
  52. package/lib/rules/new-cap.js +9 -6
  53. package/lib/rules/newline-per-chained-call.js +2 -1
  54. package/lib/rules/no-alert.js +1 -1
  55. package/lib/rules/no-bitwise.js +2 -1
  56. package/lib/rules/no-caller.js +1 -1
  57. package/lib/rules/no-confusing-arrow.js +1 -1
  58. package/lib/rules/no-constant-condition.js +2 -1
  59. package/lib/rules/no-dupe-keys.js +2 -2
  60. package/lib/rules/no-duplicate-imports.js +2 -1
  61. package/lib/rules/no-else-return.js +4 -3
  62. package/lib/rules/no-empty-character-class.js +1 -1
  63. package/lib/rules/no-empty.js +2 -1
  64. package/lib/rules/no-eval.js +1 -1
  65. package/lib/rules/no-extra-parens.js +7 -1
  66. package/lib/rules/no-fallthrough.js +4 -3
  67. package/lib/rules/no-implicit-coercion.js +10 -7
  68. package/lib/rules/no-implied-eval.js +1 -1
  69. package/lib/rules/no-invalid-regexp.js +2 -2
  70. package/lib/rules/no-irregular-whitespace.js +11 -7
  71. package/lib/rules/no-labels.js +6 -4
  72. package/lib/rules/no-lonely-if.js +1 -1
  73. package/lib/rules/no-magic-numbers.js +6 -3
  74. package/lib/rules/no-mixed-operators.js +6 -5
  75. package/lib/rules/no-mixed-requires.js +1 -1
  76. package/lib/rules/no-mixed-spaces-and-tabs.js +2 -2
  77. package/lib/rules/no-multi-spaces.js +2 -1
  78. package/lib/rules/no-octal-escape.js +1 -1
  79. package/lib/rules/no-octal.js +1 -1
  80. package/lib/rules/no-param-reassign.js +2 -2
  81. package/lib/rules/no-path-concat.js +1 -1
  82. package/lib/rules/no-plusplus.js +2 -1
  83. package/lib/rules/no-redeclare.js +2 -2
  84. package/lib/rules/no-regex-spaces.js +1 -1
  85. package/lib/rules/no-return-assign.js +1 -1
  86. package/lib/rules/no-self-assign.js +3 -2
  87. package/lib/rules/no-shadow-restricted-names.js +16 -2
  88. package/lib/rules/no-shadow.js +3 -3
  89. package/lib/rules/no-sync.js +2 -1
  90. package/lib/rules/no-tabs.js +4 -3
  91. package/lib/rules/no-template-curly-in-string.js +1 -1
  92. package/lib/rules/no-trailing-spaces.js +7 -5
  93. package/lib/rules/no-undef.js +2 -1
  94. package/lib/rules/no-underscore-dangle.js +6 -3
  95. package/lib/rules/no-unexpected-multiline.js +1 -1
  96. package/lib/rules/no-unmodified-loop-condition.js +5 -5
  97. package/lib/rules/no-unneeded-ternary.js +2 -1
  98. package/lib/rules/no-unsafe-finally.js +3 -3
  99. package/lib/rules/no-unused-expressions.js +8 -5
  100. package/lib/rules/no-unused-vars.js +6 -6
  101. package/lib/rules/no-use-before-define.js +2 -2
  102. package/lib/rules/no-useless-escape.js +1 -1
  103. package/lib/rules/no-useless-rename.js +3 -3
  104. package/lib/rules/no-var.js +1 -1
  105. package/lib/rules/no-warning-comments.js +6 -6
  106. package/lib/rules/object-property-newline.js +5 -3
  107. package/lib/rules/one-var.js +18 -35
  108. package/lib/rules/padded-blocks.js +32 -9
  109. package/lib/rules/padding-line-between-statements.js +4 -3
  110. package/lib/rules/prefer-arrow-callback.js +4 -2
  111. package/lib/rules/prefer-const.js +5 -5
  112. package/lib/rules/prefer-destructuring.js +56 -5
  113. package/lib/rules/prefer-named-capture-group.js +123 -0
  114. package/lib/rules/prefer-object-spread.js +1 -1
  115. package/lib/rules/prefer-promise-reject-errors.js +1 -1
  116. package/lib/rules/prefer-spread.js +2 -13
  117. package/lib/rules/prefer-template.js +3 -3
  118. package/lib/rules/quotes.js +2 -2
  119. package/lib/rules/require-jsdoc.js +13 -7
  120. package/lib/rules/semi-spacing.js +6 -8
  121. package/lib/rules/semi.js +4 -4
  122. package/lib/rules/sort-imports.js +6 -3
  123. package/lib/rules/sort-keys.js +13 -5
  124. package/lib/rules/sort-vars.js +2 -1
  125. package/lib/rules/space-infix-ops.js +2 -1
  126. package/lib/rules/space-unary-ops.js +5 -3
  127. package/lib/rules/spaced-comment.js +6 -5
  128. package/lib/rules/switch-colon-spacing.js +2 -2
  129. package/lib/rules/template-curly-spacing.js +2 -2
  130. package/lib/rules/use-isnan.js +1 -1
  131. package/lib/rules/valid-jsdoc.js +12 -7
  132. package/lib/rules/valid-typeof.js +2 -1
  133. package/lib/rules/vars-on-top.js +1 -1
  134. package/lib/rules/wrap-iife.js +3 -2
  135. package/lib/rules/yoda.js +6 -4
  136. package/lib/util/ajv.js +1 -0
  137. package/lib/util/ast-utils.js +12 -12
  138. package/lib/util/config-comment-parser.js +4 -4
  139. package/lib/util/glob-utils.js +3 -3
  140. package/lib/util/ignored-paths.js +4 -4
  141. package/lib/util/interpolate.js +1 -1
  142. package/lib/util/naming.js +6 -6
  143. package/lib/util/node-event-generator.js +1 -1
  144. package/lib/util/path-utils.js +2 -2
  145. package/lib/util/patterns/letters.js +1 -1
  146. package/lib/util/source-code.js +2 -2
  147. package/lib/util/xml-escape.js +1 -1
  148. package/package.json +25 -23
@@ -14,7 +14,8 @@ const OPTIONS_SCHEMA = {
14
14
  properties: {
15
15
  code: {
16
16
  type: "integer",
17
- minimum: 0
17
+ minimum: 0,
18
+ default: 80
18
19
  },
19
20
  comments: {
20
21
  type: "integer",
@@ -22,28 +23,35 @@ const OPTIONS_SCHEMA = {
22
23
  },
23
24
  tabWidth: {
24
25
  type: "integer",
25
- minimum: 0
26
+ minimum: 0,
27
+ default: 4
26
28
  },
27
29
  ignorePattern: {
28
30
  type: "string"
29
31
  },
30
32
  ignoreComments: {
31
- type: "boolean"
33
+ type: "boolean",
34
+ default: false
32
35
  },
33
36
  ignoreStrings: {
34
- type: "boolean"
37
+ type: "boolean",
38
+ default: false
35
39
  },
36
40
  ignoreUrls: {
37
- type: "boolean"
41
+ type: "boolean",
42
+ default: false
38
43
  },
39
44
  ignoreTemplateLiterals: {
40
- type: "boolean"
45
+ type: "boolean",
46
+ default: false
41
47
  },
42
48
  ignoreRegExpLiterals: {
43
- type: "boolean"
49
+ type: "boolean",
50
+ default: false
44
51
  },
45
52
  ignoreTrailingComments: {
46
- type: "boolean"
53
+ type: "boolean",
54
+ default: false
47
55
  }
48
56
  },
49
57
  additionalProperties: false
@@ -95,7 +103,7 @@ module.exports = {
95
103
  * too many false positives
96
104
  * - We don't care about matching the entire URL, any small segment is fine
97
105
  */
98
- const URL_REGEXP = /[^:/?#]:\/\/[^?#]/;
106
+ const URL_REGEXP = /[^:/?#]:\/\/[^?#]/u;
99
107
 
100
108
  const sourceCode = context.getSourceCode();
101
109
 
@@ -110,7 +118,7 @@ module.exports = {
110
118
  function computeLineLength(line, tabWidth) {
111
119
  let extraCharacterCount = 0;
112
120
 
113
- line.replace(/\t/g, (match, offset) => {
121
+ line.replace(/\t/gu, (match, offset) => {
114
122
  const totalOffset = offset + extraCharacterCount,
115
123
  previousTabStopOffset = tabWidth ? totalOffset % tabWidth : 0,
116
124
  spaceCount = tabWidth - previousTabStopOffset;
@@ -121,8 +129,7 @@ module.exports = {
121
129
  }
122
130
 
123
131
  // The options object must be the last option specified…
124
- const lastOption = context.options[context.options.length - 1];
125
- const options = typeof lastOption === "object" ? Object.create(lastOption) : {};
132
+ const options = Object.assign({}, context.options[context.options.length - 1]);
126
133
 
127
134
  // …but max code length…
128
135
  if (typeof context.options[0] === "number") {
@@ -146,7 +153,7 @@ module.exports = {
146
153
  let ignorePattern = options.ignorePattern || null;
147
154
 
148
155
  if (ignorePattern) {
149
- ignorePattern = new RegExp(ignorePattern);
156
+ ignorePattern = new RegExp(ignorePattern); // eslint-disable-line require-unicode-regexp
150
157
  }
151
158
 
152
159
  //--------------------------------------------------------------------------
@@ -194,7 +201,7 @@ module.exports = {
194
201
  function stripTrailingComment(line, comment) {
195
202
 
196
203
  // loc.column is zero-indexed
197
- return line.slice(0, comment.loc.start.column).replace(/\s+$/, "");
204
+ return line.slice(0, comment.loc.start.column).replace(/\s+$/u, "");
198
205
  }
199
206
 
200
207
  /**
@@ -19,16 +19,20 @@ const OPTIONS_SCHEMA = {
19
19
  properties: {
20
20
  max: {
21
21
  type: "integer",
22
- minimum: 0
22
+ minimum: 0,
23
+ default: 50
23
24
  },
24
25
  skipComments: {
25
- type: "boolean"
26
+ type: "boolean",
27
+ default: false
26
28
  },
27
29
  skipBlankLines: {
28
- type: "boolean"
30
+ type: "boolean",
31
+ default: false
29
32
  },
30
33
  IIFEs: {
31
- type: "boolean"
34
+ type: "boolean",
35
+ default: false
32
36
  }
33
37
  },
34
38
  additionalProperties: false
@@ -97,18 +101,10 @@ module.exports = {
97
101
  let IIFEs = false;
98
102
 
99
103
  if (typeof option === "object") {
100
- if (typeof option.max === "number") {
101
- maxLines = option.max;
102
- }
103
- if (typeof option.skipComments === "boolean") {
104
- skipComments = option.skipComments;
105
- }
106
- if (typeof option.skipBlankLines === "boolean") {
107
- skipBlankLines = option.skipBlankLines;
108
- }
109
- if (typeof option.IIFEs === "boolean") {
110
- IIFEs = option.IIFEs;
111
- }
104
+ maxLines = option.max;
105
+ skipComments = option.skipComments;
106
+ skipBlankLines = option.skipBlankLines;
107
+ IIFEs = option.IIFEs;
112
108
  } else if (typeof option === "number") {
113
109
  maxLines = option;
114
110
  }
@@ -191,7 +187,7 @@ module.exports = {
191
187
  }
192
188
 
193
189
  if (skipBlankLines) {
194
- if (line.match(/^\s*$/)) {
190
+ if (line.match(/^\s*$/u)) {
195
191
  continue;
196
192
  }
197
193
  }
@@ -61,11 +61,9 @@ module.exports = {
61
61
  const option = context.options[0];
62
62
  let max = 300;
63
63
 
64
- if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "max") && typeof option.max === "number") {
64
+ if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "max")) {
65
65
  max = option.max;
66
- }
67
-
68
- if (typeof option === "number") {
66
+ } else if (typeof option === "number") {
69
67
  max = option;
70
68
  }
71
69
 
@@ -86,7 +84,7 @@ module.exports = {
86
84
  /**
87
85
  * Returns the line numbers of a comment that don't have any code on the same line
88
86
  * @param {Node} comment The comment node to check
89
- * @returns {int[]} The line numbers
87
+ * @returns {number[]} The line numbers
90
88
  */
91
89
  function getLinesWithoutCode(comment) {
92
90
  let start = comment.loc.start.line;
@@ -57,13 +57,12 @@ module.exports = {
57
57
  const option = context.options[0];
58
58
  let THRESHOLD = 10;
59
59
 
60
- if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "maximum") && typeof option.maximum === "number") {
61
- THRESHOLD = option.maximum;
62
- }
63
- if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "max") && typeof option.max === "number") {
64
- THRESHOLD = option.max;
65
- }
66
- if (typeof option === "number") {
60
+ if (
61
+ typeof option === "object" &&
62
+ (Object.prototype.hasOwnProperty.call(option, "maximum") || Object.prototype.hasOwnProperty.call(option, "max"))
63
+ ) {
64
+ THRESHOLD = option.maximum || option.max;
65
+ } else if (typeof option === "number") {
67
66
  THRESHOLD = option;
68
67
  }
69
68
 
@@ -62,11 +62,11 @@ module.exports = {
62
62
  const option = context.options[0];
63
63
  let numParams = 3;
64
64
 
65
- if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "maximum") && typeof option.maximum === "number") {
66
- numParams = option.maximum;
67
- }
68
- if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "max") && typeof option.max === "number") {
69
- numParams = option.max;
65
+ if (
66
+ typeof option === "object" &&
67
+ (Object.prototype.hasOwnProperty.call(option, "maximum") || Object.prototype.hasOwnProperty.call(option, "max"))
68
+ ) {
69
+ numParams = option.maximum || option.max;
70
70
  }
71
71
  if (typeof option === "number") {
72
72
  numParams = option;
@@ -31,7 +31,8 @@ module.exports = {
31
31
  properties: {
32
32
  max: {
33
33
  type: "integer",
34
- minimum: 1
34
+ minimum: 1,
35
+ default: 1
35
36
  }
36
37
  },
37
38
  additionalProperties: false
@@ -56,7 +57,7 @@ module.exports = {
56
57
  // Helpers
57
58
  //--------------------------------------------------------------------------
58
59
 
59
- const SINGLE_CHILD_ALLOWED = /^(?:(?:DoWhile|For|ForIn|ForOf|If|Labeled|While)Statement|Export(?:Default|Named)Declaration)$/;
60
+ const SINGLE_CHILD_ALLOWED = /^(?:(?:DoWhile|For|ForIn|ForOf|If|Labeled|While)Statement|Export(?:Default|Named)Declaration)$/u;
60
61
 
61
62
  /**
62
63
  * Reports with the first extra statement, and clears it.
@@ -78,13 +78,12 @@ module.exports = {
78
78
  topLevelFunctions = [];
79
79
  let maxStatements = 10;
80
80
 
81
- if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "maximum") && typeof option.maximum === "number") {
82
- maxStatements = option.maximum;
83
- }
84
- if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "max") && typeof option.max === "number") {
85
- maxStatements = option.max;
86
- }
87
- if (typeof option === "number") {
81
+ if (
82
+ typeof option === "object" &&
83
+ (Object.prototype.hasOwnProperty.call(option, "maximum") || Object.prototype.hasOwnProperty.call(option, "max"))
84
+ ) {
85
+ maxStatements = option.maximum || option.max;
86
+ } else if (typeof option === "number") {
88
87
  maxStatements = option;
89
88
  }
90
89
 
@@ -52,7 +52,7 @@ module.exports = {
52
52
  }
53
53
  return commentGroup[0].value
54
54
  .split(astUtils.LINEBREAK_MATCHER)
55
- .map(line => line.replace(/^\s*\*?/, ""));
55
+ .map(line => line.replace(/^\s*\*?/u, ""));
56
56
  }
57
57
 
58
58
  /**
@@ -103,9 +103,9 @@ module.exports = {
103
103
  const lines = commentGroup[0].value.split(astUtils.LINEBREAK_MATCHER);
104
104
 
105
105
  return commentGroup[0].type === "Block" &&
106
- /^\*\s*$/.test(lines[0]) &&
107
- lines.slice(1, -1).every(line => /^\s* /.test(line)) &&
108
- /^\s*$/.test(lines[lines.length - 1]);
106
+ /^\*\s*$/u.test(lines[0]) &&
107
+ lines.slice(1, -1).every(line => /^\s* /u.test(line)) &&
108
+ /^\s*$/u.test(lines[lines.length - 1]);
109
109
  }
110
110
 
111
111
  /**
@@ -143,7 +143,7 @@ module.exports = {
143
143
  const lines = block.value.split(astUtils.LINEBREAK_MATCHER);
144
144
  const expectedLinePrefix = `${sourceCode.text.slice(block.range[0] - block.loc.start.column, block.range[0])} *`;
145
145
 
146
- if (!/^\*?\s*$/.test(lines[0])) {
146
+ if (!/^\*?\s*$/u.test(lines[0])) {
147
147
  const start = block.value.startsWith("*") ? block.range[0] + 1 : block.range[0];
148
148
 
149
149
  context.report({
@@ -156,7 +156,7 @@ module.exports = {
156
156
  });
157
157
  }
158
158
 
159
- if (!/^\s*$/.test(lines[lines.length - 1])) {
159
+ if (!/^\s*$/u.test(lines[lines.length - 1])) {
160
160
  context.report({
161
161
  loc: {
162
162
  start: { line: block.loc.end.line, column: block.loc.end.column - 2 },
@@ -176,12 +176,12 @@ module.exports = {
176
176
  start: { line: lineNumber, column: 0 },
177
177
  end: { line: lineNumber, column: sourceCode.lines[lineNumber - 1].length }
178
178
  },
179
- messageId: /^\s*\*/.test(lineText)
179
+ messageId: /^\s*\*/u.test(lineText)
180
180
  ? "alignment"
181
181
  : "missingStar",
182
182
  fix(fixer) {
183
183
  const lineStartIndex = sourceCode.getIndexFromLoc({ line: lineNumber, column: 0 });
184
- const linePrefixLength = lineText.match(/^\s*\*? ?/)[0].length;
184
+ const linePrefixLength = lineText.match(/^\s*\*? ?/u)[0].length;
185
185
  const commentStartIndex = lineStartIndex + linePrefixLength;
186
186
 
187
187
  const replacementText = lineNumber === block.loc.end.line || lineText.length === linePrefixLength
@@ -244,7 +244,7 @@ module.exports = {
244
244
  const block = commentGroup[0];
245
245
  const lines = block.value.split(astUtils.LINEBREAK_MATCHER).filter(line => line.trim());
246
246
 
247
- if (lines.length > 0 && lines.every(line => /^\s*\*/.test(line))) {
247
+ if (lines.length > 0 && lines.every(line => /^\s*\*/u.test(line))) {
248
248
  context.report({
249
249
  loc: {
250
250
  start: block.loc.start,
@@ -88,10 +88,12 @@ module.exports = {
88
88
  type: "object",
89
89
  properties: {
90
90
  newIsCap: {
91
- type: "boolean"
91
+ type: "boolean",
92
+ default: true
92
93
  },
93
94
  capIsNew: {
94
- type: "boolean"
95
+ type: "boolean",
96
+ default: true
95
97
  },
96
98
  newIsCapExceptions: {
97
99
  type: "array",
@@ -112,7 +114,8 @@ module.exports = {
112
114
  type: "string"
113
115
  },
114
116
  properties: {
115
- type: "boolean"
117
+ type: "boolean",
118
+ default: true
116
119
  }
117
120
  },
118
121
  additionalProperties: false
@@ -126,17 +129,17 @@ module.exports = {
126
129
 
127
130
  create(context) {
128
131
 
129
- const config = context.options[0] ? Object.assign({}, context.options[0]) : {};
132
+ const config = Object.assign({}, context.options[0]);
130
133
 
131
134
  config.newIsCap = config.newIsCap !== false;
132
135
  config.capIsNew = config.capIsNew !== false;
133
136
  const skipProperties = config.properties === false;
134
137
 
135
138
  const newIsCapExceptions = checkArray(config, "newIsCapExceptions", []).reduce(invert, {});
136
- const newIsCapExceptionPattern = config.newIsCapExceptionPattern ? new RegExp(config.newIsCapExceptionPattern) : null;
139
+ const newIsCapExceptionPattern = config.newIsCapExceptionPattern ? new RegExp(config.newIsCapExceptionPattern) : null; // eslint-disable-line require-unicode-regexp
137
140
 
138
141
  const capIsNewExceptions = calculateCapIsNewExceptions(config);
139
- const capIsNewExceptionPattern = config.capIsNewExceptionPattern ? new RegExp(config.capIsNewExceptionPattern) : null;
142
+ const capIsNewExceptionPattern = config.capIsNewExceptionPattern ? new RegExp(config.capIsNewExceptionPattern) : null; // eslint-disable-line require-unicode-regexp
140
143
 
141
144
  const listeners = {};
142
145
 
@@ -31,7 +31,8 @@ module.exports = {
31
31
  ignoreChainWithDepth: {
32
32
  type: "integer",
33
33
  minimum: 1,
34
- maximum: 10
34
+ maximum: 10,
35
+ default: 2
35
36
  }
36
37
  },
37
38
  additionalProperties: false
@@ -20,7 +20,7 @@ const getPropertyName = require("../util/ast-utils").getStaticPropertyName;
20
20
  * @returns {boolean} Whether or not the name is prohibited.
21
21
  */
22
22
  function isProhibitedIdentifier(name) {
23
- return /^(alert|confirm|prompt)$/.test(name);
23
+ return /^(alert|confirm|prompt)$/u.test(name);
24
24
  }
25
25
 
26
26
  /**
@@ -43,7 +43,8 @@ module.exports = {
43
43
  uniqueItems: true
44
44
  },
45
45
  int32Hint: {
46
- type: "boolean"
46
+ type: "boolean",
47
+ default: false
47
48
  }
48
49
  },
49
50
  additionalProperties: false
@@ -35,7 +35,7 @@ module.exports = {
35
35
  const objectName = node.object.name,
36
36
  propertyName = node.property.name;
37
37
 
38
- if (objectName === "arguments" && !node.computed && propertyName && propertyName.match(/^calle[er]$/)) {
38
+ if (objectName === "arguments" && !node.computed && propertyName && propertyName.match(/^calle[er]$/u)) {
39
39
  context.report({ node, messageId: "unexpected", data: { prop: propertyName } });
40
40
  }
41
41
 
@@ -41,7 +41,7 @@ module.exports = {
41
41
  schema: [{
42
42
  type: "object",
43
43
  properties: {
44
- allowParens: { type: "boolean" }
44
+ allowParens: { type: "boolean", default: false }
45
45
  },
46
46
  additionalProperties: false
47
47
  }],
@@ -32,7 +32,8 @@ module.exports = {
32
32
  type: "object",
33
33
  properties: {
34
34
  checkLoops: {
35
- type: "boolean"
35
+ type: "boolean",
36
+ default: true
36
37
  }
37
38
  },
38
39
  additionalProperties: false
@@ -15,8 +15,8 @@ const astUtils = require("../util/ast-utils");
15
15
  // Helpers
16
16
  //------------------------------------------------------------------------------
17
17
 
18
- const GET_KIND = /^(?:init|get)$/;
19
- const SET_KIND = /^(?:init|set)$/;
18
+ const GET_KIND = /^(?:init|get)$/u;
19
+ const SET_KIND = /^(?:init|set)$/u;
20
20
 
21
21
  /**
22
22
  * The class which stores properties' information of an object.
@@ -113,7 +113,8 @@ module.exports = {
113
113
  type: "object",
114
114
  properties: {
115
115
  includeExports: {
116
- type: "boolean"
116
+ type: "boolean",
117
+ default: false
117
118
  }
118
119
  },
119
120
  additionalProperties: false
@@ -31,7 +31,8 @@ module.exports = {
31
31
  type: "object",
32
32
  properties: {
33
33
  allowElseIf: {
34
- type: "boolean"
34
+ type: "boolean",
35
+ default: true
35
36
  }
36
37
  },
37
38
  additionalProperties: false
@@ -81,7 +82,7 @@ module.exports = {
81
82
  * after the if block
82
83
  */
83
84
  const ifBlockMaybeUnsafe = node.parent.consequent.type !== "BlockStatement" && lastIfToken.value !== ";";
84
- const elseBlockUnsafe = /^[([/+`-]/.test(firstTokenOfElseBlock.value);
85
+ const elseBlockUnsafe = /^[([/+`-]/u.test(firstTokenOfElseBlock.value);
85
86
 
86
87
  if (ifBlockMaybeUnsafe && elseBlockUnsafe) {
87
88
  return null;
@@ -93,7 +94,7 @@ module.exports = {
93
94
  if (lastTokenOfElseBlock.value !== ";") {
94
95
  const nextToken = sourceCode.getTokenAfter(endToken);
95
96
 
96
- const nextTokenUnsafe = nextToken && /^[([/+`-]/.test(nextToken.value);
97
+ const nextTokenUnsafe = nextToken && /^[([/+`-]/u.test(nextToken.value);
97
98
  const nextTokenOnSameLine = nextToken && nextToken.loc.start.line === lastTokenOfElseBlock.loc.start.line;
98
99
 
99
100
  /*
@@ -21,7 +21,7 @@
21
21
  * 4. `[gimuy]*`: optional regexp flags
22
22
  * 5. `$`: fix the match at the end of the string
23
23
  */
24
- const regex = /^\/([^\\[]|\\.|\[([^\\\]]|\\.)+])*\/[gimuys]*$/;
24
+ const regex = /^\/([^\\[]|\\.|\[([^\\\]]|\\.)+\])*\/[gimuys]*$/u;
25
25
 
26
26
  //------------------------------------------------------------------------------
27
27
  // Rule Definition
@@ -30,7 +30,8 @@ module.exports = {
30
30
  type: "object",
31
31
  properties: {
32
32
  allowEmptyCatch: {
33
- type: "boolean"
33
+ type: "boolean",
34
+ default: false
34
35
  }
35
36
  },
36
37
  additionalProperties: false
@@ -89,7 +89,7 @@ module.exports = {
89
89
  {
90
90
  type: "object",
91
91
  properties: {
92
- allowIndirect: { type: "boolean" }
92
+ allowIndirect: { type: "boolean", default: false }
93
93
  },
94
94
  additionalProperties: false
95
95
  }
@@ -471,6 +471,7 @@ module.exports = {
471
471
  const firstToken = isParenthesised(node) ? sourceCode.getTokenBefore(node) : sourceCode.getFirstToken(node);
472
472
  const secondToken = sourceCode.getTokenAfter(firstToken, astUtils.isNotOpeningParenToken);
473
473
  const thirdToken = secondToken ? sourceCode.getTokenAfter(secondToken) : null;
474
+ const tokenAfterClosingParens = secondToken ? sourceCode.getTokenAfter(secondToken, astUtils.isNotClosingParenToken) : null;
474
475
 
475
476
  if (
476
477
  astUtils.isOpeningParenToken(firstToken) &&
@@ -479,7 +480,12 @@ module.exports = {
479
480
  secondToken.type === "Keyword" && (
480
481
  secondToken.value === "function" ||
481
482
  secondToken.value === "class" ||
482
- secondToken.value === "let" && astUtils.isOpeningBracketToken(sourceCode.getTokenAfter(secondToken, astUtils.isNotClosingParenToken))
483
+ secondToken.value === "let" &&
484
+ tokenAfterClosingParens &&
485
+ (
486
+ astUtils.isOpeningBracketToken(tokenAfterClosingParens) ||
487
+ tokenAfterClosingParens.type === "Identifier"
488
+ )
483
489
  ) ||
484
490
  secondToken && secondToken.type === "Identifier" && secondToken.value === "async" && thirdToken && thirdToken.type === "Keyword" && thirdToken.value === "function"
485
491
  )
@@ -14,7 +14,7 @@ const lodash = require("lodash");
14
14
  // Helpers
15
15
  //------------------------------------------------------------------------------
16
16
 
17
- const DEFAULT_FALLTHROUGH_COMMENT = /falls?\s?through/i;
17
+ const DEFAULT_FALLTHROUGH_COMMENT = /falls?\s?through/iu;
18
18
 
19
19
  /**
20
20
  * Checks whether or not a given node has a fallthrough comment.
@@ -69,7 +69,8 @@ module.exports = {
69
69
  type: "object",
70
70
  properties: {
71
71
  commentPattern: {
72
- type: "string"
72
+ type: "string",
73
+ default: ""
73
74
  }
74
75
  },
75
76
  additionalProperties: false
@@ -94,7 +95,7 @@ module.exports = {
94
95
  let fallthroughCommentPattern = null;
95
96
 
96
97
  if (options.commentPattern) {
97
- fallthroughCommentPattern = new RegExp(options.commentPattern);
98
+ fallthroughCommentPattern = new RegExp(options.commentPattern); // eslint-disable-line require-unicode-regexp
98
99
  } else {
99
100
  fallthroughCommentPattern = DEFAULT_FALLTHROUGH_COMMENT;
100
101
  }
@@ -11,7 +11,7 @@ const astUtils = require("../util/ast-utils");
11
11
  // Helpers
12
12
  //------------------------------------------------------------------------------
13
13
 
14
- const INDEX_OF_PATTERN = /^(?:i|lastI)ndexOf$/;
14
+ const INDEX_OF_PATTERN = /^(?:i|lastI)ndexOf$/u;
15
15
  const ALLOWABLE_OPERATORS = ["~", "!!", "+", "*"];
16
16
 
17
17
  /**
@@ -21,9 +21,9 @@ const ALLOWABLE_OPERATORS = ["~", "!!", "+", "*"];
21
21
  */
22
22
  function parseOptions(options) {
23
23
  return {
24
- boolean: "boolean" in options ? Boolean(options.boolean) : true,
25
- number: "number" in options ? Boolean(options.number) : true,
26
- string: "string" in options ? Boolean(options.string) : true,
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
27
  allow: options.allow || []
28
28
  };
29
29
  }
@@ -167,13 +167,16 @@ module.exports = {
167
167
  type: "object",
168
168
  properties: {
169
169
  boolean: {
170
- type: "boolean"
170
+ type: "boolean",
171
+ default: true
171
172
  },
172
173
  number: {
173
- type: "boolean"
174
+ type: "boolean",
175
+ default: true
174
176
  },
175
177
  string: {
176
- type: "boolean"
178
+ type: "boolean",
179
+ default: true
177
180
  },
178
181
  allow: {
179
182
  type: "array",
@@ -24,7 +24,7 @@ module.exports = {
24
24
  },
25
25
 
26
26
  create(context) {
27
- const CALLEE_RE = /^(setTimeout|setInterval|execScript)$/;
27
+ const CALLEE_RE = /^(setTimeout|setInterval|execScript)$/u;
28
28
 
29
29
  /*
30
30
  * Figures out if we should inspect a given binary expression. Is a stack
@@ -10,7 +10,7 @@
10
10
 
11
11
  const RegExpValidator = require("regexpp").RegExpValidator;
12
12
  const validator = new RegExpValidator({ ecmaVersion: 2018 });
13
- const validFlags = /[gimuys]/g;
13
+ const validFlags = /[gimuys]/gu;
14
14
  const undefined1 = void 0;
15
15
 
16
16
  //------------------------------------------------------------------------------
@@ -51,7 +51,7 @@ module.exports = {
51
51
  const temp = options.allowConstructorFlags.join("").replace(validFlags, "");
52
52
 
53
53
  if (temp) {
54
- allowedFlags = new RegExp(`[${temp}]`, "gi");
54
+ allowedFlags = new RegExp(`[${temp}]`, "giu");
55
55
  }
56
56
  }
57
57