eslint 5.2.0 → 5.6.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 +63 -0
- package/conf/eslint-recommended.js +4 -0
- package/lib/cli-engine.js +13 -14
- package/lib/code-path-analysis/code-path-analyzer.js +1 -1
- package/lib/config/config-initializer.js +7 -7
- package/lib/config.js +1 -1
- package/lib/formatters/codeframe.js +2 -2
- package/lib/ignored-paths.js +125 -37
- package/lib/linter.js +1 -1
- package/lib/rules/array-bracket-newline.js +1 -1
- package/lib/rules/array-bracket-spacing.js +1 -1
- package/lib/rules/array-callback-return.js +1 -1
- package/lib/rules/array-element-newline.js +1 -1
- package/lib/rules/arrow-body-style.js +1 -1
- package/lib/rules/arrow-parens.js +1 -1
- package/lib/rules/arrow-spacing.js +1 -1
- package/lib/rules/block-spacing.js +1 -1
- package/lib/rules/brace-style.js +1 -1
- package/lib/rules/camelcase.js +1 -1
- package/lib/rules/capitalized-comments.js +1 -1
- package/lib/rules/comma-dangle.js +1 -1
- package/lib/rules/comma-spacing.js +1 -1
- package/lib/rules/comma-style.js +2 -2
- package/lib/rules/complexity.js +3 -3
- package/lib/rules/computed-property-spacing.js +1 -1
- package/lib/rules/consistent-return.js +1 -1
- package/lib/rules/curly.js +1 -1
- package/lib/rules/dot-location.js +1 -1
- package/lib/rules/dot-notation.js +1 -1
- package/lib/rules/eqeqeq.js +1 -1
- package/lib/rules/for-direction.js +5 -2
- package/lib/rules/func-call-spacing.js +8 -4
- package/lib/rules/func-name-matching.js +13 -7
- package/lib/rules/func-names.js +82 -21
- package/lib/rules/func-style.js +8 -4
- package/lib/rules/function-paren-newline.js +12 -6
- package/lib/rules/generator-star-spacing.js +18 -9
- package/lib/rules/getter-return.js +8 -6
- package/lib/rules/indent-legacy.js +1 -1
- package/lib/rules/indent.js +43 -7
- package/lib/rules/jsx-quotes.js +1 -1
- package/lib/rules/key-spacing.js +2 -2
- package/lib/rules/keyword-spacing.js +1 -1
- package/lib/rules/line-comment-position.js +3 -3
- package/lib/rules/linebreak-style.js +1 -1
- package/lib/rules/lines-around-comment.js +1 -1
- package/lib/rules/lines-around-directive.js +1 -1
- package/lib/rules/lines-between-class-members.js +1 -1
- package/lib/rules/max-depth.js +2 -2
- package/lib/rules/max-len.js +1 -1
- package/lib/rules/max-lines-per-function.js +1 -1
- package/lib/rules/max-lines.js +2 -2
- package/lib/rules/max-nested-callbacks.js +2 -2
- package/lib/rules/max-params.js +5 -4
- package/lib/rules/max-statements-per-line.js +1 -1
- package/lib/rules/max-statements.js +3 -3
- package/lib/rules/multiline-comment-style.js +1 -1
- package/lib/rules/multiline-ternary.js +1 -1
- package/lib/rules/new-parens.js +1 -1
- package/lib/rules/newline-after-var.js +1 -1
- package/lib/rules/newline-per-chained-call.js +1 -1
- package/lib/rules/no-alert.js +1 -1
- package/lib/rules/no-async-promise-executor.js +33 -0
- package/lib/rules/no-catch-shadow.js +1 -1
- package/lib/rules/no-class-assign.js +1 -1
- package/lib/rules/no-cond-assign.js +1 -1
- package/lib/rules/no-confusing-arrow.js +1 -1
- package/lib/rules/no-console.js +1 -1
- package/lib/rules/no-const-assign.js +1 -1
- package/lib/rules/no-constant-condition.js +2 -0
- package/lib/rules/no-dupe-keys.js +1 -1
- package/lib/rules/no-else-return.js +1 -1
- package/lib/rules/no-empty-function.js +1 -1
- package/lib/rules/no-empty.js +1 -1
- package/lib/rules/no-eval.js +1 -1
- package/lib/rules/no-ex-assign.js +1 -1
- package/lib/rules/no-extend-native.js +1 -1
- package/lib/rules/no-extra-bind.js +1 -1
- package/lib/rules/no-extra-boolean-cast.js +1 -1
- package/lib/rules/no-extra-label.js +1 -1
- package/lib/rules/no-extra-parens.js +2 -2
- package/lib/rules/no-extra-semi.js +1 -1
- package/lib/rules/no-floating-decimal.js +1 -1
- package/lib/rules/no-func-assign.js +1 -1
- package/lib/rules/no-implicit-coercion.js +1 -1
- package/lib/rules/no-inline-comments.js +1 -1
- package/lib/rules/no-invalid-this.js +1 -1
- package/lib/rules/no-irregular-whitespace.js +1 -1
- package/lib/rules/no-label-var.js +1 -1
- package/lib/rules/no-labels.js +1 -1
- package/lib/rules/no-magic-numbers.js +7 -3
- package/lib/rules/no-misleading-character-class.js +189 -0
- package/lib/rules/no-mixed-operators.js +1 -1
- package/lib/rules/no-multi-spaces.js +1 -1
- package/lib/rules/no-multi-str.js +1 -1
- package/lib/rules/no-regex-spaces.js +1 -1
- package/lib/rules/no-restricted-globals.js +1 -1
- package/lib/rules/no-restricted-imports.js +1 -1
- package/lib/rules/no-restricted-modules.js +1 -1
- package/lib/rules/no-restricted-properties.js +1 -1
- package/lib/rules/no-return-assign.js +1 -1
- package/lib/rules/no-return-await.js +1 -1
- package/lib/rules/no-self-assign.js +1 -1
- package/lib/rules/no-sequences.js +1 -1
- package/lib/rules/no-shadow.js +1 -1
- package/lib/rules/no-this-before-super.js +1 -1
- package/lib/rules/no-throw-literal.js +1 -1
- package/lib/rules/no-trailing-spaces.js +1 -1
- package/lib/rules/no-undef-init.js +1 -1
- package/lib/rules/no-unexpected-multiline.js +1 -1
- package/lib/rules/no-unmodified-loop-condition.js +2 -3
- package/lib/rules/no-unneeded-ternary.js +1 -1
- package/lib/rules/no-unsafe-negation.js +1 -1
- package/lib/rules/no-unused-vars.js +1 -1
- package/lib/rules/no-useless-call.js +1 -1
- package/lib/rules/no-useless-computed-key.js +1 -1
- package/lib/rules/no-useless-concat.js +1 -1
- package/lib/rules/no-useless-escape.js +1 -1
- package/lib/rules/no-useless-return.js +2 -11
- package/lib/rules/no-var.js +1 -1
- package/lib/rules/no-warning-comments.js +1 -1
- package/lib/rules/no-whitespace-before-property.js +1 -1
- package/lib/rules/object-curly-newline.js +1 -1
- package/lib/rules/object-curly-spacing.js +1 -1
- package/lib/rules/object-shorthand.js +1 -1
- package/lib/rules/one-var.js +6 -6
- package/lib/rules/operator-assignment.js +1 -1
- package/lib/rules/operator-linebreak.js +1 -1
- package/lib/rules/padded-blocks.js +6 -6
- package/lib/rules/padding-line-between-statements.js +2 -2
- package/lib/rules/prefer-const.js +2 -11
- package/lib/rules/prefer-object-spread.js +9 -3
- package/lib/rules/prefer-promise-reject-errors.js +1 -1
- package/lib/rules/prefer-reflect.js +1 -1
- package/lib/rules/prefer-spread.js +1 -1
- package/lib/rules/prefer-template.js +1 -1
- package/lib/rules/quotes.js +1 -1
- package/lib/rules/radix.js +1 -1
- package/lib/rules/require-atomic-updates.js +239 -0
- package/lib/rules/require-await.js +1 -1
- package/lib/rules/require-unicode-regexp.js +65 -0
- package/lib/rules/semi-spacing.js +3 -3
- package/lib/rules/semi-style.js +1 -1
- package/lib/rules/semi.js +1 -1
- package/lib/rules/sort-keys.js +1 -1
- package/lib/rules/space-before-blocks.js +1 -1
- package/lib/rules/space-before-function-paren.js +1 -1
- package/lib/rules/space-in-parens.js +1 -1
- package/lib/rules/space-unary-ops.js +2 -2
- package/lib/rules/spaced-comment.js +1 -1
- package/lib/rules/strict.js +1 -1
- package/lib/rules/switch-colon-spacing.js +1 -1
- package/lib/rules/symbol-description.js +1 -1
- package/lib/rules/template-curly-spacing.js +1 -1
- package/lib/rules/valid-jsdoc.js +1 -1
- package/lib/rules/wrap-iife.js +1 -1
- package/lib/rules/yoda.js +1 -1
- package/lib/testers/rule-tester.js +7 -7
- package/lib/token-store/index.js +1 -1
- package/lib/{ast-utils.js → util/ast-utils.js} +0 -0
- package/lib/{file-finder.js → util/file-finder.js} +2 -2
- package/lib/util/fix-tracker.js +1 -1
- package/lib/util/{glob-util.js → glob-utils.js} +4 -4
- package/lib/util/lint-result-cache.js +2 -2
- package/lib/util/naming.js +2 -2
- package/lib/util/node-event-generator.js +3 -3
- package/lib/util/{npm-util.js → npm-utils.js} +0 -0
- package/lib/util/{path-util.js → path-utils.js} +1 -1
- package/lib/util/source-code-fixer.js +1 -1
- package/lib/util/{source-code-util.js → source-code-utils.js} +3 -3
- package/lib/util/source-code.js +1 -1
- package/lib/util/unicode/index.js +11 -0
- package/lib/util/unicode/is-combining-character.js +13 -0
- package/lib/util/unicode/is-emoji-modifier.js +13 -0
- package/lib/util/unicode/is-regional-indicator-symbol.js +13 -0
- package/lib/util/unicode/is-surrogate-pair.js +14 -0
- package/package.json +13 -14
- package/lib/rules/.eslintrc.yml +0 -4
@@ -10,7 +10,7 @@
|
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
12
|
const lodash = require("lodash");
|
13
|
-
const astUtils = require("../ast-utils");
|
13
|
+
const astUtils = require("../util/ast-utils");
|
14
14
|
|
15
15
|
//------------------------------------------------------------------------------
|
16
16
|
// Helpers
|
package/lib/rules/comma-style.js
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
-
const astUtils = require("../ast-utils");
|
8
|
+
const astUtils = require("../util/ast-utils");
|
9
9
|
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
// Rule Definition
|
@@ -58,7 +58,7 @@ module.exports = {
|
|
58
58
|
NewExpression: true
|
59
59
|
};
|
60
60
|
|
61
|
-
if (context.options.length === 2 && context.options[1]
|
61
|
+
if (context.options.length === 2 && Object.prototype.hasOwnProperty.call(context.options[1], "exceptions")) {
|
62
62
|
const keys = Object.keys(context.options[1].exceptions);
|
63
63
|
|
64
64
|
for (let i = 0; i < keys.length; i++) {
|
package/lib/rules/complexity.js
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
|
13
13
|
const lodash = require("lodash");
|
14
14
|
|
15
|
-
const astUtils = require("../ast-utils");
|
15
|
+
const astUtils = require("../util/ast-utils");
|
16
16
|
|
17
17
|
//------------------------------------------------------------------------------
|
18
18
|
// Rule Definition
|
@@ -61,10 +61,10 @@ module.exports = {
|
|
61
61
|
const option = context.options[0];
|
62
62
|
let THRESHOLD = 20;
|
63
63
|
|
64
|
-
if (typeof option === "object" &&
|
64
|
+
if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "maximum") && typeof option.maximum === "number") {
|
65
65
|
THRESHOLD = option.maximum;
|
66
66
|
}
|
67
|
-
if (typeof option === "object" &&
|
67
|
+
if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "max") && typeof option.max === "number") {
|
68
68
|
THRESHOLD = option.max;
|
69
69
|
}
|
70
70
|
if (typeof option === "number") {
|
package/lib/rules/curly.js
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
// Requirements
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const astUtils = require("../ast-utils");
|
11
|
+
const astUtils = require("../util/ast-utils");
|
12
12
|
|
13
13
|
//------------------------------------------------------------------------------
|
14
14
|
// Rule Definition
|
@@ -8,7 +8,7 @@
|
|
8
8
|
// Requirements
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const astUtils = require("../ast-utils");
|
11
|
+
const astUtils = require("../util/ast-utils");
|
12
12
|
|
13
13
|
//------------------------------------------------------------------------------
|
14
14
|
// Rule Definition
|
package/lib/rules/eqeqeq.js
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("../ast-utils");
|
12
|
+
const astUtils = require("../util/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Rule Definition
|
@@ -18,7 +18,10 @@ module.exports = {
|
|
18
18
|
url: "https://eslint.org/docs/rules/for-direction"
|
19
19
|
},
|
20
20
|
fixable: null,
|
21
|
-
schema: []
|
21
|
+
schema: [],
|
22
|
+
messages: {
|
23
|
+
incorrectDirection: "The update clause in this loop moves the variable in the wrong direction."
|
24
|
+
}
|
22
25
|
},
|
23
26
|
|
24
27
|
create(context) {
|
@@ -31,7 +34,7 @@ module.exports = {
|
|
31
34
|
function report(node) {
|
32
35
|
context.report({
|
33
36
|
node,
|
34
|
-
|
37
|
+
messageId: "incorrectDirection"
|
35
38
|
});
|
36
39
|
}
|
37
40
|
|
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("../ast-utils");
|
12
|
+
const astUtils = require("../util/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Rule Definition
|
@@ -57,6 +57,10 @@ module.exports = {
|
|
57
57
|
maxItems: 2
|
58
58
|
}
|
59
59
|
]
|
60
|
+
},
|
61
|
+
messages: {
|
62
|
+
unexpected: "Unexpected newline between function name and paren.",
|
63
|
+
missing: "Missing space between function name and paren."
|
60
64
|
}
|
61
65
|
},
|
62
66
|
|
@@ -116,7 +120,7 @@ module.exports = {
|
|
116
120
|
context.report({
|
117
121
|
node,
|
118
122
|
loc: lastCalleeToken.loc.start,
|
119
|
-
|
123
|
+
messageId: "unexpected",
|
120
124
|
fix(fixer) {
|
121
125
|
|
122
126
|
/*
|
@@ -134,7 +138,7 @@ module.exports = {
|
|
134
138
|
context.report({
|
135
139
|
node,
|
136
140
|
loc: lastCalleeToken.loc.start,
|
137
|
-
|
141
|
+
messageId: "missing",
|
138
142
|
fix(fixer) {
|
139
143
|
return fixer.insertTextBefore(parenToken, " ");
|
140
144
|
}
|
@@ -143,7 +147,7 @@ module.exports = {
|
|
143
147
|
context.report({
|
144
148
|
node,
|
145
149
|
loc: lastCalleeToken.loc.start,
|
146
|
-
|
150
|
+
messageId: "unexpected",
|
147
151
|
fix(fixer) {
|
148
152
|
return fixer.replaceTextRange([prevToken.range[1], parenToken.range[0]], " ");
|
149
153
|
}
|
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//--------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("../ast-utils");
|
12
|
+
const astUtils = require("../util/ast-utils");
|
13
13
|
const esutils = require("esutils");
|
14
14
|
|
15
15
|
//--------------------------------------------------------------------------
|
@@ -87,6 +87,12 @@ module.exports = {
|
|
87
87
|
additionalItems: false,
|
88
88
|
items: [optionsObject]
|
89
89
|
}]
|
90
|
+
},
|
91
|
+
messages: {
|
92
|
+
matchProperty: "Function name `{{funcName}}` should match property name `{{name}}`",
|
93
|
+
matchVariable: "Function name `{{funcName}}` should match variable name `{{name}}`",
|
94
|
+
notMatchProperty: "Function name `{{funcName}}` should not match property name `{{name}}`",
|
95
|
+
notMatchVariable: "Function name `{{funcName}}` should not match variable name `{{name}}`"
|
90
96
|
}
|
91
97
|
},
|
92
98
|
|
@@ -132,20 +138,20 @@ module.exports = {
|
|
132
138
|
* @returns {void}
|
133
139
|
*/
|
134
140
|
function report(node, name, funcName, isProp) {
|
135
|
-
let
|
141
|
+
let messageId;
|
136
142
|
|
137
143
|
if (nameMatches === "always" && isProp) {
|
138
|
-
|
144
|
+
messageId = "matchProperty";
|
139
145
|
} else if (nameMatches === "always") {
|
140
|
-
|
146
|
+
messageId = "matchVariable";
|
141
147
|
} else if (isProp) {
|
142
|
-
|
148
|
+
messageId = "notMatchProperty";
|
143
149
|
} else {
|
144
|
-
|
150
|
+
messageId = "notMatchVariable";
|
145
151
|
}
|
146
152
|
context.report({
|
147
153
|
node,
|
148
|
-
|
154
|
+
messageId,
|
149
155
|
data: {
|
150
156
|
name,
|
151
157
|
funcName
|
package/lib/rules/func-names.js
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("../ast-utils");
|
12
|
+
const astUtils = require("../util/ast-utils");
|
13
13
|
|
14
14
|
/**
|
15
15
|
* Checks whether or not a given variable is a function name.
|
@@ -33,16 +33,55 @@ module.exports = {
|
|
33
33
|
url: "https://eslint.org/docs/rules/func-names"
|
34
34
|
},
|
35
35
|
|
36
|
-
schema:
|
37
|
-
{
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
schema: {
|
37
|
+
definitions: {
|
38
|
+
value: {
|
39
|
+
enum: [
|
40
|
+
"always",
|
41
|
+
"as-needed",
|
42
|
+
"never"
|
43
|
+
]
|
44
|
+
}
|
45
|
+
},
|
46
|
+
items: [
|
47
|
+
{
|
48
|
+
$ref: "#/definitions/value"
|
49
|
+
},
|
50
|
+
{
|
51
|
+
type: "object",
|
52
|
+
properties: {
|
53
|
+
generators: {
|
54
|
+
$ref: "#/definitions/value"
|
55
|
+
}
|
56
|
+
},
|
57
|
+
additionalProperties: false
|
58
|
+
}
|
59
|
+
]
|
60
|
+
},
|
61
|
+
messages: {
|
62
|
+
unnamed: "Unexpected unnamed {{name}}.",
|
63
|
+
named: "Unexpected named {{name}}."
|
64
|
+
}
|
41
65
|
},
|
42
66
|
|
43
67
|
create(context) {
|
44
|
-
|
45
|
-
|
68
|
+
|
69
|
+
/**
|
70
|
+
* Returns the config option for the given node.
|
71
|
+
* @param {ASTNode} node - A node to get the config for.
|
72
|
+
* @returns {string} The config option.
|
73
|
+
*/
|
74
|
+
function getConfigForNode(node) {
|
75
|
+
if (
|
76
|
+
node.generator &&
|
77
|
+
context.options.length > 1 &&
|
78
|
+
context.options[1].generators
|
79
|
+
) {
|
80
|
+
return context.options[1].generators;
|
81
|
+
}
|
82
|
+
|
83
|
+
return context.options[0] || "always";
|
84
|
+
}
|
46
85
|
|
47
86
|
/**
|
48
87
|
* Determines whether the current FunctionExpression node is a get, set, or
|
@@ -79,6 +118,32 @@ module.exports = {
|
|
79
118
|
(parent.type === "AssignmentPattern" && parent.right === node);
|
80
119
|
}
|
81
120
|
|
121
|
+
/**
|
122
|
+
* Reports that an unnamed function should be named
|
123
|
+
* @param {ASTNode} node - The node to report in the event of an error.
|
124
|
+
* @returns {void}
|
125
|
+
*/
|
126
|
+
function reportUnexpectedUnnamedFunction(node) {
|
127
|
+
context.report({
|
128
|
+
node,
|
129
|
+
messageId: "unnamed",
|
130
|
+
data: { name: astUtils.getFunctionNameWithKind(node) }
|
131
|
+
});
|
132
|
+
}
|
133
|
+
|
134
|
+
/**
|
135
|
+
* Reports that a named function should be unnamed
|
136
|
+
* @param {ASTNode} node - The node to report in the event of an error.
|
137
|
+
* @returns {void}
|
138
|
+
*/
|
139
|
+
function reportUnexpectedNamedFunction(node) {
|
140
|
+
context.report({
|
141
|
+
node,
|
142
|
+
messageId: "named",
|
143
|
+
data: { name: astUtils.getFunctionNameWithKind(node) }
|
144
|
+
});
|
145
|
+
}
|
146
|
+
|
82
147
|
return {
|
83
148
|
"FunctionExpression:exit"(node) {
|
84
149
|
|
@@ -90,23 +155,19 @@ module.exports = {
|
|
90
155
|
}
|
91
156
|
|
92
157
|
const hasName = Boolean(node.id && node.id.name);
|
93
|
-
const
|
158
|
+
const config = getConfigForNode(node);
|
94
159
|
|
95
|
-
if (never) {
|
160
|
+
if (config === "never") {
|
96
161
|
if (hasName) {
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
162
|
+
reportUnexpectedNamedFunction(node);
|
163
|
+
}
|
164
|
+
} else if (config === "as-needed") {
|
165
|
+
if (!hasName && !hasInferredName(node)) {
|
166
|
+
reportUnexpectedUnnamedFunction(node);
|
102
167
|
}
|
103
168
|
} else {
|
104
|
-
if (!hasName &&
|
105
|
-
|
106
|
-
node,
|
107
|
-
message: "Unexpected unnamed {{name}}.",
|
108
|
-
data: { name }
|
109
|
-
});
|
169
|
+
if (!hasName && !isObjectOrClassMethod(node)) {
|
170
|
+
reportUnexpectedUnnamedFunction(node);
|
110
171
|
}
|
111
172
|
}
|
112
173
|
}
|
package/lib/rules/func-style.js
CHANGED
@@ -30,7 +30,11 @@ module.exports = {
|
|
30
30
|
},
|
31
31
|
additionalProperties: false
|
32
32
|
}
|
33
|
-
]
|
33
|
+
],
|
34
|
+
messages: {
|
35
|
+
expression: "Expected a function expression.",
|
36
|
+
declaration: "Expected a function declaration."
|
37
|
+
}
|
34
38
|
},
|
35
39
|
|
36
40
|
create(context) {
|
@@ -45,7 +49,7 @@ module.exports = {
|
|
45
49
|
stack.push(false);
|
46
50
|
|
47
51
|
if (!enforceDeclarations && node.parent.type !== "ExportDefaultDeclaration") {
|
48
|
-
context.report({ node,
|
52
|
+
context.report({ node, messageId: "expression" });
|
49
53
|
}
|
50
54
|
},
|
51
55
|
"FunctionDeclaration:exit"() {
|
@@ -56,7 +60,7 @@ module.exports = {
|
|
56
60
|
stack.push(false);
|
57
61
|
|
58
62
|
if (enforceDeclarations && node.parent.type === "VariableDeclarator") {
|
59
|
-
context.report({ node: node.parent,
|
63
|
+
context.report({ node: node.parent, messageId: "declaration" });
|
60
64
|
}
|
61
65
|
},
|
62
66
|
"FunctionExpression:exit"() {
|
@@ -79,7 +83,7 @@ module.exports = {
|
|
79
83
|
const hasThisExpr = stack.pop();
|
80
84
|
|
81
85
|
if (enforceDeclarations && !hasThisExpr && node.parent.type === "VariableDeclarator") {
|
82
|
-
context.report({ node: node.parent,
|
86
|
+
context.report({ node: node.parent, messageId: "declaration" });
|
83
87
|
}
|
84
88
|
};
|
85
89
|
}
|
@@ -8,7 +8,7 @@
|
|
8
8
|
// Requirements
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const astUtils = require("../ast-utils");
|
11
|
+
const astUtils = require("../util/ast-utils");
|
12
12
|
|
13
13
|
//------------------------------------------------------------------------------
|
14
14
|
// Rule Definition
|
@@ -41,7 +41,13 @@ module.exports = {
|
|
41
41
|
}
|
42
42
|
]
|
43
43
|
}
|
44
|
-
]
|
44
|
+
],
|
45
|
+
messages: {
|
46
|
+
expectedBefore: "Expected newline before ')'.",
|
47
|
+
expectedAfter: "Expected newline after '('.",
|
48
|
+
unexpectedBefore: "Unexpected newline before '('.",
|
49
|
+
unexpectedAfter: "Unexpected newline after ')'."
|
50
|
+
}
|
45
51
|
},
|
46
52
|
|
47
53
|
create(context) {
|
@@ -99,7 +105,7 @@ module.exports = {
|
|
99
105
|
if (hasLeftNewline && !needsNewlines) {
|
100
106
|
context.report({
|
101
107
|
node: leftParen,
|
102
|
-
|
108
|
+
messageId: "unexpectedAfter",
|
103
109
|
fix(fixer) {
|
104
110
|
return sourceCode.getText().slice(leftParen.range[1], tokenAfterLeftParen.range[0]).trim()
|
105
111
|
|
@@ -111,7 +117,7 @@ module.exports = {
|
|
111
117
|
} else if (!hasLeftNewline && needsNewlines) {
|
112
118
|
context.report({
|
113
119
|
node: leftParen,
|
114
|
-
|
120
|
+
messageId: "expectedAfter",
|
115
121
|
fix: fixer => fixer.insertTextAfter(leftParen, "\n")
|
116
122
|
});
|
117
123
|
}
|
@@ -119,7 +125,7 @@ module.exports = {
|
|
119
125
|
if (hasRightNewline && !needsNewlines) {
|
120
126
|
context.report({
|
121
127
|
node: rightParen,
|
122
|
-
|
128
|
+
messageId: "unexpectedBefore",
|
123
129
|
fix(fixer) {
|
124
130
|
return sourceCode.getText().slice(tokenBeforeRightParen.range[1], rightParen.range[0]).trim()
|
125
131
|
|
@@ -131,7 +137,7 @@ module.exports = {
|
|
131
137
|
} else if (!hasRightNewline && needsNewlines) {
|
132
138
|
context.report({
|
133
139
|
node: rightParen,
|
134
|
-
|
140
|
+
messageId: "expectedBefore",
|
135
141
|
fix: fixer => fixer.insertTextBefore(rightParen, "\n")
|
136
142
|
});
|
137
143
|
}
|
@@ -55,7 +55,13 @@ module.exports = {
|
|
55
55
|
}
|
56
56
|
]
|
57
57
|
}
|
58
|
-
]
|
58
|
+
],
|
59
|
+
messages: {
|
60
|
+
missingBefore: "Missing space before *.",
|
61
|
+
missingAfter: "Missing space after *.",
|
62
|
+
unexpectedBefore: "Unexpected space before *.",
|
63
|
+
unexpectedAfter: "Unexpected space after *."
|
64
|
+
}
|
59
65
|
},
|
60
66
|
|
61
67
|
create(context) {
|
@@ -119,6 +125,15 @@ module.exports = {
|
|
119
125
|
);
|
120
126
|
}
|
121
127
|
|
128
|
+
/**
|
129
|
+
* capitalize a given string.
|
130
|
+
* @param {string} str the given string.
|
131
|
+
* @returns {string} the capitalized string.
|
132
|
+
*/
|
133
|
+
function capitalize(str) {
|
134
|
+
return str[0].toUpperCase() + str.slice(1);
|
135
|
+
}
|
136
|
+
|
122
137
|
/**
|
123
138
|
* Checks the spacing between two tokens before or after the star token.
|
124
139
|
*
|
@@ -135,17 +150,11 @@ module.exports = {
|
|
135
150
|
const after = leftToken.value === "*";
|
136
151
|
const spaceRequired = modes[kind][side];
|
137
152
|
const node = after ? leftToken : rightToken;
|
138
|
-
const
|
139
|
-
const message = "{{type}} space {{side}} *.";
|
140
|
-
const data = {
|
141
|
-
type,
|
142
|
-
side
|
143
|
-
};
|
153
|
+
const messageId = `${spaceRequired ? "missing" : "unexpected"}${capitalize(side)}`;
|
144
154
|
|
145
155
|
context.report({
|
146
156
|
node,
|
147
|
-
|
148
|
-
data,
|
157
|
+
messageId,
|
149
158
|
fix(fixer) {
|
150
159
|
if (spaceRequired) {
|
151
160
|
if (after) {
|
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("../ast-utils");
|
12
|
+
const astUtils = require("../util/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Helpers
|
@@ -61,7 +61,11 @@ module.exports = {
|
|
61
61
|
},
|
62
62
|
additionalProperties: false
|
63
63
|
}
|
64
|
-
]
|
64
|
+
],
|
65
|
+
messages: {
|
66
|
+
expected: "Expected to return a value in {{name}}.",
|
67
|
+
expectedAlways: "Expected {{name}} to always return a value."
|
68
|
+
}
|
65
69
|
},
|
66
70
|
|
67
71
|
create(context) {
|
@@ -93,9 +97,7 @@ module.exports = {
|
|
93
97
|
context.report({
|
94
98
|
node,
|
95
99
|
loc: getId(node).loc.start,
|
96
|
-
|
97
|
-
? "Expected {{name}} to always return a value."
|
98
|
-
: "Expected to return a value in {{name}}.",
|
100
|
+
messageId: funcInfo.hasReturn ? "expectedAlways" : "expected",
|
99
101
|
data: {
|
100
102
|
name: astUtils.getFunctionNameWithKind(funcInfo.node)
|
101
103
|
}
|
@@ -161,7 +163,7 @@ module.exports = {
|
|
161
163
|
if (!options.allowImplicit && !node.argument) {
|
162
164
|
context.report({
|
163
165
|
node,
|
164
|
-
|
166
|
+
messageId: "expected",
|
165
167
|
data: {
|
166
168
|
name: astUtils.getFunctionNameWithKind(funcInfo.node)
|
167
169
|
}
|
@@ -12,7 +12,7 @@
|
|
12
12
|
// Requirements
|
13
13
|
//------------------------------------------------------------------------------
|
14
14
|
|
15
|
-
const astUtils = require("../ast-utils");
|
15
|
+
const astUtils = require("../util/ast-utils");
|
16
16
|
|
17
17
|
//------------------------------------------------------------------------------
|
18
18
|
// Rule Definition
|