eslint 5.12.0 → 5.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +70 -0
- package/README.md +76 -143
- package/conf/eslint-all.js +3 -5
- package/conf/eslint-recommended.js +4 -268
- package/lib/built-in-rules-index.js +277 -0
- package/lib/cli-engine.js +6 -2
- package/lib/config/config-file.js +25 -2
- package/lib/config/config-initializer.js +150 -143
- package/lib/config/config-ops.js +30 -0
- package/lib/config/config-rule.js +2 -4
- package/lib/config/plugins.js +12 -4
- package/lib/config.js +1 -1
- package/lib/formatters/table.js +13 -4
- package/lib/formatters/tap.js +7 -4
- package/lib/linter.js +31 -31
- package/lib/load-rules.js +2 -5
- package/lib/rules/accessor-pairs.js +4 -2
- package/lib/rules/array-bracket-newline.js +4 -2
- package/lib/rules/array-callback-return.js +2 -1
- package/lib/rules/array-element-newline.js +4 -2
- package/lib/rules/arrow-body-style.js +1 -1
- package/lib/rules/arrow-parens.js +2 -1
- package/lib/rules/arrow-spacing.js +7 -6
- package/lib/rules/brace-style.js +2 -1
- package/lib/rules/camelcase.js +3 -2
- package/lib/rules/capitalized-comments.js +15 -14
- package/lib/rules/class-methods-use-this.js +1 -1
- package/lib/rules/comma-spacing.js +10 -4
- package/lib/rules/complexity.js +7 -9
- package/lib/rules/consistent-return.js +2 -1
- package/lib/rules/dot-notation.js +5 -3
- package/lib/rules/eqeqeq.js +2 -1
- package/lib/rules/for-direction.js +30 -17
- package/lib/rules/func-call-spacing.js +2 -1
- package/lib/rules/func-style.js +3 -2
- package/lib/rules/getter-return.js +2 -1
- package/lib/rules/global-require.js +5 -2
- package/lib/rules/guard-for-in.js +5 -2
- package/lib/rules/handle-callback-err.js +5 -2
- package/lib/rules/id-blacklist.js +4 -1
- package/lib/rules/id-length.js +9 -6
- package/lib/rules/id-match.js +11 -5
- package/lib/rules/implicit-arrow-linebreak.js +7 -3
- package/lib/rules/indent-legacy.js +11 -5
- package/lib/rules/indent.js +18 -9
- package/lib/rules/init-declarations.js +13 -13
- package/lib/rules/jsx-quotes.js +5 -2
- package/lib/rules/key-spacing.js +70 -35
- package/lib/rules/keyword-spacing.js +18 -12
- package/lib/rules/line-comment-position.js +15 -8
- package/lib/rules/linebreak-style.js +6 -6
- package/lib/rules/lines-around-comment.js +20 -16
- package/lib/rules/lines-around-directive.js +5 -2
- package/lib/rules/lines-between-class-members.js +8 -6
- package/lib/rules/max-depth.js +11 -9
- package/lib/rules/max-len.js +24 -13
- package/lib/rules/max-lines-per-function.js +17 -18
- package/lib/rules/max-lines.js +14 -10
- package/lib/rules/max-nested-callbacks.js +12 -11
- package/lib/rules/max-params.js +11 -9
- package/lib/rules/max-statements-per-line.js +8 -5
- package/lib/rules/max-statements.js +12 -11
- package/lib/rules/multiline-comment-style.js +18 -17
- package/lib/rules/multiline-ternary.js +8 -6
- package/lib/rules/new-cap.js +18 -11
- package/lib/rules/new-parens.js +5 -2
- package/lib/rules/newline-after-var.js +6 -8
- package/lib/rules/newline-before-return.js +5 -1
- package/lib/rules/newline-per-chained-call.js +7 -3
- package/lib/rules/no-async-promise-executor.js +5 -2
- package/lib/rules/no-bitwise.js +2 -1
- package/lib/rules/no-confusing-arrow.js +1 -1
- package/lib/rules/no-constant-condition.js +24 -2
- package/lib/rules/no-duplicate-imports.js +17 -11
- package/lib/rules/no-else-return.js +2 -1
- package/lib/rules/no-empty.js +2 -1
- package/lib/rules/no-eval.js +1 -1
- package/lib/rules/no-extra-parens.js +4 -4
- package/lib/rules/no-fallthrough.js +8 -4
- package/lib/rules/no-floating-decimal.js +7 -3
- package/lib/rules/no-implicit-coercion.js +9 -6
- package/lib/rules/no-irregular-whitespace.js +8 -4
- package/lib/rules/no-labels.js +6 -4
- package/lib/rules/no-magic-numbers.js +6 -3
- package/lib/rules/no-mixed-operators.js +5 -4
- package/lib/rules/no-mixed-requires.js +4 -2
- package/lib/rules/no-multi-spaces.js +2 -1
- package/lib/rules/no-param-reassign.js +1 -1
- package/lib/rules/no-plusplus.js +2 -1
- package/lib/rules/no-redeclare.js +2 -2
- package/lib/rules/no-self-assign.js +2 -1
- package/lib/rules/no-shadow-restricted-names.js +16 -2
- package/lib/rules/no-shadow.js +3 -3
- package/lib/rules/no-sync.js +2 -1
- package/lib/rules/no-tabs.js +2 -1
- package/lib/rules/no-trailing-spaces.js +5 -3
- package/lib/rules/no-undef.js +7 -3
- package/lib/rules/no-underscore-dangle.js +6 -3
- package/lib/rules/no-unexpected-multiline.js +14 -13
- package/lib/rules/no-unneeded-ternary.js +2 -1
- package/lib/rules/no-unsafe-negation.js +6 -3
- package/lib/rules/no-unused-expressions.js +6 -3
- package/lib/rules/no-unused-labels.js +7 -2
- package/lib/rules/no-unused-vars.js +8 -4
- package/lib/rules/no-use-before-define.js +3 -3
- package/lib/rules/no-useless-rename.js +3 -3
- package/lib/rules/object-curly-newline.js +6 -4
- package/lib/rules/object-property-newline.js +5 -3
- package/lib/rules/object-shorthand.js +9 -5
- package/lib/rules/one-var.js +24 -38
- package/lib/rules/operator-assignment.js +8 -4
- package/lib/rules/padded-blocks.js +32 -9
- package/lib/rules/prefer-arrow-callback.js +4 -2
- package/lib/rules/prefer-const.js +7 -4
- package/lib/rules/prefer-destructuring.js +70 -12
- package/lib/rules/prefer-promise-reject-errors.js +1 -1
- package/lib/rules/prefer-spread.js +2 -13
- package/lib/rules/quote-props.js +10 -5
- package/lib/rules/quotes.js +4 -2
- package/lib/rules/require-jsdoc.js +13 -7
- package/lib/rules/semi-spacing.js +6 -8
- package/lib/rules/semi.js +5 -4
- package/lib/rules/sort-imports.js +6 -3
- package/lib/rules/sort-keys.js +13 -5
- package/lib/rules/sort-vars.js +2 -1
- package/lib/rules/space-before-function-paren.js +6 -3
- package/lib/rules/space-infix-ops.js +2 -1
- package/lib/rules/space-unary-ops.js +20 -10
- package/lib/rules/spaced-comment.js +2 -1
- package/lib/rules/strict.js +34 -35
- package/lib/rules/switch-colon-spacing.js +11 -8
- package/lib/rules/symbol-description.js +6 -3
- package/lib/rules/template-curly-spacing.js +10 -10
- package/lib/rules/template-tag-spacing.js +7 -3
- package/lib/rules/unicode-bom.js +7 -3
- package/lib/rules/use-isnan.js +5 -2
- package/lib/rules/valid-jsdoc.js +40 -19
- package/lib/rules/valid-typeof.js +9 -4
- package/lib/rules/vars-on-top.js +6 -4
- package/lib/rules/wrap-iife.js +12 -6
- package/lib/rules/yield-star-spacing.js +17 -10
- package/lib/rules/yoda.js +9 -4
- package/lib/rules.js +4 -34
- package/lib/util/ajv.js +1 -0
- package/lib/util/config-comment-parser.js +7 -10
- package/package.json +20 -20
@@ -31,23 +31,30 @@ module.exports = {
|
|
31
31
|
type: "object",
|
32
32
|
properties: {
|
33
33
|
position: {
|
34
|
-
enum: ["above", "beside"]
|
34
|
+
enum: ["above", "beside"],
|
35
|
+
default: "above"
|
35
36
|
},
|
36
37
|
ignorePattern: {
|
37
38
|
type: "string"
|
38
39
|
},
|
39
40
|
applyDefaultPatterns: {
|
40
|
-
type: "boolean"
|
41
|
+
type: "boolean",
|
42
|
+
default: true
|
41
43
|
},
|
42
44
|
applyDefaultIgnorePatterns: {
|
43
|
-
type: "boolean"
|
45
|
+
type: "boolean",
|
46
|
+
default: true
|
44
47
|
}
|
45
48
|
},
|
46
49
|
additionalProperties: false
|
47
50
|
}
|
48
51
|
]
|
49
52
|
}
|
50
|
-
]
|
53
|
+
],
|
54
|
+
messages: {
|
55
|
+
above: "Expected comment to be above code.",
|
56
|
+
beside: "Expected comment to be beside code."
|
57
|
+
}
|
51
58
|
},
|
52
59
|
|
53
60
|
create(context) {
|
@@ -65,9 +72,9 @@ module.exports = {
|
|
65
72
|
ignorePattern = options.ignorePattern;
|
66
73
|
|
67
74
|
if (Object.prototype.hasOwnProperty.call(options, "applyDefaultIgnorePatterns")) {
|
68
|
-
applyDefaultIgnorePatterns = options.applyDefaultIgnorePatterns
|
75
|
+
applyDefaultIgnorePatterns = options.applyDefaultIgnorePatterns;
|
69
76
|
} else {
|
70
|
-
applyDefaultIgnorePatterns = options.applyDefaultPatterns
|
77
|
+
applyDefaultIgnorePatterns = options.applyDefaultPatterns;
|
71
78
|
}
|
72
79
|
}
|
73
80
|
|
@@ -100,14 +107,14 @@ module.exports = {
|
|
100
107
|
if (isOnSameLine) {
|
101
108
|
context.report({
|
102
109
|
node,
|
103
|
-
|
110
|
+
messageId: "above"
|
104
111
|
});
|
105
112
|
}
|
106
113
|
} else {
|
107
114
|
if (!isOnSameLine) {
|
108
115
|
context.report({
|
109
116
|
node,
|
110
|
-
|
117
|
+
messageId: "beside"
|
111
118
|
});
|
112
119
|
}
|
113
120
|
}
|
@@ -32,14 +32,14 @@ module.exports = {
|
|
32
32
|
{
|
33
33
|
enum: ["unix", "windows"]
|
34
34
|
}
|
35
|
-
]
|
35
|
+
],
|
36
|
+
messages: {
|
37
|
+
expectedLF: "Expected linebreaks to be 'LF' but found 'CRLF'.",
|
38
|
+
expectedCRLF: "Expected linebreaks to be 'CRLF' but found 'LF'."
|
39
|
+
}
|
36
40
|
},
|
37
41
|
|
38
42
|
create(context) {
|
39
|
-
|
40
|
-
const EXPECTED_LF_MSG = "Expected linebreaks to be 'LF' but found 'CRLF'.",
|
41
|
-
EXPECTED_CRLF_MSG = "Expected linebreaks to be 'CRLF' but found 'LF'.";
|
42
|
-
|
43
43
|
const sourceCode = context.getSourceCode();
|
44
44
|
|
45
45
|
//--------------------------------------------------------------------------
|
@@ -89,7 +89,7 @@ module.exports = {
|
|
89
89
|
line: i,
|
90
90
|
column: sourceCode.lines[i - 1].length
|
91
91
|
},
|
92
|
-
|
92
|
+
messageId: expectedLF ? "expectedLF" : "expectedCRLF",
|
93
93
|
fix: createFix(range, expectedLFChars)
|
94
94
|
});
|
95
95
|
}
|
@@ -68,22 +68,28 @@ module.exports = {
|
|
68
68
|
type: "object",
|
69
69
|
properties: {
|
70
70
|
beforeBlockComment: {
|
71
|
-
type: "boolean"
|
71
|
+
type: "boolean",
|
72
|
+
default: true
|
72
73
|
},
|
73
74
|
afterBlockComment: {
|
74
|
-
type: "boolean"
|
75
|
+
type: "boolean",
|
76
|
+
default: false
|
75
77
|
},
|
76
78
|
beforeLineComment: {
|
77
|
-
type: "boolean"
|
79
|
+
type: "boolean",
|
80
|
+
default: false
|
78
81
|
},
|
79
82
|
afterLineComment: {
|
80
|
-
type: "boolean"
|
83
|
+
type: "boolean",
|
84
|
+
default: false
|
81
85
|
},
|
82
86
|
allowBlockStart: {
|
83
|
-
type: "boolean"
|
87
|
+
type: "boolean",
|
88
|
+
default: false
|
84
89
|
},
|
85
90
|
allowBlockEnd: {
|
86
|
-
type: "boolean"
|
91
|
+
type: "boolean",
|
92
|
+
default: false
|
87
93
|
},
|
88
94
|
allowClassStart: {
|
89
95
|
type: "boolean"
|
@@ -112,24 +118,22 @@ module.exports = {
|
|
112
118
|
},
|
113
119
|
additionalProperties: false
|
114
120
|
}
|
115
|
-
]
|
121
|
+
],
|
122
|
+
messages: {
|
123
|
+
after: "Expected line after comment.",
|
124
|
+
before: "Expected line before comment."
|
125
|
+
}
|
116
126
|
},
|
117
127
|
|
118
128
|
create(context) {
|
119
129
|
|
120
|
-
const options =
|
130
|
+
const options = Object.assign({}, context.options[0]);
|
121
131
|
const ignorePattern = options.ignorePattern;
|
122
132
|
const defaultIgnoreRegExp = astUtils.COMMENTS_IGNORE_PATTERN;
|
123
133
|
const customIgnoreRegExp = new RegExp(ignorePattern);
|
124
134
|
const applyDefaultIgnorePatterns = options.applyDefaultIgnorePatterns !== false;
|
125
135
|
|
126
|
-
|
127
|
-
options.beforeLineComment = options.beforeLineComment || false;
|
128
|
-
options.afterLineComment = options.afterLineComment || false;
|
129
136
|
options.beforeBlockComment = typeof options.beforeBlockComment !== "undefined" ? options.beforeBlockComment : true;
|
130
|
-
options.afterBlockComment = options.afterBlockComment || false;
|
131
|
-
options.allowBlockStart = options.allowBlockStart || false;
|
132
|
-
options.allowBlockEnd = options.allowBlockEnd || false;
|
133
137
|
|
134
138
|
const sourceCode = context.getSourceCode();
|
135
139
|
|
@@ -350,7 +354,7 @@ module.exports = {
|
|
350
354
|
|
351
355
|
context.report({
|
352
356
|
node: token,
|
353
|
-
|
357
|
+
messageId: "before",
|
354
358
|
fix(fixer) {
|
355
359
|
return fixer.insertTextBeforeRange(range, "\n");
|
356
360
|
}
|
@@ -362,7 +366,7 @@ module.exports = {
|
|
362
366
|
!(astUtils.isCommentToken(nextTokenOrComment) && astUtils.isTokenOnSameLine(token, nextTokenOrComment))) {
|
363
367
|
context.report({
|
364
368
|
node: token,
|
365
|
-
|
369
|
+
messageId: "after",
|
366
370
|
fix(fixer) {
|
367
371
|
return fixer.insertTextAfter(token, "\n");
|
368
372
|
}
|
@@ -45,6 +45,10 @@ module.exports = {
|
|
45
45
|
}],
|
46
46
|
|
47
47
|
fixable: "whitespace",
|
48
|
+
messages: {
|
49
|
+
expected: "Expected newline {{location}} \"{{value}}\" directive.",
|
50
|
+
unexpected: "Unexpected newline {{location}} \"{{value}}\" directive."
|
51
|
+
},
|
48
52
|
deprecated: true,
|
49
53
|
replacedBy: ["padding-line-between-statements"]
|
50
54
|
},
|
@@ -109,9 +113,8 @@ module.exports = {
|
|
109
113
|
function reportError(node, location, expected) {
|
110
114
|
context.report({
|
111
115
|
node,
|
112
|
-
|
116
|
+
messageId: expected ? "expected" : "unexpected",
|
113
117
|
data: {
|
114
|
-
expected: expected ? "Expected" : "Unexpected",
|
115
118
|
value: node.expression.value,
|
116
119
|
location
|
117
120
|
},
|
@@ -31,12 +31,17 @@ module.exports = {
|
|
31
31
|
type: "object",
|
32
32
|
properties: {
|
33
33
|
exceptAfterSingleLine: {
|
34
|
-
type: "boolean"
|
34
|
+
type: "boolean",
|
35
|
+
default: false
|
35
36
|
}
|
36
37
|
},
|
37
38
|
additionalProperties: false
|
38
39
|
}
|
39
|
-
]
|
40
|
+
],
|
41
|
+
messages: {
|
42
|
+
never: "Unexpected blank line between class members.",
|
43
|
+
always: "Expected blank line between class members."
|
44
|
+
}
|
40
45
|
},
|
41
46
|
|
42
47
|
create(context) {
|
@@ -46,9 +51,6 @@ module.exports = {
|
|
46
51
|
options[0] = context.options[0] || "always";
|
47
52
|
options[1] = context.options[1] || { exceptAfterSingleLine: false };
|
48
53
|
|
49
|
-
const ALWAYS_MESSAGE = "Expected blank line between class members.";
|
50
|
-
const NEVER_MESSAGE = "Unexpected blank line between class members.";
|
51
|
-
|
52
54
|
const sourceCode = context.getSourceCode();
|
53
55
|
|
54
56
|
/**
|
@@ -127,7 +129,7 @@ module.exports = {
|
|
127
129
|
(options[0] === "never" && isPadded)) {
|
128
130
|
context.report({
|
129
131
|
node: body[i + 1],
|
130
|
-
|
132
|
+
messageId: isPadded ? "never" : "always",
|
131
133
|
fix(fixer) {
|
132
134
|
return isPadded
|
133
135
|
? fixer.replaceTextRange([curLast.range[1], nextFirst.range[0]], "\n")
|
package/lib/rules/max-depth.js
CHANGED
@@ -32,18 +32,23 @@ module.exports = {
|
|
32
32
|
properties: {
|
33
33
|
maximum: {
|
34
34
|
type: "integer",
|
35
|
-
minimum: 0
|
35
|
+
minimum: 0,
|
36
|
+
default: 4
|
36
37
|
},
|
37
38
|
max: {
|
38
39
|
type: "integer",
|
39
|
-
minimum: 0
|
40
|
+
minimum: 0,
|
41
|
+
default: 4
|
40
42
|
}
|
41
43
|
},
|
42
44
|
additionalProperties: false
|
43
45
|
}
|
44
46
|
]
|
45
47
|
}
|
46
|
-
]
|
48
|
+
],
|
49
|
+
messages: {
|
50
|
+
tooDeeply: "Blocks are nested too deeply ({{depth}})."
|
51
|
+
}
|
47
52
|
},
|
48
53
|
|
49
54
|
create(context) {
|
@@ -56,11 +61,8 @@ module.exports = {
|
|
56
61
|
option = context.options[0];
|
57
62
|
let maxDepth = 4;
|
58
63
|
|
59
|
-
if (typeof option === "object"
|
60
|
-
maxDepth = option.maximum;
|
61
|
-
}
|
62
|
-
if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "max") && typeof option.max === "number") {
|
63
|
-
maxDepth = option.max;
|
64
|
+
if (typeof option === "object") {
|
65
|
+
maxDepth = option.maximum || option.max;
|
64
66
|
}
|
65
67
|
if (typeof option === "number") {
|
66
68
|
maxDepth = option;
|
@@ -94,7 +96,7 @@ module.exports = {
|
|
94
96
|
const len = ++functionStack[functionStack.length - 1];
|
95
97
|
|
96
98
|
if (len > maxDepth) {
|
97
|
-
context.report({ node,
|
99
|
+
context.report({ node, messageId: "tooDeeply", data: { depth: len } });
|
98
100
|
}
|
99
101
|
}
|
100
102
|
|
package/lib/rules/max-len.js
CHANGED
@@ -14,7 +14,8 @@ const OPTIONS_SCHEMA = {
|
|
14
14
|
properties: {
|
15
15
|
code: {
|
16
16
|
type: "integer",
|
17
|
-
minimum: 0
|
17
|
+
minimum: 0,
|
18
|
+
default: 80
|
18
19
|
},
|
19
20
|
comments: {
|
20
21
|
type: "integer",
|
@@ -22,28 +23,35 @@ const OPTIONS_SCHEMA = {
|
|
22
23
|
},
|
23
24
|
tabWidth: {
|
24
25
|
type: "integer",
|
25
|
-
minimum: 0
|
26
|
+
minimum: 0,
|
27
|
+
default: 4
|
26
28
|
},
|
27
29
|
ignorePattern: {
|
28
30
|
type: "string"
|
29
31
|
},
|
30
32
|
ignoreComments: {
|
31
|
-
type: "boolean"
|
33
|
+
type: "boolean",
|
34
|
+
default: false
|
32
35
|
},
|
33
36
|
ignoreStrings: {
|
34
|
-
type: "boolean"
|
37
|
+
type: "boolean",
|
38
|
+
default: false
|
35
39
|
},
|
36
40
|
ignoreUrls: {
|
37
|
-
type: "boolean"
|
41
|
+
type: "boolean",
|
42
|
+
default: false
|
38
43
|
},
|
39
44
|
ignoreTemplateLiterals: {
|
40
|
-
type: "boolean"
|
45
|
+
type: "boolean",
|
46
|
+
default: false
|
41
47
|
},
|
42
48
|
ignoreRegExpLiterals: {
|
43
|
-
type: "boolean"
|
49
|
+
type: "boolean",
|
50
|
+
default: false
|
44
51
|
},
|
45
52
|
ignoreTrailingComments: {
|
46
|
-
type: "boolean"
|
53
|
+
type: "boolean",
|
54
|
+
default: false
|
47
55
|
}
|
48
56
|
},
|
49
57
|
additionalProperties: false
|
@@ -78,7 +86,11 @@ module.exports = {
|
|
78
86
|
OPTIONS_OR_INTEGER_SCHEMA,
|
79
87
|
OPTIONS_OR_INTEGER_SCHEMA,
|
80
88
|
OPTIONS_SCHEMA
|
81
|
-
]
|
89
|
+
],
|
90
|
+
messages: {
|
91
|
+
max: "Line {{lineNumber}} exceeds the maximum line length of {{maxLength}}.",
|
92
|
+
maxComment: "Line {{lineNumber}} exceeds the maximum comment line length of {{maxCommentLength}}."
|
93
|
+
}
|
82
94
|
},
|
83
95
|
|
84
96
|
create(context) {
|
@@ -117,8 +129,7 @@ module.exports = {
|
|
117
129
|
}
|
118
130
|
|
119
131
|
// The options object must be the last option specified…
|
120
|
-
const
|
121
|
-
const options = typeof lastOption === "object" ? Object.create(lastOption) : {};
|
132
|
+
const options = Object.assign({}, context.options[context.options.length - 1]);
|
122
133
|
|
123
134
|
// …but max code length…
|
124
135
|
if (typeof context.options[0] === "number") {
|
@@ -341,7 +352,7 @@ module.exports = {
|
|
341
352
|
context.report({
|
342
353
|
node,
|
343
354
|
loc: { line: lineNumber, column: 0 },
|
344
|
-
|
355
|
+
messageId: "maxComment",
|
345
356
|
data: {
|
346
357
|
lineNumber: i + 1,
|
347
358
|
maxCommentLength
|
@@ -352,7 +363,7 @@ module.exports = {
|
|
352
363
|
context.report({
|
353
364
|
node,
|
354
365
|
loc: { line: lineNumber, column: 0 },
|
355
|
-
|
366
|
+
messageId: "max",
|
356
367
|
data: {
|
357
368
|
lineNumber: i + 1,
|
358
369
|
maxLength
|
@@ -19,16 +19,20 @@ const OPTIONS_SCHEMA = {
|
|
19
19
|
properties: {
|
20
20
|
max: {
|
21
21
|
type: "integer",
|
22
|
-
minimum: 0
|
22
|
+
minimum: 0,
|
23
|
+
default: 50
|
23
24
|
},
|
24
25
|
skipComments: {
|
25
|
-
type: "boolean"
|
26
|
+
type: "boolean",
|
27
|
+
default: false
|
26
28
|
},
|
27
29
|
skipBlankLines: {
|
28
|
-
type: "boolean"
|
30
|
+
type: "boolean",
|
31
|
+
default: false
|
29
32
|
},
|
30
33
|
IIFEs: {
|
31
|
-
type: "boolean"
|
34
|
+
type: "boolean",
|
35
|
+
default: false
|
32
36
|
}
|
33
37
|
},
|
34
38
|
additionalProperties: false
|
@@ -80,7 +84,10 @@ module.exports = {
|
|
80
84
|
|
81
85
|
schema: [
|
82
86
|
OPTIONS_OR_INTEGER_SCHEMA
|
83
|
-
]
|
87
|
+
],
|
88
|
+
messages: {
|
89
|
+
exceed: "{{name}} has too many lines ({{lineCount}}). Maximum allowed is {{maxLines}}."
|
90
|
+
}
|
84
91
|
},
|
85
92
|
|
86
93
|
create(context) {
|
@@ -94,18 +101,10 @@ module.exports = {
|
|
94
101
|
let IIFEs = false;
|
95
102
|
|
96
103
|
if (typeof option === "object") {
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
skipComments = option.skipComments;
|
102
|
-
}
|
103
|
-
if (typeof option.skipBlankLines === "boolean") {
|
104
|
-
skipBlankLines = option.skipBlankLines;
|
105
|
-
}
|
106
|
-
if (typeof option.IIFEs === "boolean") {
|
107
|
-
IIFEs = option.IIFEs;
|
108
|
-
}
|
104
|
+
maxLines = option.max;
|
105
|
+
skipComments = option.skipComments;
|
106
|
+
skipBlankLines = option.skipBlankLines;
|
107
|
+
IIFEs = option.IIFEs;
|
109
108
|
} else if (typeof option === "number") {
|
110
109
|
maxLines = option;
|
111
110
|
}
|
@@ -201,7 +200,7 @@ module.exports = {
|
|
201
200
|
|
202
201
|
context.report({
|
203
202
|
node,
|
204
|
-
|
203
|
+
messageId: "exceed",
|
205
204
|
data: { name, lineCount, maxLines }
|
206
205
|
});
|
207
206
|
}
|
package/lib/rules/max-lines.js
CHANGED
@@ -38,31 +38,35 @@ module.exports = {
|
|
38
38
|
properties: {
|
39
39
|
max: {
|
40
40
|
type: "integer",
|
41
|
-
minimum: 0
|
41
|
+
minimum: 0,
|
42
|
+
default: 300
|
42
43
|
},
|
43
44
|
skipComments: {
|
44
|
-
type: "boolean"
|
45
|
+
type: "boolean",
|
46
|
+
default: false
|
45
47
|
},
|
46
48
|
skipBlankLines: {
|
47
|
-
type: "boolean"
|
49
|
+
type: "boolean",
|
50
|
+
default: false
|
48
51
|
}
|
49
52
|
},
|
50
53
|
additionalProperties: false
|
51
54
|
}
|
52
55
|
]
|
53
56
|
}
|
54
|
-
]
|
57
|
+
],
|
58
|
+
messages: {
|
59
|
+
exceed: "File must be at most {{max}} lines long. It's {{actual}} lines long."
|
60
|
+
}
|
55
61
|
},
|
56
62
|
|
57
63
|
create(context) {
|
58
64
|
const option = context.options[0];
|
59
65
|
let max = 300;
|
60
66
|
|
61
|
-
if (typeof option === "object"
|
67
|
+
if (typeof option === "object") {
|
62
68
|
max = option.max;
|
63
|
-
}
|
64
|
-
|
65
|
-
if (typeof option === "number") {
|
69
|
+
} else if (typeof option === "number") {
|
66
70
|
max = option;
|
67
71
|
}
|
68
72
|
|
@@ -83,7 +87,7 @@ module.exports = {
|
|
83
87
|
/**
|
84
88
|
* Returns the line numbers of a comment that don't have any code on the same line
|
85
89
|
* @param {Node} comment The comment node to check
|
86
|
-
* @returns {
|
90
|
+
* @returns {number[]} The line numbers
|
87
91
|
*/
|
88
92
|
function getLinesWithoutCode(comment) {
|
89
93
|
let start = comment.loc.start.line;
|
@@ -134,7 +138,7 @@ module.exports = {
|
|
134
138
|
if (lines.length > max) {
|
135
139
|
context.report({
|
136
140
|
loc: { line: 1, column: 0 },
|
137
|
-
|
141
|
+
messageId: "exceed",
|
138
142
|
data: {
|
139
143
|
max,
|
140
144
|
actual: lines.length
|
@@ -32,18 +32,23 @@ module.exports = {
|
|
32
32
|
properties: {
|
33
33
|
maximum: {
|
34
34
|
type: "integer",
|
35
|
-
minimum: 0
|
35
|
+
minimum: 0,
|
36
|
+
default: 10
|
36
37
|
},
|
37
38
|
max: {
|
38
39
|
type: "integer",
|
39
|
-
minimum: 0
|
40
|
+
minimum: 0,
|
41
|
+
default: 10
|
40
42
|
}
|
41
43
|
},
|
42
44
|
additionalProperties: false
|
43
45
|
}
|
44
46
|
]
|
45
47
|
}
|
46
|
-
]
|
48
|
+
],
|
49
|
+
messages: {
|
50
|
+
exceed: "Too many nested callbacks ({{num}}). Maximum allowed is {{max}}."
|
51
|
+
}
|
47
52
|
},
|
48
53
|
|
49
54
|
create(context) {
|
@@ -54,13 +59,9 @@ module.exports = {
|
|
54
59
|
const option = context.options[0];
|
55
60
|
let THRESHOLD = 10;
|
56
61
|
|
57
|
-
if (typeof option === "object"
|
58
|
-
THRESHOLD = option.maximum;
|
59
|
-
}
|
60
|
-
if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "max") && typeof option.max === "number") {
|
61
|
-
THRESHOLD = option.max;
|
62
|
-
}
|
63
|
-
if (typeof option === "number") {
|
62
|
+
if (typeof option === "object") {
|
63
|
+
THRESHOLD = option.maximum || option.max;
|
64
|
+
} else if (typeof option === "number") {
|
64
65
|
THRESHOLD = option;
|
65
66
|
}
|
66
67
|
|
@@ -86,7 +87,7 @@ module.exports = {
|
|
86
87
|
if (callbackStack.length > THRESHOLD) {
|
87
88
|
const opts = { num: callbackStack.length, max: THRESHOLD };
|
88
89
|
|
89
|
-
context.report({ node,
|
90
|
+
context.report({ node, messageId: "exceed", data: opts });
|
90
91
|
}
|
91
92
|
}
|
92
93
|
|
package/lib/rules/max-params.js
CHANGED
@@ -40,18 +40,23 @@ module.exports = {
|
|
40
40
|
properties: {
|
41
41
|
maximum: {
|
42
42
|
type: "integer",
|
43
|
-
minimum: 0
|
43
|
+
minimum: 0,
|
44
|
+
default: 3
|
44
45
|
},
|
45
46
|
max: {
|
46
47
|
type: "integer",
|
47
|
-
minimum: 0
|
48
|
+
minimum: 0,
|
49
|
+
default: 3
|
48
50
|
}
|
49
51
|
},
|
50
52
|
additionalProperties: false
|
51
53
|
}
|
52
54
|
]
|
53
55
|
}
|
54
|
-
]
|
56
|
+
],
|
57
|
+
messages: {
|
58
|
+
exceed: "{{name}} has too many parameters ({{count}}). Maximum allowed is {{max}}."
|
59
|
+
}
|
55
60
|
},
|
56
61
|
|
57
62
|
create(context) {
|
@@ -59,11 +64,8 @@ module.exports = {
|
|
59
64
|
const option = context.options[0];
|
60
65
|
let numParams = 3;
|
61
66
|
|
62
|
-
if (typeof option === "object"
|
63
|
-
numParams = option.maximum;
|
64
|
-
}
|
65
|
-
if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "max") && typeof option.max === "number") {
|
66
|
-
numParams = option.max;
|
67
|
+
if (typeof option === "object") {
|
68
|
+
numParams = option.maximum || option.max;
|
67
69
|
}
|
68
70
|
if (typeof option === "number") {
|
69
71
|
numParams = option;
|
@@ -80,7 +82,7 @@ module.exports = {
|
|
80
82
|
context.report({
|
81
83
|
loc: astUtils.getFunctionHeadLoc(node, sourceCode),
|
82
84
|
node,
|
83
|
-
|
85
|
+
messageId: "exceed",
|
84
86
|
data: {
|
85
87
|
name: lodash.upperFirst(astUtils.getFunctionNameWithKind(node)),
|
86
88
|
count: node.params.length,
|
@@ -31,20 +31,23 @@ module.exports = {
|
|
31
31
|
properties: {
|
32
32
|
max: {
|
33
33
|
type: "integer",
|
34
|
-
minimum: 1
|
34
|
+
minimum: 1,
|
35
|
+
default: 1
|
35
36
|
}
|
36
37
|
},
|
37
38
|
additionalProperties: false
|
38
39
|
}
|
39
|
-
]
|
40
|
+
],
|
41
|
+
messages: {
|
42
|
+
exceed: "This line has {{numberOfStatementsOnThisLine}} {{statements}}. Maximum allowed is {{maxStatementsPerLine}}."
|
43
|
+
}
|
40
44
|
},
|
41
45
|
|
42
46
|
create(context) {
|
43
47
|
|
44
48
|
const sourceCode = context.getSourceCode(),
|
45
49
|
options = context.options[0] || {},
|
46
|
-
maxStatementsPerLine = typeof options.max !== "undefined" ? options.max : 1
|
47
|
-
message = "This line has {{numberOfStatementsOnThisLine}} {{statements}}. Maximum allowed is {{maxStatementsPerLine}}.";
|
50
|
+
maxStatementsPerLine = typeof options.max !== "undefined" ? options.max : 1;
|
48
51
|
|
49
52
|
let lastStatementLine = 0,
|
50
53
|
numberOfStatementsOnThisLine = 0,
|
@@ -65,7 +68,7 @@ module.exports = {
|
|
65
68
|
if (firstExtraStatement) {
|
66
69
|
context.report({
|
67
70
|
node: firstExtraStatement,
|
68
|
-
|
71
|
+
messageId: "exceed",
|
69
72
|
data: {
|
70
73
|
numberOfStatementsOnThisLine,
|
71
74
|
maxStatementsPerLine,
|