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.
- package/CHANGELOG.md +76 -0
- package/README.md +2 -2
- package/conf/eslint-recommended.js +1 -0
- package/lib/cli-engine.js +129 -32
- package/lib/cli.js +6 -1
- package/lib/config/autoconfig.js +0 -1
- package/lib/config/config-rule.js +4 -4
- package/lib/config/config-validator.js +2 -2
- package/lib/config.js +15 -2
- package/lib/linter.js +17 -120
- package/lib/options.js +5 -0
- package/lib/rules/accessor-pairs.js +4 -0
- package/lib/rules/array-bracket-newline.js +5 -0
- package/lib/rules/array-bracket-spacing.js +5 -0
- package/lib/rules/array-callback-return.js +2 -0
- package/lib/rules/array-element-newline.js +4 -1
- package/lib/rules/arrow-body-style.js +2 -0
- package/lib/rules/arrow-parens.js +2 -0
- package/lib/rules/arrow-spacing.js +2 -0
- package/lib/rules/block-scoped-var.js +2 -0
- package/lib/rules/block-spacing.js +2 -0
- package/lib/rules/brace-style.js +2 -0
- package/lib/rules/callback-return.js +2 -0
- package/lib/rules/camelcase.js +26 -14
- package/lib/rules/capitalized-comments.js +4 -0
- package/lib/rules/class-methods-use-this.js +3 -0
- package/lib/rules/comma-dangle.js +4 -0
- package/lib/rules/comma-spacing.js +2 -0
- package/lib/rules/comma-style.js +12 -2
- package/lib/rules/complexity.js +2 -0
- package/lib/rules/computed-property-spacing.js +2 -0
- package/lib/rules/consistent-return.js +2 -0
- package/lib/rules/consistent-this.js +2 -0
- package/lib/rules/constructor-super.js +2 -0
- package/lib/rules/curly.js +2 -0
- package/lib/rules/default-case.js +2 -0
- package/lib/rules/dot-location.js +2 -0
- package/lib/rules/dot-notation.js +2 -0
- package/lib/rules/eol-last.js +5 -0
- package/lib/rules/eqeqeq.js +2 -1
- package/lib/rules/for-direction.js +4 -0
- package/lib/rules/func-call-spacing.js +4 -0
- package/lib/rules/func-name-matching.js +3 -0
- package/lib/rules/func-names.js +3 -0
- package/lib/rules/func-style.js +3 -0
- package/lib/rules/function-paren-newline.js +5 -0
- package/lib/rules/generator-star-spacing.js +3 -0
- package/lib/rules/getter-return.js +5 -0
- package/lib/rules/global-require.js +2 -0
- package/lib/rules/guard-for-in.js +2 -0
- package/lib/rules/handle-callback-err.js +3 -1
- package/lib/rules/id-blacklist.js +2 -0
- package/lib/rules/id-length.js +2 -0
- package/lib/rules/id-match.js +101 -27
- package/lib/rules/implicit-arrow-linebreak.js +147 -2
- package/lib/rules/indent-legacy.js +4 -4
- package/lib/rules/indent.js +31 -23
- package/lib/rules/init-declarations.js +2 -0
- package/lib/rules/jsx-quotes.js +2 -0
- package/lib/rules/key-spacing.js +4 -3
- package/lib/rules/keyword-spacing.js +7 -1
- package/lib/rules/line-comment-position.js +2 -0
- package/lib/rules/linebreak-style.js +2 -0
- package/lib/rules/lines-around-comment.js +2 -0
- package/lib/rules/lines-around-directive.js +6 -2
- package/lib/rules/lines-between-class-members.js +2 -0
- package/lib/rules/max-classes-per-file.js +4 -0
- package/lib/rules/max-depth.js +2 -0
- package/lib/rules/max-len.js +2 -0
- package/lib/rules/max-lines-per-function.js +2 -0
- package/lib/rules/max-lines.js +2 -0
- package/lib/rules/max-nested-callbacks.js +2 -0
- package/lib/rules/max-params.js +2 -0
- package/lib/rules/max-statements-per-line.js +2 -0
- package/lib/rules/max-statements.js +2 -0
- package/lib/rules/multiline-comment-style.js +3 -0
- package/lib/rules/multiline-ternary.js +3 -0
- package/lib/rules/new-cap.js +2 -0
- package/lib/rules/new-parens.js +2 -1
- package/lib/rules/newline-after-var.js +5 -2
- package/lib/rules/newline-before-return.js +6 -3
- package/lib/rules/newline-per-chained-call.js +4 -0
- package/lib/rules/no-alert.js +2 -0
- package/lib/rules/no-array-constructor.js +2 -0
- package/lib/rules/no-async-promise-executor.js +3 -0
- package/lib/rules/no-await-in-loop.js +4 -0
- package/lib/rules/no-bitwise.js +2 -0
- package/lib/rules/no-buffer-constructor.js +4 -0
- package/lib/rules/no-caller.js +2 -0
- package/lib/rules/no-case-declarations.js +2 -0
- package/lib/rules/no-catch-shadow.js +6 -3
- package/lib/rules/no-class-assign.js +2 -0
- package/lib/rules/no-compare-neg-zero.js +4 -0
- package/lib/rules/no-cond-assign.js +2 -0
- package/lib/rules/no-confusing-arrow.js +2 -0
- package/lib/rules/no-console.js +2 -0
- package/lib/rules/no-const-assign.js +2 -0
- package/lib/rules/no-constant-condition.js +2 -1
- package/lib/rules/no-continue.js +2 -0
- package/lib/rules/no-control-regex.js +4 -2
- package/lib/rules/no-debugger.js +4 -0
- package/lib/rules/no-delete-var.js +2 -0
- package/lib/rules/no-div-regex.js +2 -0
- package/lib/rules/no-dupe-args.js +2 -0
- package/lib/rules/no-dupe-class-members.js +2 -0
- package/lib/rules/no-dupe-keys.js +2 -0
- package/lib/rules/no-duplicate-case.js +2 -0
- package/lib/rules/no-duplicate-imports.js +2 -0
- package/lib/rules/no-else-return.js +2 -1
- package/lib/rules/no-empty-character-class.js +2 -0
- package/lib/rules/no-empty-function.js +2 -0
- package/lib/rules/no-empty-pattern.js +2 -0
- package/lib/rules/no-empty.js +2 -0
- package/lib/rules/no-eq-null.js +2 -0
- package/lib/rules/no-eval.js +2 -0
- package/lib/rules/no-ex-assign.js +2 -0
- package/lib/rules/no-extend-native.js +2 -0
- package/lib/rules/no-extra-bind.js +2 -1
- package/lib/rules/no-extra-boolean-cast.js +2 -1
- package/lib/rules/no-extra-label.js +2 -1
- package/lib/rules/no-extra-parens.js +5 -6
- package/lib/rules/no-extra-semi.js +2 -0
- package/lib/rules/no-fallthrough.js +2 -0
- package/lib/rules/no-floating-decimal.js +2 -1
- package/lib/rules/no-func-assign.js +2 -0
- package/lib/rules/no-global-assign.js +2 -0
- package/lib/rules/no-implicit-coercion.js +3 -0
- package/lib/rules/no-implicit-globals.js +2 -0
- package/lib/rules/no-implied-eval.js +3 -1
- package/lib/rules/no-inline-comments.js +2 -0
- package/lib/rules/no-inner-declarations.js +2 -0
- package/lib/rules/no-invalid-regexp.js +2 -0
- package/lib/rules/no-invalid-this.js +2 -0
- package/lib/rules/no-irregular-whitespace.js +7 -9
- package/lib/rules/no-iterator.js +2 -0
- package/lib/rules/no-label-var.js +2 -0
- package/lib/rules/no-labels.js +2 -0
- package/lib/rules/no-lone-blocks.js +2 -0
- package/lib/rules/no-lonely-if.js +2 -1
- package/lib/rules/no-loop-func.js +2 -0
- package/lib/rules/no-magic-numbers.js +3 -0
- package/lib/rules/no-misleading-character-class.js +4 -0
- package/lib/rules/no-mixed-operators.js +3 -0
- package/lib/rules/no-mixed-requires.js +2 -0
- package/lib/rules/no-mixed-spaces-and-tabs.js +2 -0
- package/lib/rules/no-multi-assign.js +3 -0
- package/lib/rules/no-multi-spaces.js +2 -0
- package/lib/rules/no-multi-str.js +2 -0
- package/lib/rules/no-multiple-empty-lines.js +2 -0
- package/lib/rules/no-native-reassign.js +4 -1
- package/lib/rules/no-negated-condition.js +2 -0
- package/lib/rules/no-negated-in-lhs.js +5 -2
- package/lib/rules/no-nested-ternary.js +2 -0
- package/lib/rules/no-new-func.js +2 -0
- package/lib/rules/no-new-object.js +2 -0
- package/lib/rules/no-new-require.js +2 -0
- package/lib/rules/no-new-symbol.js +2 -0
- package/lib/rules/no-new-wrappers.js +2 -0
- package/lib/rules/no-new.js +2 -0
- package/lib/rules/no-obj-calls.js +2 -0
- package/lib/rules/no-octal-escape.js +2 -0
- package/lib/rules/no-octal.js +2 -0
- package/lib/rules/no-param-reassign.js +2 -0
- package/lib/rules/no-path-concat.js +2 -0
- package/lib/rules/no-plusplus.js +2 -0
- package/lib/rules/no-process-env.js +2 -0
- package/lib/rules/no-process-exit.js +2 -0
- package/lib/rules/no-proto.js +2 -0
- package/lib/rules/no-prototype-builtins.js +2 -0
- package/lib/rules/no-redeclare.js +2 -0
- package/lib/rules/no-regex-spaces.js +2 -1
- package/lib/rules/no-restricted-globals.js +2 -0
- package/lib/rules/no-restricted-imports.js +41 -23
- package/lib/rules/no-restricted-modules.js +2 -0
- package/lib/rules/no-restricted-properties.js +2 -0
- package/lib/rules/no-restricted-syntax.js +2 -0
- package/lib/rules/no-return-assign.js +2 -0
- package/lib/rules/no-return-await.js +4 -0
- package/lib/rules/no-script-url.js +2 -0
- package/lib/rules/no-self-assign.js +2 -0
- package/lib/rules/no-self-compare.js +2 -0
- package/lib/rules/no-sequences.js +2 -0
- package/lib/rules/no-shadow-restricted-names.js +2 -0
- package/lib/rules/no-shadow.js +2 -0
- package/lib/rules/no-spaced-func.js +4 -1
- package/lib/rules/no-sparse-arrays.js +2 -0
- package/lib/rules/no-sync.js +2 -0
- package/lib/rules/no-tabs.js +2 -0
- package/lib/rules/no-template-curly-in-string.js +2 -0
- package/lib/rules/no-ternary.js +2 -0
- package/lib/rules/no-this-before-super.js +2 -1
- package/lib/rules/no-throw-literal.js +2 -0
- package/lib/rules/no-trailing-spaces.js +2 -0
- package/lib/rules/no-undef-init.js +2 -1
- package/lib/rules/no-undef.js +2 -0
- package/lib/rules/no-undefined.js +2 -0
- package/lib/rules/no-underscore-dangle.js +2 -0
- package/lib/rules/no-unexpected-multiline.js +2 -0
- package/lib/rules/no-unmodified-loop-condition.js +2 -0
- package/lib/rules/no-unneeded-ternary.js +2 -0
- package/lib/rules/no-unreachable.js +2 -1
- package/lib/rules/no-unsafe-finally.js +2 -0
- package/lib/rules/no-unsafe-negation.js +3 -0
- package/lib/rules/no-unused-expressions.js +2 -0
- package/lib/rules/no-unused-labels.js +2 -1
- package/lib/rules/no-unused-vars.js +36 -12
- package/lib/rules/no-use-before-define.js +2 -0
- package/lib/rules/no-useless-call.js +2 -0
- package/lib/rules/no-useless-catch.js +51 -0
- package/lib/rules/no-useless-computed-key.js +2 -1
- package/lib/rules/no-useless-concat.js +2 -0
- package/lib/rules/no-useless-constructor.js +2 -0
- package/lib/rules/no-useless-escape.js +2 -0
- package/lib/rules/no-useless-rename.js +4 -0
- package/lib/rules/no-useless-return.js +3 -0
- package/lib/rules/no-var.js +2 -0
- package/lib/rules/no-void.js +2 -0
- package/lib/rules/no-warning-comments.js +2 -0
- package/lib/rules/no-whitespace-before-property.js +2 -0
- package/lib/rules/no-with.js +2 -0
- package/lib/rules/nonblock-statement-body-position.js +4 -0
- package/lib/rules/object-curly-newline.js +4 -1
- package/lib/rules/object-curly-spacing.js +2 -0
- package/lib/rules/object-property-newline.js +3 -2
- package/lib/rules/object-shorthand.js +2 -0
- package/lib/rules/one-var-declaration-per-line.js +2 -0
- package/lib/rules/one-var.js +2 -1
- package/lib/rules/operator-assignment.js +2 -0
- package/lib/rules/operator-linebreak.js +2 -0
- package/lib/rules/padded-blocks.js +2 -0
- package/lib/rules/padding-line-between-statements.js +41 -0
- package/lib/rules/prefer-arrow-callback.js +2 -0
- package/lib/rules/prefer-const.js +116 -11
- package/lib/rules/prefer-destructuring.js +3 -0
- package/lib/rules/prefer-numeric-literals.js +2 -1
- package/lib/rules/prefer-object-spread.js +4 -0
- package/lib/rules/prefer-promise-reject-errors.js +4 -0
- package/lib/rules/prefer-reflect.js +4 -1
- package/lib/rules/prefer-rest-params.js +2 -0
- package/lib/rules/prefer-spread.js +2 -1
- package/lib/rules/prefer-template.js +2 -1
- package/lib/rules/quote-props.js +2 -0
- package/lib/rules/quotes.js +50 -25
- package/lib/rules/radix.js +2 -0
- package/lib/rules/require-atomic-updates.js +4 -0
- package/lib/rules/require-await.js +3 -0
- package/lib/rules/require-jsdoc.js +6 -1
- package/lib/rules/require-unicode-regexp.js +4 -0
- package/lib/rules/require-yield.js +2 -0
- package/lib/rules/rest-spread-spacing.js +4 -0
- package/lib/rules/semi-spacing.js +2 -0
- package/lib/rules/semi-style.js +3 -0
- package/lib/rules/semi.js +2 -0
- package/lib/rules/sort-imports.js +2 -0
- package/lib/rules/sort-keys.js +3 -0
- package/lib/rules/sort-vars.js +2 -0
- package/lib/rules/space-before-blocks.js +46 -35
- package/lib/rules/space-before-function-paren.js +2 -0
- package/lib/rules/space-in-parens.js +2 -1
- package/lib/rules/space-infix-ops.js +6 -1
- package/lib/rules/space-unary-ops.js +2 -0
- package/lib/rules/spaced-comment.js +2 -0
- package/lib/rules/strict.js +2 -0
- package/lib/rules/switch-colon-spacing.js +4 -0
- package/lib/rules/symbol-description.js +2 -0
- package/lib/rules/template-curly-spacing.js +2 -0
- package/lib/rules/template-tag-spacing.js +2 -0
- package/lib/rules/unicode-bom.js +2 -0
- package/lib/rules/use-isnan.js +2 -0
- package/lib/rules/valid-jsdoc.js +6 -1
- package/lib/rules/valid-typeof.js +2 -0
- package/lib/rules/vars-on-top.js +2 -0
- package/lib/rules/wrap-iife.js +2 -0
- package/lib/rules/wrap-regex.js +3 -1
- package/lib/rules/yield-star-spacing.js +2 -0
- package/lib/rules/yoda.js +2 -0
- package/lib/testers/rule-tester.js +2 -2
- package/lib/util/config-comment-parser.js +144 -0
- package/lib/util/glob-utils.js +1 -1
- package/lib/{ignored-paths.js → util/ignored-paths.js} +4 -4
- package/lib/{report-translator.js → util/report-translator.js} +2 -2
- package/lib/util/source-code.js +2 -1
- package/messages/all-files-ignored.txt +1 -1
- 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:
|
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) {
|
package/lib/rules/indent.js
CHANGED
@@ -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
|
-
|
532
|
-
|
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
|
-
|
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
|
-
|
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,
|
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);
|
package/lib/rules/jsx-quotes.js
CHANGED
package/lib/rules/key-spacing.js
CHANGED
@@ -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:
|
561
|
+
ExportDefaultDeclaration: checkSpacingForModuleDeclaration,
|
556
562
|
ExportAllDeclaration: checkSpacingForModuleDeclaration,
|
557
563
|
FunctionDeclaration: checkSpacingForFunction,
|
558
564
|
ImportDeclaration: checkSpacingForModuleDeclaration,
|
@@ -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) {
|
@@ -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
|
}
|
package/lib/rules/max-depth.js
CHANGED
package/lib/rules/max-len.js
CHANGED
package/lib/rules/max-lines.js
CHANGED
package/lib/rules/max-params.js
CHANGED
@@ -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"]
|
package/lib/rules/new-cap.js
CHANGED
package/lib/rules/new-parens.js
CHANGED
@@ -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) {
|