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
@@ -4,18 +4,28 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
+ const {
8
+ isArrowToken,
9
+ isParenthesised,
10
+ isOpeningParenToken
11
+ } = require("../util/ast-utils");
12
+
7
13
  //------------------------------------------------------------------------------
8
14
  // Rule Definition
9
15
  //------------------------------------------------------------------------------
10
16
  module.exports = {
11
17
  meta: {
18
+ type: "layout",
19
+
12
20
  docs: {
13
21
  description: "enforce the location of arrow function bodies",
14
22
  category: "Stylistic Issues",
15
23
  recommended: false,
16
24
  url: "https://eslint.org/docs/rules/implicit-arrow-linebreak"
17
25
  },
26
+
18
27
  fixable: "whitespace",
28
+
19
29
  schema: [
20
30
  {
21
31
  enum: ["beside", "below"]
@@ -37,10 +47,145 @@ module.exports = {
37
47
  return context.options[0] || "beside";
38
48
  }
39
49
 
50
+ /**
51
+ * Formats the comments depending on whether it's a line or block comment.
52
+ * @param {Comment[]} comments The array of comments between the arrow and body
53
+ * @param {Integer} column The column number of the first token
54
+ * @returns {string} A string of comment text joined by line breaks
55
+ */
56
+ function formatComments(comments, column) {
57
+ const whiteSpaces = " ".repeat(column);
58
+
59
+ return `${comments.map(comment => {
60
+
61
+ if (comment.type === "Line") {
62
+ return `//${comment.value}`;
63
+ }
64
+
65
+ return `/*${comment.value}*/`;
66
+ }).join(`\n${whiteSpaces}`)}\n${whiteSpaces}`;
67
+ }
68
+
69
+ /**
70
+ * Finds the first token to prepend comments to depending on the parent type
71
+ * @param {Node} node The validated node
72
+ * @returns {Token|Node} The node to prepend comments to
73
+ */
74
+ function findFirstToken(node) {
75
+ switch (node.parent.type) {
76
+ case "VariableDeclarator":
77
+
78
+ // If the parent is first or only declarator, return the declaration, else, declarator
79
+ return sourceCode.getFirstToken(
80
+ node.parent.parent.declarations.length === 1 ||
81
+ node.parent.parent.declarations[0].id.name === node.parent.id.name
82
+ ? node.parent.parent : node.parent
83
+ );
84
+ case "CallExpression":
85
+ case "Property":
86
+
87
+ // find the object key
88
+ return sourceCode.getFirstToken(node.parent);
89
+ default:
90
+ return node;
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Helper function for adding parentheses fixes for nodes containing nested arrow functions
96
+ * @param {Fixer} fixer Fixer
97
+ * @param {Token} arrow - The arrow token
98
+ * @param {ASTNode} arrowBody - The arrow function body
99
+ * @returns {Function[]} autofixer -- wraps function bodies with parentheses
100
+ */
101
+ function addParentheses(fixer, arrow, arrowBody) {
102
+ const parenthesesFixes = [];
103
+ let closingParentheses = "";
104
+
105
+ let followingBody = arrowBody;
106
+ let currentArrow = arrow;
107
+
108
+ while (currentArrow) {
109
+ if (!isParenthesised(sourceCode, followingBody)) {
110
+ parenthesesFixes.push(
111
+ fixer.insertTextAfter(currentArrow, " (")
112
+ );
113
+
114
+ const paramsToken = sourceCode.getTokenBefore(currentArrow, token =>
115
+ isOpeningParenToken(token) || token.type === "Identifier");
116
+
117
+ const whiteSpaces = " ".repeat(paramsToken.loc.start.column);
118
+
119
+ closingParentheses = `\n${whiteSpaces})${closingParentheses}`;
120
+ }
121
+
122
+ currentArrow = sourceCode.getTokenAfter(currentArrow, isArrowToken);
123
+
124
+ if (currentArrow) {
125
+ followingBody = sourceCode.getTokenAfter(currentArrow, token => !isOpeningParenToken(token));
126
+ }
127
+ }
128
+
129
+ return [...parenthesesFixes,
130
+ fixer.insertTextAfter(arrowBody, closingParentheses)
131
+ ];
132
+ }
133
+
134
+ /**
135
+ * Autofixes the function body to collapse onto the same line as the arrow.
136
+ * If comments exist, prepends the comments before the arrow function.
137
+ * If the function body contains arrow functions, appends the function bodies with parentheses.
138
+ * @param {Token} arrowToken The arrow token.
139
+ * @param {ASTNode} arrowBody the function body
140
+ * @param {ASTNode} node The evaluated node
141
+ * @returns {Function} autofixer -- validates the node to adhere to besides
142
+ */
143
+ function autoFixBesides(arrowToken, arrowBody, node) {
144
+ return fixer => {
145
+ const placeBesides = fixer.replaceTextRange([arrowToken.range[1], arrowBody.range[0]], " ");
146
+
147
+ const comments = sourceCode.getCommentsInside(node).filter(comment =>
148
+ comment.loc.start.line < arrowBody.loc.start.line);
149
+
150
+ if (comments.length) {
151
+
152
+ // If the grandparent is not a variable declarator
153
+ if (
154
+ arrowBody.parent &&
155
+ arrowBody.parent.parent &&
156
+ arrowBody.parent.parent.type !== "VariableDeclarator"
157
+ ) {
158
+
159
+ // If any arrow functions follow, return the necessary parens fixes.
160
+ if (sourceCode.getTokenAfter(arrowToken, isArrowToken) && arrowBody.parent.parent.type !== "VariableDeclarator") {
161
+ return addParentheses(fixer, arrowToken, arrowBody);
162
+ }
163
+
164
+ // If any arrow functions precede, the necessary fixes have already been returned, so return null.
165
+ if (sourceCode.getTokenBefore(arrowToken, isArrowToken) && arrowBody.parent.parent.type !== "VariableDeclarator") {
166
+ return null;
167
+ }
168
+ }
169
+
170
+ const firstToken = findFirstToken(node);
171
+
172
+ const commentText = formatComments(comments, firstToken.loc.start.column);
173
+
174
+ const commentBeforeExpression = fixer.insertTextBeforeRange(
175
+ firstToken.range,
176
+ commentText
177
+ );
178
+
179
+ return [placeBesides, commentBeforeExpression];
180
+ }
181
+
182
+ return placeBesides;
183
+ };
184
+ }
185
+
40
186
  /**
41
187
  * Validates the location of an arrow function body
42
188
  * @param {ASTNode} node The arrow function body
43
- * @param {string} keywordName The applicable keyword name for the arrow function body
44
189
  * @returns {void}
45
190
  */
46
191
  function validateExpression(node) {
@@ -72,7 +217,7 @@ module.exports = {
72
217
  context.report({
73
218
  node: fixerTarget,
74
219
  message: "Expected no linebreak before this expression.",
75
- fix: fixer => fixer.replaceTextRange([tokenBefore.range[1], fixerTarget.range[0]], " ")
220
+ fix: autoFixBesides(tokenBefore, fixerTarget, node)
76
221
  });
77
222
  }
78
223
  }
@@ -21,16 +21,19 @@ const astUtils = require("../util/ast-utils");
21
21
  /* istanbul ignore next: this rule has known coverage issues, but it's deprecated and shouldn't be updated in the future anyway. */
22
22
  module.exports = {
23
23
  meta: {
24
+ type: "layout",
25
+
24
26
  docs: {
25
27
  description: "enforce consistent indentation",
26
28
  category: "Stylistic Issues",
27
29
  recommended: false,
28
- replacedBy: ["indent"],
29
30
  url: "https://eslint.org/docs/rules/indent-legacy"
30
31
  },
31
32
 
32
33
  deprecated: true,
33
34
 
35
+ replacedBy: ["indent"],
36
+
34
37
  fixable: "whitespace",
35
38
 
36
39
  schema: [
@@ -297,7 +300,6 @@ module.exports = {
297
300
  * @param {int} gottenTabs Indentation tab count in the actual node/code
298
301
  * @param {Object=} loc Error line and column location
299
302
  * @param {boolean} isLastNodeCheck Is the error for last node check
300
- * @param {int} lastNodeCheckEndOffset Number of charecters to skip from the end
301
303
  * @returns {void}
302
304
  */
303
305
  function report(node, needed, gottenSpaces, gottenTabs, loc, isLastNodeCheck) {
@@ -362,7 +364,6 @@ module.exports = {
362
364
  * Check indent for node
363
365
  * @param {ASTNode} node Node to check
364
366
  * @param {int} neededIndent needed indent
365
- * @param {boolean} [excludeCommas=false] skip comma on start of line
366
367
  * @returns {void}
367
368
  */
368
369
  function checkNodeIndent(node, neededIndent) {
@@ -410,7 +411,6 @@ module.exports = {
410
411
  * Check indent for nodes list
411
412
  * @param {ASTNode[]} nodes list of node objects
412
413
  * @param {int} indent needed indent
413
- * @param {boolean} [excludeCommas=false] skip comma on start of line
414
414
  * @returns {void}
415
415
  */
416
416
  function checkNodesIndent(nodes, indent) {
@@ -490,6 +490,8 @@ const ELEMENT_LIST_SCHEMA = {
490
490
 
491
491
  module.exports = {
492
492
  meta: {
493
+ type: "layout",
494
+
493
495
  docs: {
494
496
  description: "enforce consistent indentation",
495
497
  category: "Stylistic Issues",
@@ -520,25 +522,13 @@ module.exports = {
520
522
  },
521
523
  VariableDeclarator: {
522
524
  oneOf: [
523
- {
524
- type: "integer",
525
- minimum: 0
526
- },
525
+ ELEMENT_LIST_SCHEMA,
527
526
  {
528
527
  type: "object",
529
528
  properties: {
530
- var: {
531
- type: "integer",
532
- minimum: 0
533
- },
534
- let: {
535
- type: "integer",
536
- minimum: 0
537
- },
538
- const: {
539
- type: "integer",
540
- minimum: 0
541
- }
529
+ var: ELEMENT_LIST_SCHEMA,
530
+ let: ELEMENT_LIST_SCHEMA,
531
+ const: ELEMENT_LIST_SCHEMA
542
532
  },
543
533
  additionalProperties: false
544
534
  }
@@ -659,7 +649,7 @@ module.exports = {
659
649
  if (context.options[1]) {
660
650
  lodash.merge(options, context.options[1]);
661
651
 
662
- if (typeof options.VariableDeclarator === "number") {
652
+ if (typeof options.VariableDeclarator === "number" || options.VariableDeclarator === "first") {
663
653
  options.VariableDeclarator = {
664
654
  var: options.VariableDeclarator,
665
655
  let: options.VariableDeclarator,
@@ -1227,9 +1217,13 @@ module.exports = {
1227
1217
  }
1228
1218
 
1229
1219
  const fromToken = sourceCode.getLastToken(node, token => token.type === "Identifier" && token.value === "from");
1220
+ const sourceToken = sourceCode.getLastToken(node, token => token.type === "String");
1221
+ const semiToken = sourceCode.getLastToken(node, token => token.type === "Punctuator" && token.value === ";");
1230
1222
 
1231
1223
  if (fromToken) {
1232
- offsets.setDesiredOffsets([fromToken.range[0], node.range[1]], sourceCode.getFirstToken(node), 1);
1224
+ const end = semiToken && semiToken.range[1] === sourceToken.range[1] ? node.range[1] : sourceToken.range[1];
1225
+
1226
+ offsets.setDesiredOffsets([fromToken.range[0], end], sourceCode.getFirstToken(node), 1);
1233
1227
  }
1234
1228
  },
1235
1229
 
@@ -1343,10 +1337,27 @@ module.exports = {
1343
1337
  },
1344
1338
 
1345
1339
  VariableDeclaration(node) {
1346
- const variableIndent = Object.prototype.hasOwnProperty.call(options.VariableDeclarator, node.kind)
1340
+ let variableIndent = Object.prototype.hasOwnProperty.call(options.VariableDeclarator, node.kind)
1347
1341
  ? options.VariableDeclarator[node.kind]
1348
1342
  : DEFAULT_VARIABLE_INDENT;
1349
1343
 
1344
+ const firstToken = sourceCode.getFirstToken(node),
1345
+ lastToken = sourceCode.getLastToken(node);
1346
+
1347
+ if (options.VariableDeclarator[node.kind] === "first") {
1348
+ if (node.declarations.length > 1) {
1349
+ addElementListIndent(
1350
+ node.declarations,
1351
+ firstToken,
1352
+ lastToken,
1353
+ "first"
1354
+ );
1355
+ return;
1356
+ }
1357
+
1358
+ variableIndent = DEFAULT_VARIABLE_INDENT;
1359
+ }
1360
+
1350
1361
  if (node.declarations[node.declarations.length - 1].loc.start.line > node.loc.start.line) {
1351
1362
 
1352
1363
  /*
@@ -1368,13 +1379,10 @@ module.exports = {
1368
1379
  * on the same line as the start of the declaration, provided that there are declarators that
1369
1380
  * follow this one.
1370
1381
  */
1371
- const firstToken = sourceCode.getFirstToken(node);
1372
-
1373
1382
  offsets.setDesiredOffsets(node.range, firstToken, variableIndent, true);
1374
1383
  } else {
1375
- offsets.setDesiredOffsets(node.range, sourceCode.getFirstToken(node), variableIndent);
1384
+ offsets.setDesiredOffsets(node.range, firstToken, variableIndent);
1376
1385
  }
1377
- const lastToken = sourceCode.getLastToken(node);
1378
1386
 
1379
1387
  if (astUtils.isSemicolonToken(lastToken)) {
1380
1388
  offsets.ignoreToken(lastToken);
@@ -44,6 +44,8 @@ function isInitialized(node) {
44
44
 
45
45
  module.exports = {
46
46
  meta: {
47
+ type: "suggestion",
48
+
47
49
  docs: {
48
50
  description: "require or disallow initialization in variable declarations",
49
51
  category: "Variables",
@@ -38,6 +38,8 @@ const QUOTE_SETTINGS = {
38
38
 
39
39
  module.exports = {
40
40
  meta: {
41
+ type: "layout",
42
+
41
43
  docs: {
42
44
  description: "enforce the consistent use of either double or single quotes in JSX attributes",
43
45
  category: "Stylistic Issues",
@@ -128,6 +128,8 @@ const messages = {
128
128
 
129
129
  module.exports = {
130
130
  meta: {
131
+ type: "layout",
132
+
131
133
  docs: {
132
134
  description: "enforce consistent spacing between keys and values in object literal properties",
133
135
  category: "Stylistic Issues",
@@ -360,10 +362,9 @@ module.exports = {
360
362
  */
361
363
  function isKeyValueProperty(property) {
362
364
  return !(
363
- property.method ||
365
+ (property.method ||
364
366
  property.shorthand ||
365
- property.kind !== "init" ||
366
- property.type !== "Property" // Could be "ExperimentalSpreadProperty" or "SpreadElement"
367
+ property.kind !== "init" || property.type !== "Property") // Could be "ExperimentalSpreadProperty" or "SpreadElement"
367
368
  );
368
369
  }
369
370
 
@@ -65,6 +65,8 @@ function isCloseParenOfTemplate(token) {
65
65
 
66
66
  module.exports = {
67
67
  meta: {
68
+ type: "layout",
69
+
68
70
  docs: {
69
71
  description: "enforce consistent spacing before and after keywords",
70
72
  category: "Stylistic Issues",
@@ -451,6 +453,10 @@ module.exports = {
451
453
  checkSpacingBefore(firstToken, PREV_TOKEN_M);
452
454
  checkSpacingAfter(firstToken, NEXT_TOKEN_M);
453
455
 
456
+ if (node.type === "ExportDefaultDeclaration") {
457
+ checkSpacingAround(sourceCode.getTokenAfter(firstToken));
458
+ }
459
+
454
460
  if (node.source) {
455
461
  const fromToken = sourceCode.getTokenBefore(node.source);
456
462
 
@@ -552,7 +558,7 @@ module.exports = {
552
558
  // Statements - Declarations
553
559
  ClassDeclaration: checkSpacingForClass,
554
560
  ExportNamedDeclaration: checkSpacingForModuleDeclaration,
555
- ExportDefaultDeclaration: checkSpacingAroundFirstToken,
561
+ ExportDefaultDeclaration: checkSpacingForModuleDeclaration,
556
562
  ExportAllDeclaration: checkSpacingForModuleDeclaration,
557
563
  FunctionDeclaration: checkSpacingForFunction,
558
564
  ImportDeclaration: checkSpacingForModuleDeclaration,
@@ -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 position of line comments",
17
19
  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",
22
24
  category: "Stylistic Issues",
@@ -52,6 +52,8 @@ function getCommentLineNums(comments) {
52
52
 
53
53
  module.exports = {
54
54
  meta: {
55
+ type: "layout",
56
+
55
57
  docs: {
56
58
  description: "require empty lines around comments",
57
59
  category: "Stylistic Issues",
@@ -14,13 +14,15 @@ const astUtils = require("../util/ast-utils");
14
14
 
15
15
  module.exports = {
16
16
  meta: {
17
+ type: "layout",
18
+
17
19
  docs: {
18
20
  description: "require or disallow newlines around directives",
19
21
  category: "Stylistic Issues",
20
22
  recommended: false,
21
- replacedBy: ["padding-line-between-statements"],
22
23
  url: "https://eslint.org/docs/rules/lines-around-directive"
23
24
  },
25
+
24
26
  schema: [{
25
27
  oneOf: [
26
28
  {
@@ -41,8 +43,10 @@ module.exports = {
41
43
  }
42
44
  ]
43
45
  }],
46
+
44
47
  fixable: "whitespace",
45
- deprecated: true
48
+ deprecated: true,
49
+ replacedBy: ["padding-line-between-statements"]
46
50
  },
47
51
 
48
52
  create(context) {
@@ -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: "require or disallow an empty line between class members",
17
19
  category: "Stylistic Issues",
@@ -15,18 +15,22 @@
15
15
 
16
16
  module.exports = {
17
17
  meta: {
18
+ type: "suggestion",
19
+
18
20
  docs: {
19
21
  description: "enforce a maximum number of classes per file",
20
22
  category: "Best Practices",
21
23
  recommended: false,
22
24
  url: "https://eslint.org/docs/rules/max-classes-per-file"
23
25
  },
26
+
24
27
  schema: [
25
28
  {
26
29
  type: "integer",
27
30
  minimum: 1
28
31
  }
29
32
  ],
33
+
30
34
  messages: {
31
35
  maximumExceeded: "Number of classes per file must not exceed {{ max }}"
32
36
  }
@@ -11,6 +11,8 @@
11
11
 
12
12
  module.exports = {
13
13
  meta: {
14
+ type: "suggestion",
15
+
14
16
  docs: {
15
17
  description: "enforce a maximum depth that blocks can be nested",
16
18
  category: "Stylistic Issues",
@@ -65,6 +65,8 @@ const OPTIONS_OR_INTEGER_SCHEMA = {
65
65
 
66
66
  module.exports = {
67
67
  meta: {
68
+ type: "layout",
69
+
68
70
  docs: {
69
71
  description: "enforce a maximum line length",
70
72
  category: "Stylistic Issues",
@@ -69,6 +69,8 @@ function getCommentLineNumbers(comments) {
69
69
 
70
70
  module.exports = {
71
71
  meta: {
72
+ type: "suggestion",
73
+
72
74
  docs: {
73
75
  description: "enforce a maximum number of line of code in a function",
74
76
  category: "Stylistic Issues",
@@ -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: "enforce a maximum number of lines per file",
22
24
  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 a maximum depth that callbacks can be nested",
16
18
  category: "Stylistic Issues",
@@ -19,6 +19,8 @@ const astUtils = require("../util/ast-utils");
19
19
 
20
20
  module.exports = {
21
21
  meta: {
22
+ type: "suggestion",
23
+
22
24
  docs: {
23
25
  description: "enforce a maximum number of parameters in function definitions",
24
26
  category: "Stylistic Issues",
@@ -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: "enforce a maximum number of statements allowed per line",
21
23
  category: "Stylistic Issues",
@@ -19,6 +19,8 @@ const astUtils = require("../util/ast-utils");
19
19
 
20
20
  module.exports = {
21
21
  meta: {
22
+ type: "suggestion",
23
+
22
24
  docs: {
23
25
  description: "enforce a maximum number of statements allowed in function blocks",
24
26
  category: "Stylistic Issues",
@@ -12,12 +12,15 @@ 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: "enforce a particular style for multiline comments",
17
19
  category: "Stylistic Issues",
18
20
  recommended: false,
19
21
  url: "https://eslint.org/docs/rules/multiline-comment-style"
20
22
  },
23
+
21
24
  fixable: "whitespace",
22
25
  schema: [{ enum: ["starred-block", "separate-lines", "bare-block"] }]
23
26
  },
@@ -13,12 +13,15 @@ const astUtils = require("../util/ast-utils");
13
13
 
14
14
  module.exports = {
15
15
  meta: {
16
+ type: "layout",
17
+
16
18
  docs: {
17
19
  description: "enforce newlines between operands of ternary expressions",
18
20
  category: "Stylistic Issues",
19
21
  recommended: false,
20
22
  url: "https://eslint.org/docs/rules/multiline-ternary"
21
23
  },
24
+
22
25
  schema: [
23
26
  {
24
27
  enum: ["always", "always-multiline", "never"]
@@ -74,6 +74,8 @@ function calculateCapIsNewExceptions(config) {
74
74
 
75
75
  module.exports = {
76
76
  meta: {
77
+ type: "suggestion",
78
+
77
79
  docs: {
78
80
  description: "require constructor names to begin with a capital letter",
79
81
  category: "Stylistic Issues",
@@ -21,6 +21,8 @@ const astUtils = require("../util/ast-utils");
21
21
 
22
22
  module.exports = {
23
23
  meta: {
24
+ type: "layout",
25
+
24
26
  docs: {
25
27
  description: "require parentheses when invoking a constructor with no arguments",
26
28
  category: "Stylistic Issues",
@@ -29,7 +31,6 @@ module.exports = {
29
31
  },
30
32
 
31
33
  schema: [],
32
-
33
34
  fixable: "code"
34
35
  },
35
36
 
@@ -18,11 +18,12 @@ const astUtils = require("../util/ast-utils");
18
18
 
19
19
  module.exports = {
20
20
  meta: {
21
+ type: "layout",
22
+
21
23
  docs: {
22
24
  description: "require or disallow an empty line after variable declarations",
23
25
  category: "Stylistic Issues",
24
26
  recommended: false,
25
- replacedBy: ["padding-line-between-statements"],
26
27
  url: "https://eslint.org/docs/rules/newline-after-var"
27
28
  },
28
29
 
@@ -34,7 +35,9 @@ module.exports = {
34
35
 
35
36
  fixable: "whitespace",
36
37
 
37
- deprecated: true
38
+ deprecated: true,
39
+
40
+ replacedBy: ["padding-line-between-statements"]
38
41
  },
39
42
 
40
43
  create(context) {