eslint 5.6.0 → 5.9.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 (273) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/bin/eslint.js +0 -1
  3. package/lib/cli-engine.js +128 -31
  4. package/lib/cli.js +6 -1
  5. package/lib/linter.js +9 -0
  6. package/lib/options.js +5 -0
  7. package/lib/rules/accessor-pairs.js +4 -0
  8. package/lib/rules/array-bracket-newline.js +5 -0
  9. package/lib/rules/array-bracket-spacing.js +5 -0
  10. package/lib/rules/array-callback-return.js +2 -0
  11. package/lib/rules/array-element-newline.js +4 -0
  12. package/lib/rules/arrow-body-style.js +2 -0
  13. package/lib/rules/arrow-parens.js +2 -0
  14. package/lib/rules/arrow-spacing.js +2 -0
  15. package/lib/rules/block-scoped-var.js +2 -0
  16. package/lib/rules/block-spacing.js +2 -0
  17. package/lib/rules/brace-style.js +2 -0
  18. package/lib/rules/callback-return.js +2 -0
  19. package/lib/rules/camelcase.js +38 -8
  20. package/lib/rules/capitalized-comments.js +4 -0
  21. package/lib/rules/class-methods-use-this.js +3 -0
  22. package/lib/rules/comma-dangle.js +4 -0
  23. package/lib/rules/comma-spacing.js +2 -0
  24. package/lib/rules/comma-style.js +5 -0
  25. package/lib/rules/complexity.js +2 -0
  26. package/lib/rules/computed-property-spacing.js +2 -0
  27. package/lib/rules/consistent-return.js +2 -0
  28. package/lib/rules/consistent-this.js +2 -0
  29. package/lib/rules/constructor-super.js +2 -0
  30. package/lib/rules/curly.js +2 -0
  31. package/lib/rules/default-case.js +2 -0
  32. package/lib/rules/dot-location.js +2 -0
  33. package/lib/rules/dot-notation.js +2 -0
  34. package/lib/rules/eol-last.js +5 -0
  35. package/lib/rules/eqeqeq.js +2 -0
  36. package/lib/rules/for-direction.js +4 -0
  37. package/lib/rules/func-call-spacing.js +4 -0
  38. package/lib/rules/func-name-matching.js +3 -0
  39. package/lib/rules/func-names.js +3 -0
  40. package/lib/rules/func-style.js +3 -0
  41. package/lib/rules/function-paren-newline.js +5 -0
  42. package/lib/rules/generator-star-spacing.js +3 -0
  43. package/lib/rules/getter-return.js +5 -0
  44. package/lib/rules/global-require.js +2 -0
  45. package/lib/rules/guard-for-in.js +2 -0
  46. package/lib/rules/handle-callback-err.js +2 -0
  47. package/lib/rules/id-blacklist.js +2 -0
  48. package/lib/rules/id-length.js +2 -0
  49. package/lib/rules/id-match.js +101 -27
  50. package/lib/rules/implicit-arrow-linebreak.js +4 -0
  51. package/lib/rules/indent-legacy.js +4 -1
  52. package/lib/rules/indent.js +2 -0
  53. package/lib/rules/init-declarations.js +2 -0
  54. package/lib/rules/jsx-quotes.js +2 -0
  55. package/lib/rules/key-spacing.js +4 -3
  56. package/lib/rules/keyword-spacing.js +2 -0
  57. package/lib/rules/line-comment-position.js +2 -0
  58. package/lib/rules/linebreak-style.js +2 -0
  59. package/lib/rules/lines-around-comment.js +2 -0
  60. package/lib/rules/lines-around-directive.js +6 -2
  61. package/lib/rules/lines-between-class-members.js +2 -0
  62. package/lib/rules/max-classes-per-file.js +4 -0
  63. package/lib/rules/max-depth.js +2 -0
  64. package/lib/rules/max-len.js +2 -0
  65. package/lib/rules/max-lines-per-function.js +2 -0
  66. package/lib/rules/max-lines.js +2 -0
  67. package/lib/rules/max-nested-callbacks.js +2 -0
  68. package/lib/rules/max-params.js +2 -0
  69. package/lib/rules/max-statements-per-line.js +2 -0
  70. package/lib/rules/max-statements.js +2 -0
  71. package/lib/rules/multiline-comment-style.js +3 -0
  72. package/lib/rules/multiline-ternary.js +3 -0
  73. package/lib/rules/new-cap.js +2 -0
  74. package/lib/rules/new-parens.js +2 -1
  75. package/lib/rules/newline-after-var.js +5 -2
  76. package/lib/rules/newline-before-return.js +5 -2
  77. package/lib/rules/newline-per-chained-call.js +4 -0
  78. package/lib/rules/no-alert.js +2 -0
  79. package/lib/rules/no-array-constructor.js +2 -0
  80. package/lib/rules/no-async-promise-executor.js +3 -0
  81. package/lib/rules/no-await-in-loop.js +4 -0
  82. package/lib/rules/no-bitwise.js +2 -0
  83. package/lib/rules/no-buffer-constructor.js +4 -0
  84. package/lib/rules/no-caller.js +2 -0
  85. package/lib/rules/no-case-declarations.js +2 -0
  86. package/lib/rules/no-catch-shadow.js +6 -3
  87. package/lib/rules/no-class-assign.js +2 -0
  88. package/lib/rules/no-compare-neg-zero.js +4 -0
  89. package/lib/rules/no-cond-assign.js +2 -0
  90. package/lib/rules/no-confusing-arrow.js +2 -0
  91. package/lib/rules/no-console.js +2 -0
  92. package/lib/rules/no-const-assign.js +2 -0
  93. package/lib/rules/no-constant-condition.js +2 -0
  94. package/lib/rules/no-continue.js +2 -0
  95. package/lib/rules/no-control-regex.js +4 -2
  96. package/lib/rules/no-debugger.js +4 -0
  97. package/lib/rules/no-delete-var.js +2 -0
  98. package/lib/rules/no-div-regex.js +2 -0
  99. package/lib/rules/no-dupe-args.js +2 -0
  100. package/lib/rules/no-dupe-class-members.js +2 -0
  101. package/lib/rules/no-dupe-keys.js +2 -0
  102. package/lib/rules/no-duplicate-case.js +2 -0
  103. package/lib/rules/no-duplicate-imports.js +2 -0
  104. package/lib/rules/no-else-return.js +2 -0
  105. package/lib/rules/no-empty-character-class.js +2 -0
  106. package/lib/rules/no-empty-function.js +2 -0
  107. package/lib/rules/no-empty-pattern.js +2 -0
  108. package/lib/rules/no-empty.js +2 -0
  109. package/lib/rules/no-eq-null.js +2 -0
  110. package/lib/rules/no-eval.js +2 -0
  111. package/lib/rules/no-ex-assign.js +2 -0
  112. package/lib/rules/no-extend-native.js +2 -0
  113. package/lib/rules/no-extra-bind.js +24 -1
  114. package/lib/rules/no-extra-boolean-cast.js +2 -1
  115. package/lib/rules/no-extra-label.js +2 -1
  116. package/lib/rules/no-extra-parens.js +5 -6
  117. package/lib/rules/no-extra-semi.js +2 -0
  118. package/lib/rules/no-fallthrough.js +2 -0
  119. package/lib/rules/no-floating-decimal.js +2 -1
  120. package/lib/rules/no-func-assign.js +2 -0
  121. package/lib/rules/no-global-assign.js +2 -0
  122. package/lib/rules/no-implicit-coercion.js +3 -0
  123. package/lib/rules/no-implicit-globals.js +2 -0
  124. package/lib/rules/no-implied-eval.js +2 -0
  125. package/lib/rules/no-inline-comments.js +2 -0
  126. package/lib/rules/no-inner-declarations.js +2 -0
  127. package/lib/rules/no-invalid-regexp.js +2 -0
  128. package/lib/rules/no-invalid-this.js +2 -0
  129. package/lib/rules/no-irregular-whitespace.js +6 -8
  130. package/lib/rules/no-iterator.js +2 -0
  131. package/lib/rules/no-label-var.js +2 -0
  132. package/lib/rules/no-labels.js +2 -0
  133. package/lib/rules/no-lone-blocks.js +2 -0
  134. package/lib/rules/no-lonely-if.js +2 -1
  135. package/lib/rules/no-loop-func.js +2 -0
  136. package/lib/rules/no-magic-numbers.js +3 -0
  137. package/lib/rules/no-misleading-character-class.js +4 -0
  138. package/lib/rules/no-mixed-operators.js +3 -0
  139. package/lib/rules/no-mixed-requires.js +2 -0
  140. package/lib/rules/no-mixed-spaces-and-tabs.js +2 -0
  141. package/lib/rules/no-multi-assign.js +3 -0
  142. package/lib/rules/no-multi-spaces.js +2 -0
  143. package/lib/rules/no-multi-str.js +2 -0
  144. package/lib/rules/no-multiple-empty-lines.js +2 -0
  145. package/lib/rules/no-native-reassign.js +4 -1
  146. package/lib/rules/no-negated-condition.js +2 -0
  147. package/lib/rules/no-negated-in-lhs.js +5 -2
  148. package/lib/rules/no-nested-ternary.js +2 -0
  149. package/lib/rules/no-new-func.js +2 -0
  150. package/lib/rules/no-new-object.js +2 -0
  151. package/lib/rules/no-new-require.js +2 -0
  152. package/lib/rules/no-new-symbol.js +2 -0
  153. package/lib/rules/no-new-wrappers.js +2 -0
  154. package/lib/rules/no-new.js +2 -0
  155. package/lib/rules/no-obj-calls.js +2 -0
  156. package/lib/rules/no-octal-escape.js +2 -0
  157. package/lib/rules/no-octal.js +2 -0
  158. package/lib/rules/no-param-reassign.js +2 -0
  159. package/lib/rules/no-path-concat.js +2 -0
  160. package/lib/rules/no-plusplus.js +2 -0
  161. package/lib/rules/no-process-env.js +2 -0
  162. package/lib/rules/no-process-exit.js +2 -0
  163. package/lib/rules/no-proto.js +2 -0
  164. package/lib/rules/no-prototype-builtins.js +2 -0
  165. package/lib/rules/no-redeclare.js +2 -0
  166. package/lib/rules/no-regex-spaces.js +2 -1
  167. package/lib/rules/no-restricted-globals.js +2 -0
  168. package/lib/rules/no-restricted-imports.js +40 -22
  169. package/lib/rules/no-restricted-modules.js +2 -0
  170. package/lib/rules/no-restricted-properties.js +2 -0
  171. package/lib/rules/no-restricted-syntax.js +2 -0
  172. package/lib/rules/no-return-assign.js +2 -0
  173. package/lib/rules/no-return-await.js +4 -0
  174. package/lib/rules/no-script-url.js +2 -0
  175. package/lib/rules/no-self-assign.js +2 -0
  176. package/lib/rules/no-self-compare.js +2 -0
  177. package/lib/rules/no-sequences.js +2 -0
  178. package/lib/rules/no-shadow-restricted-names.js +2 -0
  179. package/lib/rules/no-shadow.js +2 -0
  180. package/lib/rules/no-spaced-func.js +4 -1
  181. package/lib/rules/no-sparse-arrays.js +2 -0
  182. package/lib/rules/no-sync.js +2 -0
  183. package/lib/rules/no-tabs.js +25 -6
  184. package/lib/rules/no-template-curly-in-string.js +2 -0
  185. package/lib/rules/no-ternary.js +2 -0
  186. package/lib/rules/no-this-before-super.js +2 -0
  187. package/lib/rules/no-throw-literal.js +2 -0
  188. package/lib/rules/no-trailing-spaces.js +2 -0
  189. package/lib/rules/no-undef-init.js +2 -1
  190. package/lib/rules/no-undef.js +2 -0
  191. package/lib/rules/no-undefined.js +2 -0
  192. package/lib/rules/no-underscore-dangle.js +2 -0
  193. package/lib/rules/no-unexpected-multiline.js +2 -0
  194. package/lib/rules/no-unmodified-loop-condition.js +2 -0
  195. package/lib/rules/no-unneeded-ternary.js +2 -0
  196. package/lib/rules/no-unreachable.js +2 -1
  197. package/lib/rules/no-unsafe-finally.js +2 -0
  198. package/lib/rules/no-unsafe-negation.js +3 -0
  199. package/lib/rules/no-unused-expressions.js +2 -0
  200. package/lib/rules/no-unused-labels.js +2 -1
  201. package/lib/rules/no-unused-vars.js +37 -13
  202. package/lib/rules/no-use-before-define.js +2 -0
  203. package/lib/rules/no-useless-call.js +2 -0
  204. package/lib/rules/no-useless-computed-key.js +2 -1
  205. package/lib/rules/no-useless-concat.js +2 -0
  206. package/lib/rules/no-useless-constructor.js +2 -0
  207. package/lib/rules/no-useless-escape.js +2 -0
  208. package/lib/rules/no-useless-rename.js +4 -0
  209. package/lib/rules/no-useless-return.js +3 -0
  210. package/lib/rules/no-var.js +2 -0
  211. package/lib/rules/no-void.js +2 -0
  212. package/lib/rules/no-warning-comments.js +2 -0
  213. package/lib/rules/no-whitespace-before-property.js +2 -0
  214. package/lib/rules/no-with.js +2 -0
  215. package/lib/rules/nonblock-statement-body-position.js +4 -0
  216. package/lib/rules/object-curly-newline.js +4 -0
  217. package/lib/rules/object-curly-spacing.js +2 -0
  218. package/lib/rules/object-property-newline.js +3 -2
  219. package/lib/rules/object-shorthand.js +2 -0
  220. package/lib/rules/one-var-declaration-per-line.js +2 -0
  221. package/lib/rules/one-var.js +13 -1
  222. package/lib/rules/operator-assignment.js +2 -0
  223. package/lib/rules/operator-linebreak.js +2 -0
  224. package/lib/rules/padded-blocks.js +2 -0
  225. package/lib/rules/padding-line-between-statements.js +7 -0
  226. package/lib/rules/prefer-arrow-callback.js +2 -0
  227. package/lib/rules/prefer-const.js +116 -11
  228. package/lib/rules/prefer-destructuring.js +3 -0
  229. package/lib/rules/prefer-numeric-literals.js +2 -1
  230. package/lib/rules/prefer-object-spread.js +4 -0
  231. package/lib/rules/prefer-promise-reject-errors.js +4 -0
  232. package/lib/rules/prefer-reflect.js +4 -1
  233. package/lib/rules/prefer-rest-params.js +2 -0
  234. package/lib/rules/prefer-spread.js +2 -1
  235. package/lib/rules/prefer-template.js +2 -1
  236. package/lib/rules/quote-props.js +2 -0
  237. package/lib/rules/quotes.js +2 -0
  238. package/lib/rules/radix.js +2 -0
  239. package/lib/rules/require-atomic-updates.js +91 -30
  240. package/lib/rules/require-await.js +3 -0
  241. package/lib/rules/require-jsdoc.js +2 -0
  242. package/lib/rules/require-unicode-regexp.js +4 -0
  243. package/lib/rules/require-yield.js +2 -0
  244. package/lib/rules/rest-spread-spacing.js +4 -0
  245. package/lib/rules/semi-spacing.js +2 -0
  246. package/lib/rules/semi-style.js +3 -0
  247. package/lib/rules/semi.js +2 -0
  248. package/lib/rules/sort-imports.js +2 -0
  249. package/lib/rules/sort-keys.js +3 -0
  250. package/lib/rules/sort-vars.js +2 -0
  251. package/lib/rules/space-before-blocks.js +46 -35
  252. package/lib/rules/space-before-function-paren.js +2 -0
  253. package/lib/rules/space-in-parens.js +2 -0
  254. package/lib/rules/space-infix-ops.js +18 -25
  255. package/lib/rules/space-unary-ops.js +2 -0
  256. package/lib/rules/spaced-comment.js +2 -0
  257. package/lib/rules/strict.js +2 -0
  258. package/lib/rules/switch-colon-spacing.js +4 -0
  259. package/lib/rules/symbol-description.js +2 -0
  260. package/lib/rules/template-curly-spacing.js +2 -0
  261. package/lib/rules/template-tag-spacing.js +2 -0
  262. package/lib/rules/unicode-bom.js +2 -0
  263. package/lib/rules/use-isnan.js +2 -0
  264. package/lib/rules/valid-jsdoc.js +2 -0
  265. package/lib/rules/valid-typeof.js +2 -0
  266. package/lib/rules/vars-on-top.js +2 -0
  267. package/lib/rules/wrap-iife.js +2 -0
  268. package/lib/rules/wrap-regex.js +3 -1
  269. package/lib/rules/yield-star-spacing.js +2 -0
  270. package/lib/rules/yoda.js +2 -0
  271. package/lib/testers/rule-tester.js +2 -2
  272. package/lib/util/source-code-fixer.js +1 -1
  273. package/package.json +12 -12
@@ -165,6 +165,8 @@ function eachSelfAssignment(left, right, props, report) {
165
165
 
166
166
  module.exports = {
167
167
  meta: {
168
+ type: "problem",
169
+
168
170
  docs: {
169
171
  description: "disallow assignments where both sides are exactly the same",
170
172
  category: "Best Practices",
@@ -12,6 +12,8 @@
12
12
 
13
13
  module.exports = {
14
14
  meta: {
15
+ type: "problem",
16
+
15
17
  docs: {
16
18
  description: "disallow comparisons where both sides are exactly the same",
17
19
  category: "Best Practices",
@@ -17,6 +17,8 @@ const astUtils = require("../util/ast-utils");
17
17
 
18
18
  module.exports = {
19
19
  meta: {
20
+ type: "suggestion",
21
+
20
22
  docs: {
21
23
  description: "disallow comma operators",
22
24
  category: "Best Practices",
@@ -10,6 +10,8 @@
10
10
 
11
11
  module.exports = {
12
12
  meta: {
13
+ type: "suggestion",
14
+
13
15
  docs: {
14
16
  description: "disallow identifiers from shadowing restricted names",
15
17
  category: "Variables",
@@ -17,6 +17,8 @@ const astUtils = require("../util/ast-utils");
17
17
 
18
18
  module.exports = {
19
19
  meta: {
20
+ type: "suggestion",
21
+
20
22
  docs: {
21
23
  description: "disallow variable declarations from shadowing variables declared in the outer scope",
22
24
  category: "Variables",
@@ -12,16 +12,19 @@
12
12
 
13
13
  module.exports = {
14
14
  meta: {
15
+ type: "layout",
16
+
15
17
  docs: {
16
18
  description: "disallow spacing between function identifiers and their applications (deprecated)",
17
19
  category: "Stylistic Issues",
18
20
  recommended: false,
19
- replacedBy: ["func-call-spacing"],
20
21
  url: "https://eslint.org/docs/rules/no-spaced-func"
21
22
  },
22
23
 
23
24
  deprecated: true,
24
25
 
26
+ replacedBy: ["func-call-spacing"],
27
+
25
28
  fixable: "whitespace",
26
29
  schema: []
27
30
  },
@@ -10,6 +10,8 @@
10
10
 
11
11
  module.exports = {
12
12
  meta: {
13
+ type: "problem",
14
+
13
15
  docs: {
14
16
  description: "disallow sparse arrays",
15
17
  category: "Possible Errors",
@@ -13,6 +13,8 @@
13
13
 
14
14
  module.exports = {
15
15
  meta: {
16
+ type: "suggestion",
17
+
16
18
  docs: {
17
19
  description: "disallow synchronous methods",
18
20
  category: "Node.js and CommonJS",
@@ -8,7 +8,9 @@
8
8
  //------------------------------------------------------------------------------
9
9
  // Helpers
10
10
  //------------------------------------------------------------------------------
11
- const regex = /\t/;
11
+
12
+ const tabRegex = /\t+/g;
13
+ const anyNonWhitespaceRegex = /\S/;
12
14
 
13
15
  //------------------------------------------------------------------------------
14
16
  // Public Interface
@@ -16,27 +18,44 @@ const regex = /\t/;
16
18
 
17
19
  module.exports = {
18
20
  meta: {
21
+ type: "layout",
22
+
19
23
  docs: {
20
24
  description: "disallow all tabs",
21
25
  category: "Stylistic Issues",
22
26
  recommended: false,
23
27
  url: "https://eslint.org/docs/rules/no-tabs"
24
28
  },
25
- schema: []
29
+ schema: [{
30
+ type: "object",
31
+ properties: {
32
+ allowIndentationTabs: {
33
+ type: "boolean"
34
+ }
35
+ },
36
+ additionalProperties: false
37
+ }]
26
38
  },
27
39
 
28
40
  create(context) {
41
+ const sourceCode = context.getSourceCode();
42
+ const allowIndentationTabs = context.options && context.options[0] && context.options[0].allowIndentationTabs;
43
+
29
44
  return {
30
45
  Program(node) {
31
- context.getSourceCode().getLines().forEach((line, index) => {
32
- const match = regex.exec(line);
46
+ sourceCode.getLines().forEach((line, index) => {
47
+ let match;
48
+
49
+ while ((match = tabRegex.exec(line)) !== null) {
50
+ if (allowIndentationTabs && !anyNonWhitespaceRegex.test(line.slice(0, match.index))) {
51
+ continue;
52
+ }
33
53
 
34
- if (match) {
35
54
  context.report({
36
55
  node,
37
56
  loc: {
38
57
  line: index + 1,
39
- column: match.index + 1
58
+ column: match.index
40
59
  },
41
60
  message: "Unexpected tab character."
42
61
  });
@@ -10,6 +10,8 @@
10
10
 
11
11
  module.exports = {
12
12
  meta: {
13
+ type: "problem",
14
+
13
15
  docs: {
14
16
  description: "disallow template literal placeholder syntax in regular strings",
15
17
  category: "Possible Errors",
@@ -11,6 +11,8 @@
11
11
 
12
12
  module.exports = {
13
13
  meta: {
14
+ type: "suggestion",
15
+
14
16
  docs: {
15
17
  description: "disallow ternary operators",
16
18
  category: "Stylistic Issues",
@@ -36,6 +36,8 @@ function isConstructorFunction(node) {
36
36
 
37
37
  module.exports = {
38
38
  meta: {
39
+ type: "problem",
40
+
39
41
  docs: {
40
42
  description: "disallow `this`/`super` before calling `super()` in constructors",
41
43
  category: "ECMAScript 6",
@@ -13,6 +13,8 @@ const astUtils = require("../util/ast-utils");
13
13
 
14
14
  module.exports = {
15
15
  meta: {
16
+ type: "suggestion",
17
+
16
18
  docs: {
17
19
  description: "disallow throwing literals as exceptions",
18
20
  category: "Best Practices",
@@ -16,6 +16,8 @@ const astUtils = require("../util/ast-utils");
16
16
 
17
17
  module.exports = {
18
18
  meta: {
19
+ type: "layout",
20
+
19
21
  docs: {
20
22
  description: "disallow trailing whitespace at the end of lines",
21
23
  category: "Stylistic Issues",
@@ -13,6 +13,8 @@ const astUtils = require("../util/ast-utils");
13
13
 
14
14
  module.exports = {
15
15
  meta: {
16
+ type: "suggestion",
17
+
16
18
  docs: {
17
19
  description: "disallow initializing variables to `undefined`",
18
20
  category: "Variables",
@@ -21,7 +23,6 @@ module.exports = {
21
23
  },
22
24
 
23
25
  schema: [],
24
-
25
26
  fixable: "code"
26
27
  },
27
28
 
@@ -25,6 +25,8 @@ function hasTypeOfOperator(node) {
25
25
 
26
26
  module.exports = {
27
27
  meta: {
28
+ type: "problem",
29
+
28
30
  docs: {
29
31
  description: "disallow the use of undeclared variables unless mentioned in `/*global */` comments",
30
32
  category: "Variables",
@@ -10,6 +10,8 @@
10
10
 
11
11
  module.exports = {
12
12
  meta: {
13
+ type: "suggestion",
14
+
13
15
  docs: {
14
16
  description: "disallow the use of `undefined` as an identifier",
15
17
  category: "Variables",
@@ -11,6 +11,8 @@
11
11
 
12
12
  module.exports = {
13
13
  meta: {
14
+ type: "suggestion",
15
+
14
16
  docs: {
15
17
  description: "disallow dangling underscores in identifiers",
16
18
  category: "Stylistic Issues",
@@ -16,6 +16,8 @@ const astUtils = require("../util/ast-utils");
16
16
 
17
17
  module.exports = {
18
18
  meta: {
19
+ type: "problem",
20
+
19
21
  docs: {
20
22
  description: "disallow confusing multiline expressions",
21
23
  category: "Possible Errors",
@@ -165,6 +165,8 @@ function updateModifiedFlag(conditions, modifiers) {
165
165
 
166
166
  module.exports = {
167
167
  meta: {
168
+ type: "problem",
169
+
168
170
  docs: {
169
171
  description: "disallow unmodified loop conditions",
170
172
  category: "Best Practices",
@@ -24,6 +24,8 @@ const OPERATOR_INVERSES = {
24
24
 
25
25
  module.exports = {
26
26
  meta: {
27
+ type: "suggestion",
28
+
27
29
  docs: {
28
30
  description: "disallow ternary operators when simpler alternatives exist",
29
31
  category: "Stylistic Issues",
@@ -101,6 +101,8 @@ class ConsecutiveRange {
101
101
 
102
102
  module.exports = {
103
103
  meta: {
104
+ type: "problem",
105
+
104
106
  docs: {
105
107
  description: "disallow unreachable code after `return`, `throw`, `continue`, and `break` statements",
106
108
  category: "Possible Errors",
@@ -180,7 +182,6 @@ module.exports = {
180
182
  ContinueStatement: reportIfUnreachable,
181
183
  DebuggerStatement: reportIfUnreachable,
182
184
  DoWhileStatement: reportIfUnreachable,
183
- EmptyStatement: reportIfUnreachable,
184
185
  ExpressionStatement: reportIfUnreachable,
185
186
  ForInStatement: reportIfUnreachable,
186
187
  ForOfStatement: reportIfUnreachable,
@@ -20,6 +20,8 @@ const SENTINEL_NODE_TYPE_CONTINUE = /^(?:Program|(?:Function|Class)(?:Declaratio
20
20
 
21
21
  module.exports = {
22
22
  meta: {
23
+ type: "problem",
24
+
23
25
  docs: {
24
26
  description: "disallow control flow statements in `finally` blocks",
25
27
  category: "Possible Errors",
@@ -41,12 +41,15 @@ function isNegation(node) {
41
41
 
42
42
  module.exports = {
43
43
  meta: {
44
+ type: "problem",
45
+
44
46
  docs: {
45
47
  description: "disallow negating the left operand of relational operators",
46
48
  category: "Possible Errors",
47
49
  recommended: true,
48
50
  url: "https://eslint.org/docs/rules/no-unsafe-negation"
49
51
  },
52
+
50
53
  schema: [],
51
54
  fixable: "code"
52
55
  },
@@ -10,6 +10,8 @@
10
10
 
11
11
  module.exports = {
12
12
  meta: {
13
+ type: "suggestion",
14
+
13
15
  docs: {
14
16
  description: "disallow unused expressions",
15
17
  category: "Best Practices",
@@ -11,6 +11,8 @@
11
11
 
12
12
  module.exports = {
13
13
  meta: {
14
+ type: "suggestion",
15
+
14
16
  docs: {
15
17
  description: "disallow unused labels",
16
18
  category: "Best Practices",
@@ -19,7 +21,6 @@ module.exports = {
19
21
  },
20
22
 
21
23
  schema: [],
22
-
23
24
  fixable: "code"
24
25
  },
25
26
 
@@ -18,6 +18,8 @@ const astUtils = require("../util/ast-utils");
18
18
 
19
19
  module.exports = {
20
20
  meta: {
21
+ type: "problem",
22
+
21
23
  docs: {
22
24
  description: "disallow unused variables",
23
25
  category: "Variables",
@@ -223,6 +225,32 @@ module.exports = {
223
225
  return false;
224
226
  }
225
227
 
228
+ /**
229
+ * Gets a list of function definitions for a specified variable.
230
+ * @param {Variable} variable - eslint-scope variable object.
231
+ * @returns {ASTNode[]} Function nodes.
232
+ * @private
233
+ */
234
+ function getFunctionDefinitions(variable) {
235
+ const functionDefinitions = [];
236
+
237
+ variable.defs.forEach(def => {
238
+ const { type, node } = def;
239
+
240
+ // FunctionDeclarations
241
+ if (type === "FunctionName") {
242
+ functionDefinitions.push(node);
243
+ }
244
+
245
+ // FunctionExpressions
246
+ if (type === "Variable" && node.init &&
247
+ (node.init.type === "FunctionExpression" || node.init.type === "ArrowFunctionExpression")) {
248
+ functionDefinitions.push(node.init);
249
+ }
250
+ });
251
+ return functionDefinitions;
252
+ }
253
+
226
254
  /**
227
255
  * Checks the position of given nodes.
228
256
  *
@@ -372,22 +400,18 @@ module.exports = {
372
400
  return ref.isRead() && (
373
401
 
374
402
  // self update. e.g. `a += 1`, `a++`
375
- (
376
- parent.type === "AssignmentExpression" &&
403
+ (// in RHS of an assignment for itself. e.g. `a = a + 1`
404
+ ((
405
+ parent.type === "AssignmentExpression" &&
377
406
  granpa.type === "ExpressionStatement" &&
378
407
  parent.left === id
379
- ) ||
408
+ ) ||
380
409
  (
381
410
  parent.type === "UpdateExpression" &&
382
411
  granpa.type === "ExpressionStatement"
383
- ) ||
384
-
385
- // in RHS of an assignment for itself. e.g. `a = a + 1`
386
- (
387
- rhsNode &&
388
- isInside(id, rhsNode) &&
389
- !isInsideOfStorableFunction(id, rhsNode)
390
- )
412
+ ) || rhsNode &&
413
+ isInside(id, rhsNode) &&
414
+ !isInsideOfStorableFunction(id, rhsNode)))
391
415
  );
392
416
  }
393
417
 
@@ -435,7 +459,7 @@ module.exports = {
435
459
  * @private
436
460
  */
437
461
  function isUsedVariable(variable) {
438
- const functionNodes = variable.defs.filter(def => def.type === "FunctionName").map(def => def.node),
462
+ const functionNodes = getFunctionDefinitions(variable),
439
463
  isFunctionDefinition = functionNodes.length > 0;
440
464
  let rhsNode = null;
441
465
 
@@ -469,7 +493,7 @@ module.exports = {
469
493
  const posteriorParams = params.slice(params.indexOf(variable) + 1);
470
494
 
471
495
  // If any used parameters occur after this parameter, do not report.
472
- return !posteriorParams.some(v => v.references.length > 0);
496
+ return !posteriorParams.some(v => v.references.length > 0 || v.eslintUsed);
473
497
  }
474
498
 
475
499
  /**
@@ -136,6 +136,8 @@ function isInInitializer(variable, reference) {
136
136
 
137
137
  module.exports = {
138
138
  meta: {
139
+ type: "problem",
140
+
139
141
  docs: {
140
142
  description: "disallow the use of variables before they are defined",
141
143
  category: "Variables",
@@ -49,6 +49,8 @@ function isValidThisArg(expectedThis, thisArg, sourceCode) {
49
49
 
50
50
  module.exports = {
51
51
  meta: {
52
+ type: "suggestion",
53
+
52
54
  docs: {
53
55
  description: "disallow unnecessary calls to `.call()` and `.apply()`",
54
56
  category: "Best Practices",
@@ -18,6 +18,8 @@ const MESSAGE_UNNECESSARY_COMPUTED = "Unnecessarily computed property [{{propert
18
18
 
19
19
  module.exports = {
20
20
  meta: {
21
+ type: "suggestion",
22
+
21
23
  docs: {
22
24
  description: "disallow unnecessary computed property keys in object literals",
23
25
  category: "ECMAScript 6",
@@ -26,7 +28,6 @@ module.exports = {
26
28
  },
27
29
 
28
30
  schema: [],
29
-
30
31
  fixable: "code"
31
32
  },
32
33
  create(context) {
@@ -66,6 +66,8 @@ function getRight(node) {
66
66
 
67
67
  module.exports = {
68
68
  meta: {
69
+ type: "suggestion",
70
+
69
71
  docs: {
70
72
  description: "disallow unnecessary concatenation of literals or template literals",
71
73
  category: "Best Practices",
@@ -142,6 +142,8 @@ function isRedundantSuperCall(body, ctorParams) {
142
142
 
143
143
  module.exports = {
144
144
  meta: {
145
+ type: "suggestion",
146
+
145
147
  docs: {
146
148
  description: "disallow unnecessary constructors",
147
149
  category: "ECMAScript 6",
@@ -79,6 +79,8 @@ function parseRegExp(regExpText) {
79
79
 
80
80
  module.exports = {
81
81
  meta: {
82
+ type: "suggestion",
83
+
82
84
  docs: {
83
85
  description: "disallow unnecessary escape characters",
84
86
  category: "Best Practices",
@@ -11,13 +11,17 @@
11
11
 
12
12
  module.exports = {
13
13
  meta: {
14
+ type: "suggestion",
15
+
14
16
  docs: {
15
17
  description: "disallow renaming import, export, and destructured assignments to the same name",
16
18
  category: "ECMAScript 6",
17
19
  recommended: false,
18
20
  url: "https://eslint.org/docs/rules/no-useless-rename"
19
21
  },
22
+
20
23
  fixable: "code",
24
+
21
25
  schema: [
22
26
  {
23
27
  type: "object",
@@ -66,12 +66,15 @@ function isInFinally(node) {
66
66
 
67
67
  module.exports = {
68
68
  meta: {
69
+ type: "suggestion",
70
+
69
71
  docs: {
70
72
  description: "disallow redundant return statements",
71
73
  category: "Best Practices",
72
74
  recommended: false,
73
75
  url: "https://eslint.org/docs/rules/no-useless-return"
74
76
  },
77
+
75
78
  fixable: "code",
76
79
  schema: []
77
80
  },
@@ -180,6 +180,8 @@ function hasReferenceInTDZ(node) {
180
180
 
181
181
  module.exports = {
182
182
  meta: {
183
+ type: "suggestion",
184
+
183
185
  docs: {
184
186
  description: "require `let` or `const` instead of `var`",
185
187
  category: "ECMAScript 6",
@@ -10,6 +10,8 @@
10
10
 
11
11
  module.exports = {
12
12
  meta: {
13
+ type: "suggestion",
14
+
13
15
  docs: {
14
16
  description: "disallow `void` operators",
15
17
  category: "Best Practices",
@@ -13,6 +13,8 @@ const astUtils = require("../util/ast-utils");
13
13
 
14
14
  module.exports = {
15
15
  meta: {
16
+ type: "suggestion",
17
+
16
18
  docs: {
17
19
  description: "disallow specified warning terms in comments",
18
20
  category: "Best Practices",
@@ -16,6 +16,8 @@ const astUtils = require("../util/ast-utils");
16
16
 
17
17
  module.exports = {
18
18
  meta: {
19
+ type: "layout",
20
+
19
21
  docs: {
20
22
  description: "disallow whitespace before properties",
21
23
  category: "Stylistic Issues",
@@ -11,6 +11,8 @@
11
11
 
12
12
  module.exports = {
13
13
  meta: {
14
+ type: "suggestion",
15
+
14
16
  docs: {
15
17
  description: "disallow `with` statements",
16
18
  category: "Best Practices",
@@ -12,13 +12,17 @@ const POSITION_SCHEMA = { enum: ["beside", "below", "any"] };
12
12
 
13
13
  module.exports = {
14
14
  meta: {
15
+ type: "layout",
16
+
15
17
  docs: {
16
18
  description: "enforce the location of single-line statements",
17
19
  category: "Stylistic Issues",
18
20
  recommended: false,
19
21
  url: "https://eslint.org/docs/rules/nonblock-statement-body-position"
20
22
  },
23
+
21
24
  fixable: "whitespace",
25
+
22
26
  schema: [
23
27
  POSITION_SCHEMA,
24
28
  {
@@ -134,13 +134,17 @@ function areLineBreaksRequired(node, options, first, last) {
134
134
 
135
135
  module.exports = {
136
136
  meta: {
137
+ type: "layout",
138
+
137
139
  docs: {
138
140
  description: "enforce consistent line breaks inside braces",
139
141
  category: "Stylistic Issues",
140
142
  recommended: false,
141
143
  url: "https://eslint.org/docs/rules/object-curly-newline"
142
144
  },
145
+
143
146
  fixable: "whitespace",
147
+
144
148
  schema: [
145
149
  {
146
150
  oneOf: [
@@ -12,6 +12,8 @@ const astUtils = require("../util/ast-utils");
12
12
 
13
13
  module.exports = {
14
14
  meta: {
15
+ type: "layout",
16
+
15
17
  docs: {
16
18
  description: "enforce consistent spacing inside braces",
17
19
  category: "Stylistic Issues",