eslint 5.7.0 → 5.11.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 (284) hide show
  1. package/CHANGELOG.md +76 -0
  2. package/README.md +2 -2
  3. package/conf/eslint-recommended.js +1 -0
  4. package/lib/cli-engine.js +129 -32
  5. package/lib/cli.js +6 -1
  6. package/lib/config/autoconfig.js +0 -1
  7. package/lib/config/config-rule.js +4 -4
  8. package/lib/config/config-validator.js +2 -2
  9. package/lib/config.js +15 -2
  10. package/lib/linter.js +17 -120
  11. package/lib/options.js +5 -0
  12. package/lib/rules/accessor-pairs.js +4 -0
  13. package/lib/rules/array-bracket-newline.js +5 -0
  14. package/lib/rules/array-bracket-spacing.js +5 -0
  15. package/lib/rules/array-callback-return.js +2 -0
  16. package/lib/rules/array-element-newline.js +4 -1
  17. package/lib/rules/arrow-body-style.js +2 -0
  18. package/lib/rules/arrow-parens.js +2 -0
  19. package/lib/rules/arrow-spacing.js +2 -0
  20. package/lib/rules/block-scoped-var.js +2 -0
  21. package/lib/rules/block-spacing.js +2 -0
  22. package/lib/rules/brace-style.js +2 -0
  23. package/lib/rules/callback-return.js +2 -0
  24. package/lib/rules/camelcase.js +26 -14
  25. package/lib/rules/capitalized-comments.js +4 -0
  26. package/lib/rules/class-methods-use-this.js +3 -0
  27. package/lib/rules/comma-dangle.js +4 -0
  28. package/lib/rules/comma-spacing.js +2 -0
  29. package/lib/rules/comma-style.js +12 -2
  30. package/lib/rules/complexity.js +2 -0
  31. package/lib/rules/computed-property-spacing.js +2 -0
  32. package/lib/rules/consistent-return.js +2 -0
  33. package/lib/rules/consistent-this.js +2 -0
  34. package/lib/rules/constructor-super.js +2 -0
  35. package/lib/rules/curly.js +2 -0
  36. package/lib/rules/default-case.js +2 -0
  37. package/lib/rules/dot-location.js +2 -0
  38. package/lib/rules/dot-notation.js +2 -0
  39. package/lib/rules/eol-last.js +5 -0
  40. package/lib/rules/eqeqeq.js +2 -1
  41. package/lib/rules/for-direction.js +4 -0
  42. package/lib/rules/func-call-spacing.js +4 -0
  43. package/lib/rules/func-name-matching.js +3 -0
  44. package/lib/rules/func-names.js +3 -0
  45. package/lib/rules/func-style.js +3 -0
  46. package/lib/rules/function-paren-newline.js +5 -0
  47. package/lib/rules/generator-star-spacing.js +3 -0
  48. package/lib/rules/getter-return.js +5 -0
  49. package/lib/rules/global-require.js +2 -0
  50. package/lib/rules/guard-for-in.js +2 -0
  51. package/lib/rules/handle-callback-err.js +3 -1
  52. package/lib/rules/id-blacklist.js +2 -0
  53. package/lib/rules/id-length.js +2 -0
  54. package/lib/rules/id-match.js +101 -27
  55. package/lib/rules/implicit-arrow-linebreak.js +147 -2
  56. package/lib/rules/indent-legacy.js +4 -4
  57. package/lib/rules/indent.js +31 -23
  58. package/lib/rules/init-declarations.js +2 -0
  59. package/lib/rules/jsx-quotes.js +2 -0
  60. package/lib/rules/key-spacing.js +4 -3
  61. package/lib/rules/keyword-spacing.js +7 -1
  62. package/lib/rules/line-comment-position.js +2 -0
  63. package/lib/rules/linebreak-style.js +2 -0
  64. package/lib/rules/lines-around-comment.js +2 -0
  65. package/lib/rules/lines-around-directive.js +6 -2
  66. package/lib/rules/lines-between-class-members.js +2 -0
  67. package/lib/rules/max-classes-per-file.js +4 -0
  68. package/lib/rules/max-depth.js +2 -0
  69. package/lib/rules/max-len.js +2 -0
  70. package/lib/rules/max-lines-per-function.js +2 -0
  71. package/lib/rules/max-lines.js +2 -0
  72. package/lib/rules/max-nested-callbacks.js +2 -0
  73. package/lib/rules/max-params.js +2 -0
  74. package/lib/rules/max-statements-per-line.js +2 -0
  75. package/lib/rules/max-statements.js +2 -0
  76. package/lib/rules/multiline-comment-style.js +3 -0
  77. package/lib/rules/multiline-ternary.js +3 -0
  78. package/lib/rules/new-cap.js +2 -0
  79. package/lib/rules/new-parens.js +2 -1
  80. package/lib/rules/newline-after-var.js +5 -2
  81. package/lib/rules/newline-before-return.js +6 -3
  82. package/lib/rules/newline-per-chained-call.js +4 -0
  83. package/lib/rules/no-alert.js +2 -0
  84. package/lib/rules/no-array-constructor.js +2 -0
  85. package/lib/rules/no-async-promise-executor.js +3 -0
  86. package/lib/rules/no-await-in-loop.js +4 -0
  87. package/lib/rules/no-bitwise.js +2 -0
  88. package/lib/rules/no-buffer-constructor.js +4 -0
  89. package/lib/rules/no-caller.js +2 -0
  90. package/lib/rules/no-case-declarations.js +2 -0
  91. package/lib/rules/no-catch-shadow.js +6 -3
  92. package/lib/rules/no-class-assign.js +2 -0
  93. package/lib/rules/no-compare-neg-zero.js +4 -0
  94. package/lib/rules/no-cond-assign.js +2 -0
  95. package/lib/rules/no-confusing-arrow.js +2 -0
  96. package/lib/rules/no-console.js +2 -0
  97. package/lib/rules/no-const-assign.js +2 -0
  98. package/lib/rules/no-constant-condition.js +2 -1
  99. package/lib/rules/no-continue.js +2 -0
  100. package/lib/rules/no-control-regex.js +4 -2
  101. package/lib/rules/no-debugger.js +4 -0
  102. package/lib/rules/no-delete-var.js +2 -0
  103. package/lib/rules/no-div-regex.js +2 -0
  104. package/lib/rules/no-dupe-args.js +2 -0
  105. package/lib/rules/no-dupe-class-members.js +2 -0
  106. package/lib/rules/no-dupe-keys.js +2 -0
  107. package/lib/rules/no-duplicate-case.js +2 -0
  108. package/lib/rules/no-duplicate-imports.js +2 -0
  109. package/lib/rules/no-else-return.js +2 -1
  110. package/lib/rules/no-empty-character-class.js +2 -0
  111. package/lib/rules/no-empty-function.js +2 -0
  112. package/lib/rules/no-empty-pattern.js +2 -0
  113. package/lib/rules/no-empty.js +2 -0
  114. package/lib/rules/no-eq-null.js +2 -0
  115. package/lib/rules/no-eval.js +2 -0
  116. package/lib/rules/no-ex-assign.js +2 -0
  117. package/lib/rules/no-extend-native.js +2 -0
  118. package/lib/rules/no-extra-bind.js +2 -1
  119. package/lib/rules/no-extra-boolean-cast.js +2 -1
  120. package/lib/rules/no-extra-label.js +2 -1
  121. package/lib/rules/no-extra-parens.js +5 -6
  122. package/lib/rules/no-extra-semi.js +2 -0
  123. package/lib/rules/no-fallthrough.js +2 -0
  124. package/lib/rules/no-floating-decimal.js +2 -1
  125. package/lib/rules/no-func-assign.js +2 -0
  126. package/lib/rules/no-global-assign.js +2 -0
  127. package/lib/rules/no-implicit-coercion.js +3 -0
  128. package/lib/rules/no-implicit-globals.js +2 -0
  129. package/lib/rules/no-implied-eval.js +3 -1
  130. package/lib/rules/no-inline-comments.js +2 -0
  131. package/lib/rules/no-inner-declarations.js +2 -0
  132. package/lib/rules/no-invalid-regexp.js +2 -0
  133. package/lib/rules/no-invalid-this.js +2 -0
  134. package/lib/rules/no-irregular-whitespace.js +7 -9
  135. package/lib/rules/no-iterator.js +2 -0
  136. package/lib/rules/no-label-var.js +2 -0
  137. package/lib/rules/no-labels.js +2 -0
  138. package/lib/rules/no-lone-blocks.js +2 -0
  139. package/lib/rules/no-lonely-if.js +2 -1
  140. package/lib/rules/no-loop-func.js +2 -0
  141. package/lib/rules/no-magic-numbers.js +3 -0
  142. package/lib/rules/no-misleading-character-class.js +4 -0
  143. package/lib/rules/no-mixed-operators.js +3 -0
  144. package/lib/rules/no-mixed-requires.js +2 -0
  145. package/lib/rules/no-mixed-spaces-and-tabs.js +2 -0
  146. package/lib/rules/no-multi-assign.js +3 -0
  147. package/lib/rules/no-multi-spaces.js +2 -0
  148. package/lib/rules/no-multi-str.js +2 -0
  149. package/lib/rules/no-multiple-empty-lines.js +2 -0
  150. package/lib/rules/no-native-reassign.js +4 -1
  151. package/lib/rules/no-negated-condition.js +2 -0
  152. package/lib/rules/no-negated-in-lhs.js +5 -2
  153. package/lib/rules/no-nested-ternary.js +2 -0
  154. package/lib/rules/no-new-func.js +2 -0
  155. package/lib/rules/no-new-object.js +2 -0
  156. package/lib/rules/no-new-require.js +2 -0
  157. package/lib/rules/no-new-symbol.js +2 -0
  158. package/lib/rules/no-new-wrappers.js +2 -0
  159. package/lib/rules/no-new.js +2 -0
  160. package/lib/rules/no-obj-calls.js +2 -0
  161. package/lib/rules/no-octal-escape.js +2 -0
  162. package/lib/rules/no-octal.js +2 -0
  163. package/lib/rules/no-param-reassign.js +2 -0
  164. package/lib/rules/no-path-concat.js +2 -0
  165. package/lib/rules/no-plusplus.js +2 -0
  166. package/lib/rules/no-process-env.js +2 -0
  167. package/lib/rules/no-process-exit.js +2 -0
  168. package/lib/rules/no-proto.js +2 -0
  169. package/lib/rules/no-prototype-builtins.js +2 -0
  170. package/lib/rules/no-redeclare.js +2 -0
  171. package/lib/rules/no-regex-spaces.js +2 -1
  172. package/lib/rules/no-restricted-globals.js +2 -0
  173. package/lib/rules/no-restricted-imports.js +41 -23
  174. package/lib/rules/no-restricted-modules.js +2 -0
  175. package/lib/rules/no-restricted-properties.js +2 -0
  176. package/lib/rules/no-restricted-syntax.js +2 -0
  177. package/lib/rules/no-return-assign.js +2 -0
  178. package/lib/rules/no-return-await.js +4 -0
  179. package/lib/rules/no-script-url.js +2 -0
  180. package/lib/rules/no-self-assign.js +2 -0
  181. package/lib/rules/no-self-compare.js +2 -0
  182. package/lib/rules/no-sequences.js +2 -0
  183. package/lib/rules/no-shadow-restricted-names.js +2 -0
  184. package/lib/rules/no-shadow.js +2 -0
  185. package/lib/rules/no-spaced-func.js +4 -1
  186. package/lib/rules/no-sparse-arrays.js +2 -0
  187. package/lib/rules/no-sync.js +2 -0
  188. package/lib/rules/no-tabs.js +2 -0
  189. package/lib/rules/no-template-curly-in-string.js +2 -0
  190. package/lib/rules/no-ternary.js +2 -0
  191. package/lib/rules/no-this-before-super.js +2 -1
  192. package/lib/rules/no-throw-literal.js +2 -0
  193. package/lib/rules/no-trailing-spaces.js +2 -0
  194. package/lib/rules/no-undef-init.js +2 -1
  195. package/lib/rules/no-undef.js +2 -0
  196. package/lib/rules/no-undefined.js +2 -0
  197. package/lib/rules/no-underscore-dangle.js +2 -0
  198. package/lib/rules/no-unexpected-multiline.js +2 -0
  199. package/lib/rules/no-unmodified-loop-condition.js +2 -0
  200. package/lib/rules/no-unneeded-ternary.js +2 -0
  201. package/lib/rules/no-unreachable.js +2 -1
  202. package/lib/rules/no-unsafe-finally.js +2 -0
  203. package/lib/rules/no-unsafe-negation.js +3 -0
  204. package/lib/rules/no-unused-expressions.js +2 -0
  205. package/lib/rules/no-unused-labels.js +2 -1
  206. package/lib/rules/no-unused-vars.js +36 -12
  207. package/lib/rules/no-use-before-define.js +2 -0
  208. package/lib/rules/no-useless-call.js +2 -0
  209. package/lib/rules/no-useless-catch.js +51 -0
  210. package/lib/rules/no-useless-computed-key.js +2 -1
  211. package/lib/rules/no-useless-concat.js +2 -0
  212. package/lib/rules/no-useless-constructor.js +2 -0
  213. package/lib/rules/no-useless-escape.js +2 -0
  214. package/lib/rules/no-useless-rename.js +4 -0
  215. package/lib/rules/no-useless-return.js +3 -0
  216. package/lib/rules/no-var.js +2 -0
  217. package/lib/rules/no-void.js +2 -0
  218. package/lib/rules/no-warning-comments.js +2 -0
  219. package/lib/rules/no-whitespace-before-property.js +2 -0
  220. package/lib/rules/no-with.js +2 -0
  221. package/lib/rules/nonblock-statement-body-position.js +4 -0
  222. package/lib/rules/object-curly-newline.js +4 -1
  223. package/lib/rules/object-curly-spacing.js +2 -0
  224. package/lib/rules/object-property-newline.js +3 -2
  225. package/lib/rules/object-shorthand.js +2 -0
  226. package/lib/rules/one-var-declaration-per-line.js +2 -0
  227. package/lib/rules/one-var.js +2 -1
  228. package/lib/rules/operator-assignment.js +2 -0
  229. package/lib/rules/operator-linebreak.js +2 -0
  230. package/lib/rules/padded-blocks.js +2 -0
  231. package/lib/rules/padding-line-between-statements.js +41 -0
  232. package/lib/rules/prefer-arrow-callback.js +2 -0
  233. package/lib/rules/prefer-const.js +116 -11
  234. package/lib/rules/prefer-destructuring.js +3 -0
  235. package/lib/rules/prefer-numeric-literals.js +2 -1
  236. package/lib/rules/prefer-object-spread.js +4 -0
  237. package/lib/rules/prefer-promise-reject-errors.js +4 -0
  238. package/lib/rules/prefer-reflect.js +4 -1
  239. package/lib/rules/prefer-rest-params.js +2 -0
  240. package/lib/rules/prefer-spread.js +2 -1
  241. package/lib/rules/prefer-template.js +2 -1
  242. package/lib/rules/quote-props.js +2 -0
  243. package/lib/rules/quotes.js +50 -25
  244. package/lib/rules/radix.js +2 -0
  245. package/lib/rules/require-atomic-updates.js +4 -0
  246. package/lib/rules/require-await.js +3 -0
  247. package/lib/rules/require-jsdoc.js +6 -1
  248. package/lib/rules/require-unicode-regexp.js +4 -0
  249. package/lib/rules/require-yield.js +2 -0
  250. package/lib/rules/rest-spread-spacing.js +4 -0
  251. package/lib/rules/semi-spacing.js +2 -0
  252. package/lib/rules/semi-style.js +3 -0
  253. package/lib/rules/semi.js +2 -0
  254. package/lib/rules/sort-imports.js +2 -0
  255. package/lib/rules/sort-keys.js +3 -0
  256. package/lib/rules/sort-vars.js +2 -0
  257. package/lib/rules/space-before-blocks.js +46 -35
  258. package/lib/rules/space-before-function-paren.js +2 -0
  259. package/lib/rules/space-in-parens.js +2 -1
  260. package/lib/rules/space-infix-ops.js +6 -1
  261. package/lib/rules/space-unary-ops.js +2 -0
  262. package/lib/rules/spaced-comment.js +2 -0
  263. package/lib/rules/strict.js +2 -0
  264. package/lib/rules/switch-colon-spacing.js +4 -0
  265. package/lib/rules/symbol-description.js +2 -0
  266. package/lib/rules/template-curly-spacing.js +2 -0
  267. package/lib/rules/template-tag-spacing.js +2 -0
  268. package/lib/rules/unicode-bom.js +2 -0
  269. package/lib/rules/use-isnan.js +2 -0
  270. package/lib/rules/valid-jsdoc.js +6 -1
  271. package/lib/rules/valid-typeof.js +2 -0
  272. package/lib/rules/vars-on-top.js +2 -0
  273. package/lib/rules/wrap-iife.js +2 -0
  274. package/lib/rules/wrap-regex.js +3 -1
  275. package/lib/rules/yield-star-spacing.js +2 -0
  276. package/lib/rules/yoda.js +2 -0
  277. package/lib/testers/rule-tester.js +2 -2
  278. package/lib/util/config-comment-parser.js +144 -0
  279. package/lib/util/glob-utils.js +1 -1
  280. package/lib/{ignored-paths.js → util/ignored-paths.js} +4 -4
  281. package/lib/{report-translator.js → util/report-translator.js} +2 -2
  282. package/lib/util/source-code.js +2 -1
  283. package/messages/all-files-ignored.txt +1 -1
  284. package/package.json +10 -11
@@ -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: [
@@ -168,7 +172,6 @@ module.exports = {
168
172
  /**
169
173
  * Reports a given node if it violated this rule.
170
174
  * @param {ASTNode} node - A node to check. This is an ObjectExpression, ObjectPattern, ImportDeclaration or ExportNamedDeclaration node.
171
- * @param {{multiline: boolean, minProperties: number, consistent: boolean}} options - An option object.
172
175
  * @returns {void}
173
176
  */
174
177
  function check(node) {
@@ -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",
@@ -11,6 +11,8 @@
11
11
 
12
12
  module.exports = {
13
13
  meta: {
14
+ type: "layout",
15
+
14
16
  docs: {
15
17
  description: "enforce placing object properties on separate lines",
16
18
  category: "Stylistic Issues",
@@ -38,8 +40,7 @@ module.exports = {
38
40
 
39
41
  create(context) {
40
42
  const allowSameLine = context.options[0] && (
41
- Boolean(context.options[0].allowAllPropertiesOnSameLine) ||
42
- Boolean(context.options[0].allowMultiplePropertiesPerLine) // Deprecated
43
+ (Boolean(context.options[0].allowAllPropertiesOnSameLine) || Boolean(context.options[0].allowMultiplePropertiesPerLine)) // Deprecated
43
44
  );
44
45
  const errorMessage = allowSameLine
45
46
  ? "Object properties must go on a new line if they aren't all on the same line."
@@ -24,6 +24,8 @@ const astUtils = require("../util/ast-utils");
24
24
  //------------------------------------------------------------------------------
25
25
  module.exports = {
26
26
  meta: {
27
+ type: "suggestion",
28
+
27
29
  docs: {
28
30
  description: "require or disallow method and property shorthand syntax for object literals",
29
31
  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: "require or disallow newlines around variable declarations",
15
17
  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: "enforce variables to be declared either together or separately in functions",
16
18
  category: "Stylistic Issues",
@@ -308,7 +310,6 @@ module.exports = {
308
310
  /**
309
311
  * Fixer to split a VariableDeclaration into individual declarations
310
312
  * @param {VariableDeclaration} declaration The `VariableDeclaration` to split
311
- * @param {?Function} filter Function to filter the declarations
312
313
  * @returns {Function} The fixer function
313
314
  */
314
315
  function splitDeclarations(declaration) {
@@ -89,6 +89,8 @@ function canBeFixed(node) {
89
89
 
90
90
  module.exports = {
91
91
  meta: {
92
+ type: "suggestion",
93
+
92
94
  docs: {
93
95
  description: "require or disallow assignment operator shorthand where possible",
94
96
  category: "Stylistic Issues",
@@ -17,6 +17,8 @@ const astUtils = require("../util/ast-utils");
17
17
 
18
18
  module.exports = {
19
19
  meta: {
20
+ type: "layout",
21
+
20
22
  docs: {
21
23
  description: "enforce consistent linebreak style for operators",
22
24
  category: "Stylistic Issues",
@@ -11,6 +11,8 @@
11
11
 
12
12
  module.exports = {
13
13
  meta: {
14
+ type: "layout",
15
+
14
16
  docs: {
15
17
  description: "require or disallow padding within blocks",
16
18
  category: "Stylistic Issues",
@@ -36,6 +36,36 @@ function newKeywordTester(keyword) {
36
36
  };
37
37
  }
38
38
 
39
+ /**
40
+ * Creates tester which check if a node starts with specific keyword and spans a single line.
41
+ *
42
+ * @param {string} keyword The keyword to test.
43
+ * @returns {Object} the created tester.
44
+ * @private
45
+ */
46
+ function newSinglelineKeywordTester(keyword) {
47
+ return {
48
+ test: (node, sourceCode) =>
49
+ node.loc.start.line === node.loc.end.line &&
50
+ sourceCode.getFirstToken(node).value === keyword
51
+ };
52
+ }
53
+
54
+ /**
55
+ * Creates tester which check if a node starts with specific keyword and spans multiple lines.
56
+ *
57
+ * @param {string} keyword The keyword to test.
58
+ * @returns {Object} the created tester.
59
+ * @private
60
+ */
61
+ function newMultilineKeywordTester(keyword) {
62
+ return {
63
+ test: (node, sourceCode) =>
64
+ node.loc.start.line !== node.loc.end.line &&
65
+ sourceCode.getFirstToken(node).value === keyword
66
+ };
67
+ }
68
+
39
69
  /**
40
70
  * Creates tester which check if a node is specific type.
41
71
  *
@@ -368,6 +398,13 @@ const StatementTypes = {
368
398
  !isDirectivePrologue(node, sourceCode)
369
399
  },
370
400
 
401
+ "multiline-const": newMultilineKeywordTester("const"),
402
+ "multiline-let": newMultilineKeywordTester("let"),
403
+ "multiline-var": newMultilineKeywordTester("var"),
404
+ "singleline-const": newSinglelineKeywordTester("const"),
405
+ "singleline-let": newSinglelineKeywordTester("let"),
406
+ "singleline-var": newSinglelineKeywordTester("var"),
407
+
371
408
  block: newNodeTypeTester("BlockStatement"),
372
409
  empty: newNodeTypeTester("EmptyStatement"),
373
410
  function: newNodeTypeTester("FunctionDeclaration"),
@@ -400,13 +437,17 @@ const StatementTypes = {
400
437
 
401
438
  module.exports = {
402
439
  meta: {
440
+ type: "layout",
441
+
403
442
  docs: {
404
443
  description: "require or disallow padding lines between statements",
405
444
  category: "Stylistic Issues",
406
445
  recommended: false,
407
446
  url: "https://eslint.org/docs/rules/padding-line-between-statements"
408
447
  },
448
+
409
449
  fixable: "whitespace",
450
+
410
451
  schema: {
411
452
  definitions: {
412
453
  paddingType: {
@@ -132,6 +132,8 @@ function hasDuplicateParams(paramsList) {
132
132
 
133
133
  module.exports = {
134
134
  meta: {
135
+ type: "suggestion",
136
+
135
137
  docs: {
136
138
  description: "require using arrow functions for callbacks",
137
139
  category: "ECMAScript 6",
@@ -57,6 +57,7 @@ function canBecomeVariableDeclaration(identifier) {
57
57
  * @returns {boolean} Indicates if the variable is from outer scope or function parameters.
58
58
  */
59
59
  function isOuterVariableInDestructing(name, initScope) {
60
+
60
61
  if (initScope.through.find(ref => ref.resolved && ref.resolved.name === name)) {
61
62
  return true;
62
63
  }
@@ -96,6 +97,54 @@ function getDestructuringHost(reference) {
96
97
  return node;
97
98
  }
98
99
 
100
+ /**
101
+ * Determines if a destructuring assignment node contains
102
+ * any MemberExpression nodes. This is used to determine if a
103
+ * variable that is only written once using destructuring can be
104
+ * safely converted into a const declaration.
105
+ * @param {ASTNode} node The ObjectPattern or ArrayPattern node to check.
106
+ * @returns {boolean} True if the destructuring pattern contains
107
+ * a MemberExpression, false if not.
108
+ */
109
+ function hasMemberExpressionAssignment(node) {
110
+ switch (node.type) {
111
+ case "ObjectPattern":
112
+ return node.properties.some(prop => {
113
+ if (prop) {
114
+
115
+ /*
116
+ * Spread elements have an argument property while
117
+ * others have a value property. Because different
118
+ * parsers use different node types for spread elements,
119
+ * we just check if there is an argument property.
120
+ */
121
+ return hasMemberExpressionAssignment(prop.argument || prop.value);
122
+ }
123
+
124
+ return false;
125
+ });
126
+
127
+ case "ArrayPattern":
128
+ return node.elements.some(element => {
129
+ if (element) {
130
+ return hasMemberExpressionAssignment(element);
131
+ }
132
+
133
+ return false;
134
+ });
135
+
136
+ case "AssignmentPattern":
137
+ return hasMemberExpressionAssignment(node.left);
138
+
139
+ case "MemberExpression":
140
+ return true;
141
+
142
+ // no default
143
+ }
144
+
145
+ return false;
146
+ }
147
+
99
148
  /**
100
149
  * Gets an identifier node of a given variable.
101
150
  *
@@ -148,7 +197,8 @@ function getIdentifierIfShouldBeConst(variable, ignoreReadBeforeAssign) {
148
197
 
149
198
  if (destructuringHost !== null && destructuringHost.left !== void 0) {
150
199
  const leftNode = destructuringHost.left;
151
- let hasOuterVariables = false;
200
+ let hasOuterVariables = false,
201
+ hasNonIdentifiers = false;
152
202
 
153
203
  if (leftNode.type === "ObjectPattern") {
154
204
  const properties = leftNode.properties;
@@ -157,16 +207,23 @@ function getIdentifierIfShouldBeConst(variable, ignoreReadBeforeAssign) {
157
207
  .filter(prop => prop.value)
158
208
  .map(prop => prop.value.name)
159
209
  .some(name => isOuterVariableInDestructing(name, variable.scope));
210
+
211
+ hasNonIdentifiers = hasMemberExpressionAssignment(leftNode);
212
+
160
213
  } else if (leftNode.type === "ArrayPattern") {
161
214
  const elements = leftNode.elements;
162
215
 
163
216
  hasOuterVariables = elements
164
217
  .map(element => element && element.name)
165
218
  .some(name => isOuterVariableInDestructing(name, variable.scope));
219
+
220
+ hasNonIdentifiers = hasMemberExpressionAssignment(leftNode);
166
221
  }
167
- if (hasOuterVariables) {
222
+
223
+ if (hasOuterVariables || hasNonIdentifiers) {
168
224
  return null;
169
225
  }
226
+
170
227
  }
171
228
 
172
229
  writer = reference;
@@ -192,9 +249,11 @@ function getIdentifierIfShouldBeConst(variable, ignoreReadBeforeAssign) {
192
249
  if (!shouldBeConst) {
193
250
  return null;
194
251
  }
252
+
195
253
  if (isReadBeforeInit) {
196
254
  return variable.defs[0].name;
197
255
  }
256
+
198
257
  return writer.identifier;
199
258
  }
200
259
 
@@ -271,6 +330,8 @@ function findUp(node, type, shouldStop) {
271
330
 
272
331
  module.exports = {
273
332
  meta: {
333
+ type: "suggestion",
334
+
274
335
  docs: {
275
336
  description: "require `const` declarations for variables that are never reassigned after declared",
276
337
  category: "ECMAScript 6",
@@ -295,9 +356,11 @@ module.exports = {
295
356
  create(context) {
296
357
  const options = context.options[0] || {};
297
358
  const sourceCode = context.getSourceCode();
298
- const checkingMixedDestructuring = options.destructuring !== "all";
359
+ const shouldMatchAnyDestructuredVariable = options.destructuring !== "all";
299
360
  const ignoreReadBeforeAssign = options.ignoreReadBeforeAssign === true;
300
361
  const variables = [];
362
+ let reportCount = 0;
363
+ let name = "";
301
364
 
302
365
  /**
303
366
  * Reports given identifier nodes if all of the nodes should be declared
@@ -316,16 +379,43 @@ module.exports = {
316
379
  function checkGroup(nodes) {
317
380
  const nodesToReport = nodes.filter(Boolean);
318
381
 
319
- if (nodes.length && (checkingMixedDestructuring || nodesToReport.length === nodes.length)) {
382
+ if (nodes.length && (shouldMatchAnyDestructuredVariable || nodesToReport.length === nodes.length)) {
320
383
  const varDeclParent = findUp(nodes[0], "VariableDeclaration", parentNode => parentNode.type.endsWith("Statement"));
321
- const shouldFix = varDeclParent &&
384
+ const isVarDecParentNull = varDeclParent === null;
385
+
386
+ if (!isVarDecParentNull && varDeclParent.declarations.length > 0) {
387
+ const firstDeclaration = varDeclParent.declarations[0];
388
+
389
+ if (firstDeclaration.init) {
390
+ const firstDecParent = firstDeclaration.init.parent;
391
+
392
+ /*
393
+ * First we check the declaration type and then depending on
394
+ * if the type is a "VariableDeclarator" or its an "ObjectPattern"
395
+ * we compare the name from the first identifier, if the names are different
396
+ * we assign the new name and reset the count of reportCount and nodeCount in
397
+ * order to check each block for the number of reported errors and base our fix
398
+ * based on comparing nodes.length and nodesToReport.length.
399
+ */
400
+
401
+ if (firstDecParent.type === "VariableDeclarator") {
402
+
403
+ if (firstDecParent.id.name !== name) {
404
+ name = firstDecParent.id.name;
405
+ reportCount = 0;
406
+ }
407
+
408
+ if (firstDecParent.id.type === "ObjectPattern") {
409
+ if (firstDecParent.init.name !== name) {
410
+ name = firstDecParent.init.name;
411
+ reportCount = 0;
412
+ }
413
+ }
414
+ }
415
+ }
416
+ }
322
417
 
323
- /*
324
- * If there are multiple variable declarations, like {let a = 1, b = 2}, then
325
- * do not attempt to fix if one of the declarations should be `const`. It's
326
- * too hard to know how the developer would want to automatically resolve the issue.
327
- */
328
- varDeclParent.declarations.length === 1 &&
418
+ let shouldFix = varDeclParent &&
329
419
 
330
420
  // Don't do a fix unless the variable is initialized (or it's in a for-in or for-of loop)
331
421
  (varDeclParent.parent.type === "ForInStatement" || varDeclParent.parent.type === "ForOfStatement" || varDeclParent.declarations[0].init) &&
@@ -337,6 +427,21 @@ module.exports = {
337
427
  */
338
428
  nodesToReport.length === nodes.length;
339
429
 
430
+ if (!isVarDecParentNull && varDeclParent.declarations && varDeclParent.declarations.length !== 1) {
431
+
432
+ if (varDeclParent && varDeclParent.declarations && varDeclParent.declarations.length >= 1) {
433
+
434
+ /*
435
+ * Add nodesToReport.length to a count, then comparing the count to the length
436
+ * of the declarations in the current block.
437
+ */
438
+
439
+ reportCount += nodesToReport.length;
440
+
441
+ shouldFix = shouldFix && (reportCount === varDeclParent.declarations.length);
442
+ }
443
+ }
444
+
340
445
  nodesToReport.forEach(node => {
341
446
  context.report({
342
447
  node,
@@ -10,12 +10,15 @@
10
10
 
11
11
  module.exports = {
12
12
  meta: {
13
+ type: "suggestion",
14
+
13
15
  docs: {
14
16
  description: "require destructuring from arrays and/or objects",
15
17
  category: "ECMAScript 6",
16
18
  recommended: false,
17
19
  url: "https://eslint.org/docs/rules/prefer-destructuring"
18
20
  },
21
+
19
22
  schema: [
20
23
  {
21
24
 
@@ -38,6 +38,8 @@ function isParseInt(calleeNode) {
38
38
 
39
39
  module.exports = {
40
40
  meta: {
41
+ type: "suggestion",
42
+
41
43
  docs: {
42
44
  description: "disallow `parseInt()` and `Number.parseInt()` in favor of binary, octal, and hexadecimal literals",
43
45
  category: "ECMAScript 6",
@@ -46,7 +48,6 @@ module.exports = {
46
48
  },
47
49
 
48
50
  schema: [],
49
-
50
51
  fixable: "code"
51
52
  },
52
53
 
@@ -212,6 +212,8 @@ function defineFixer(node, sourceCode) {
212
212
 
213
213
  module.exports = {
214
214
  meta: {
215
+ type: "suggestion",
216
+
215
217
  docs: {
216
218
  description:
217
219
  "disallow using Object.assign with an object literal as the first argument and prefer the use of object spread instead.",
@@ -219,8 +221,10 @@ module.exports = {
219
221
  recommended: false,
220
222
  url: "https://eslint.org/docs/rules/prefer-object-spread"
221
223
  },
224
+
222
225
  schema: [],
223
226
  fixable: "code",
227
+
224
228
  messages: {
225
229
  useSpreadMessage: "Use an object spread instead of `Object.assign` eg: `{ ...foo }`",
226
230
  useLiteralMessage: "Use an object literal instead of `Object.assign`. eg: `{ foo: bar }`"
@@ -12,13 +12,17 @@ const astUtils = require("../util/ast-utils");
12
12
 
13
13
  module.exports = {
14
14
  meta: {
15
+ type: "suggestion",
16
+
15
17
  docs: {
16
18
  description: "require using Error objects as Promise rejection reasons",
17
19
  category: "Best Practices",
18
20
  recommended: false,
19
21
  url: "https://eslint.org/docs/rules/prefer-promise-reject-errors"
20
22
  },
23
+
21
24
  fixable: null,
25
+
22
26
  schema: [
23
27
  {
24
28
  type: "object",
@@ -11,16 +11,19 @@
11
11
 
12
12
  module.exports = {
13
13
  meta: {
14
+ type: "suggestion",
15
+
14
16
  docs: {
15
17
  description: "require `Reflect` methods where applicable",
16
18
  category: "ECMAScript 6",
17
19
  recommended: false,
18
- replacedBy: [],
19
20
  url: "https://eslint.org/docs/rules/prefer-reflect"
20
21
  },
21
22
 
22
23
  deprecated: true,
23
24
 
25
+ replacedBy: [],
26
+
24
27
  schema: [
25
28
  {
26
29
  type: "object",
@@ -62,6 +62,8 @@ function isNotNormalMemberAccess(reference) {
62
62
 
63
63
  module.exports = {
64
64
  meta: {
65
+ type: "suggestion",
66
+
65
67
  docs: {
66
68
  description: "require rest parameters instead of `arguments`",
67
69
  category: "ECMAScript 6",
@@ -49,6 +49,8 @@ function isValidThisArg(expectedThis, thisArg, context) {
49
49
 
50
50
  module.exports = {
51
51
  meta: {
52
+ type: "suggestion",
53
+
52
54
  docs: {
53
55
  description: "require spread operators instead of `.apply()`",
54
56
  category: "ECMAScript 6",
@@ -57,7 +59,6 @@ module.exports = {
57
59
  },
58
60
 
59
61
  schema: [],
60
-
61
62
  fixable: "code"
62
63
  },
63
64
 
@@ -141,6 +141,8 @@ function endsWithTemplateCurly(node) {
141
141
 
142
142
  module.exports = {
143
143
  meta: {
144
+ type: "suggestion",
145
+
144
146
  docs: {
145
147
  description: "require template literals instead of string concatenation",
146
148
  category: "ECMAScript 6",
@@ -149,7 +151,6 @@ module.exports = {
149
151
  },
150
152
 
151
153
  schema: [],
152
-
153
154
  fixable: "code"
154
155
  },
155
156
 
@@ -17,6 +17,8 @@ const espree = require("espree"),
17
17
 
18
18
  module.exports = {
19
19
  meta: {
20
+ type: "suggestion",
21
+
20
22
  docs: {
21
23
  description: "require quotes around object literal property names",
22
24
  category: "Stylistic Issues",