eslint 5.13.0 → 5.15.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 +69 -0
- package/README.md +68 -156
- package/lib/built-in-rules-index.js +1 -0
- package/lib/cli-engine.js +5 -2
- package/lib/config/config-file.js +27 -4
- package/lib/config/config-initializer.js +151 -144
- package/lib/config/config-ops.js +2 -0
- package/lib/config/config-validator.js +1 -1
- package/lib/config/plugins.js +1 -1
- package/lib/formatters/codeframe.js +1 -1
- package/lib/formatters/stylish.js +2 -2
- package/lib/linter.js +7 -4
- package/lib/rules/accessor-pairs.js +4 -2
- package/lib/rules/array-callback-return.js +4 -3
- 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 +5 -4
- package/lib/rules/capitalized-comments.js +10 -14
- package/lib/rules/class-methods-use-this.js +1 -1
- package/lib/rules/comma-spacing.js +10 -4
- package/lib/rules/complexity.js +6 -7
- package/lib/rules/consistent-return.js +2 -1
- package/lib/rules/curly.js +1 -1
- package/lib/rules/default-case.js +2 -2
- package/lib/rules/dot-notation.js +7 -5
- package/lib/rules/eol-last.js +1 -1
- package/lib/rules/func-call-spacing.js +2 -2
- package/lib/rules/func-style.js +3 -2
- package/lib/rules/getter-return.js +3 -2
- package/lib/rules/handle-callback-err.js +1 -1
- package/lib/rules/id-length.js +3 -2
- package/lib/rules/id-match.js +7 -4
- package/lib/rules/indent-legacy.js +1 -1
- package/lib/rules/indent.js +9 -6
- package/lib/rules/jsx-quotes.js +2 -2
- package/lib/rules/key-spacing.js +1 -1
- package/lib/rules/keyword-spacing.js +14 -14
- package/lib/rules/line-comment-position.js +5 -4
- package/lib/rules/lines-around-comment.js +14 -14
- package/lib/rules/lines-between-class-members.js +2 -1
- package/lib/rules/max-depth.js +5 -5
- package/lib/rules/max-len.js +21 -14
- package/lib/rules/max-lines-per-function.js +13 -17
- package/lib/rules/max-lines.js +3 -5
- package/lib/rules/max-nested-callbacks.js +6 -7
- package/lib/rules/max-params.js +5 -5
- package/lib/rules/max-statements-per-line.js +3 -2
- package/lib/rules/max-statements.js +6 -7
- package/lib/rules/multiline-comment-style.js +9 -9
- package/lib/rules/new-cap.js +9 -6
- package/lib/rules/newline-per-chained-call.js +2 -1
- package/lib/rules/no-alert.js +1 -1
- package/lib/rules/no-bitwise.js +2 -1
- package/lib/rules/no-caller.js +1 -1
- package/lib/rules/no-confusing-arrow.js +1 -1
- package/lib/rules/no-constant-condition.js +2 -1
- package/lib/rules/no-dupe-keys.js +2 -2
- package/lib/rules/no-duplicate-imports.js +2 -1
- package/lib/rules/no-else-return.js +4 -3
- package/lib/rules/no-empty-character-class.js +1 -1
- package/lib/rules/no-empty.js +2 -1
- package/lib/rules/no-eval.js +1 -1
- package/lib/rules/no-extra-parens.js +7 -1
- package/lib/rules/no-fallthrough.js +4 -3
- package/lib/rules/no-implicit-coercion.js +10 -7
- package/lib/rules/no-implied-eval.js +1 -1
- package/lib/rules/no-invalid-regexp.js +2 -2
- package/lib/rules/no-irregular-whitespace.js +11 -7
- package/lib/rules/no-labels.js +6 -4
- package/lib/rules/no-lonely-if.js +1 -1
- package/lib/rules/no-magic-numbers.js +6 -3
- package/lib/rules/no-mixed-operators.js +6 -5
- package/lib/rules/no-mixed-requires.js +1 -1
- package/lib/rules/no-mixed-spaces-and-tabs.js +2 -2
- package/lib/rules/no-multi-spaces.js +2 -1
- package/lib/rules/no-octal-escape.js +1 -1
- package/lib/rules/no-octal.js +1 -1
- package/lib/rules/no-param-reassign.js +2 -2
- package/lib/rules/no-path-concat.js +1 -1
- package/lib/rules/no-plusplus.js +2 -1
- package/lib/rules/no-redeclare.js +2 -2
- package/lib/rules/no-regex-spaces.js +1 -1
- package/lib/rules/no-return-assign.js +1 -1
- package/lib/rules/no-self-assign.js +3 -2
- 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 +4 -3
- package/lib/rules/no-template-curly-in-string.js +1 -1
- package/lib/rules/no-trailing-spaces.js +7 -5
- package/lib/rules/no-undef.js +2 -1
- package/lib/rules/no-underscore-dangle.js +6 -3
- package/lib/rules/no-unexpected-multiline.js +1 -1
- package/lib/rules/no-unmodified-loop-condition.js +5 -5
- package/lib/rules/no-unneeded-ternary.js +2 -1
- package/lib/rules/no-unsafe-finally.js +3 -3
- package/lib/rules/no-unused-expressions.js +8 -5
- package/lib/rules/no-unused-vars.js +6 -6
- package/lib/rules/no-use-before-define.js +2 -2
- package/lib/rules/no-useless-escape.js +1 -1
- package/lib/rules/no-useless-rename.js +3 -3
- package/lib/rules/no-var.js +1 -1
- package/lib/rules/no-warning-comments.js +6 -6
- package/lib/rules/object-property-newline.js +5 -3
- package/lib/rules/one-var.js +18 -35
- package/lib/rules/padded-blocks.js +32 -9
- package/lib/rules/padding-line-between-statements.js +4 -3
- package/lib/rules/prefer-arrow-callback.js +4 -2
- package/lib/rules/prefer-const.js +5 -5
- package/lib/rules/prefer-destructuring.js +56 -5
- package/lib/rules/prefer-named-capture-group.js +123 -0
- package/lib/rules/prefer-object-spread.js +1 -1
- package/lib/rules/prefer-promise-reject-errors.js +1 -1
- package/lib/rules/prefer-spread.js +2 -13
- package/lib/rules/prefer-template.js +3 -3
- package/lib/rules/quotes.js +2 -2
- package/lib/rules/require-jsdoc.js +13 -7
- package/lib/rules/semi-spacing.js +6 -8
- package/lib/rules/semi.js +4 -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-infix-ops.js +2 -1
- package/lib/rules/space-unary-ops.js +5 -3
- package/lib/rules/spaced-comment.js +6 -5
- package/lib/rules/switch-colon-spacing.js +2 -2
- package/lib/rules/template-curly-spacing.js +2 -2
- package/lib/rules/use-isnan.js +1 -1
- package/lib/rules/valid-jsdoc.js +12 -7
- package/lib/rules/valid-typeof.js +2 -1
- package/lib/rules/vars-on-top.js +1 -1
- package/lib/rules/wrap-iife.js +3 -2
- package/lib/rules/yoda.js +6 -4
- package/lib/util/ajv.js +1 -0
- package/lib/util/ast-utils.js +12 -12
- package/lib/util/config-comment-parser.js +4 -4
- package/lib/util/glob-utils.js +3 -3
- package/lib/util/ignored-paths.js +4 -4
- package/lib/util/interpolate.js +1 -1
- package/lib/util/naming.js +6 -6
- package/lib/util/node-event-generator.js +1 -1
- package/lib/util/path-utils.js +2 -2
- package/lib/util/patterns/letters.js +1 -1
- package/lib/util/source-code.js +2 -2
- package/lib/util/xml-escape.js +1 -1
- package/package.json +25 -23
@@ -16,9 +16,9 @@ const astUtils = require("../util/ast-utils");
|
|
16
16
|
// Constants
|
17
17
|
//------------------------------------------------------------------------------
|
18
18
|
|
19
|
-
const ALL_IRREGULARS = /[\f\v\u0085\ufeff\u00a0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u202f\u205f\u3000\u2028\u2029]
|
20
|
-
const IRREGULAR_WHITESPACE = /[\f\v\u0085\ufeff\u00a0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u202f\u205f\u3000]+/
|
21
|
-
const IRREGULAR_LINE_TERMINATORS = /[\u2028\u2029]/
|
19
|
+
const ALL_IRREGULARS = /[\f\v\u0085\ufeff\u00a0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u202f\u205f\u3000\u2028\u2029]/u;
|
20
|
+
const IRREGULAR_WHITESPACE = /[\f\v\u0085\ufeff\u00a0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u202f\u205f\u3000]+/mgu;
|
21
|
+
const IRREGULAR_LINE_TERMINATORS = /[\u2028\u2029]/mgu;
|
22
22
|
const LINE_BREAK = astUtils.createGlobalLinebreakMatcher();
|
23
23
|
|
24
24
|
//------------------------------------------------------------------------------
|
@@ -41,16 +41,20 @@ module.exports = {
|
|
41
41
|
type: "object",
|
42
42
|
properties: {
|
43
43
|
skipComments: {
|
44
|
-
type: "boolean"
|
44
|
+
type: "boolean",
|
45
|
+
default: false
|
45
46
|
},
|
46
47
|
skipStrings: {
|
47
|
-
type: "boolean"
|
48
|
+
type: "boolean",
|
49
|
+
default: true
|
48
50
|
},
|
49
51
|
skipTemplates: {
|
50
|
-
type: "boolean"
|
52
|
+
type: "boolean",
|
53
|
+
default: false
|
51
54
|
},
|
52
55
|
skipRegExps: {
|
53
|
-
type: "boolean"
|
56
|
+
type: "boolean",
|
57
|
+
default: false
|
54
58
|
}
|
55
59
|
},
|
56
60
|
additionalProperties: false
|
package/lib/rules/no-labels.js
CHANGED
@@ -30,10 +30,12 @@ module.exports = {
|
|
30
30
|
type: "object",
|
31
31
|
properties: {
|
32
32
|
allowLoop: {
|
33
|
-
type: "boolean"
|
33
|
+
type: "boolean",
|
34
|
+
default: false
|
34
35
|
},
|
35
36
|
allowSwitch: {
|
36
|
-
type: "boolean"
|
37
|
+
type: "boolean",
|
38
|
+
default: false
|
37
39
|
}
|
38
40
|
},
|
39
41
|
additionalProperties: false
|
@@ -43,8 +45,8 @@ module.exports = {
|
|
43
45
|
|
44
46
|
create(context) {
|
45
47
|
const options = context.options[0];
|
46
|
-
const allowLoop =
|
47
|
-
const allowSwitch =
|
48
|
+
const allowLoop = options && options.allowLoop;
|
49
|
+
const allowSwitch = options && options.allowSwitch;
|
48
50
|
let scopeInfo = null;
|
49
51
|
|
50
52
|
/**
|
@@ -58,7 +58,7 @@ module.exports = {
|
|
58
58
|
node.consequent.type !== "BlockStatement" && lastIfToken.value !== ";" && tokenAfterElseBlock &&
|
59
59
|
(
|
60
60
|
node.consequent.loc.end.line === tokenAfterElseBlock.loc.start.line ||
|
61
|
-
/^[([/+`-]
|
61
|
+
/^[([/+`-]/u.test(tokenAfterElseBlock.value) ||
|
62
62
|
lastIfToken.value === "++" ||
|
63
63
|
lastIfToken.value === "--"
|
64
64
|
)
|
@@ -24,10 +24,12 @@ module.exports = {
|
|
24
24
|
type: "object",
|
25
25
|
properties: {
|
26
26
|
detectObjects: {
|
27
|
-
type: "boolean"
|
27
|
+
type: "boolean",
|
28
|
+
default: false
|
28
29
|
},
|
29
30
|
enforceConst: {
|
30
|
-
type: "boolean"
|
31
|
+
type: "boolean",
|
32
|
+
default: false
|
31
33
|
},
|
32
34
|
ignore: {
|
33
35
|
type: "array",
|
@@ -37,7 +39,8 @@ module.exports = {
|
|
37
39
|
uniqueItems: true
|
38
40
|
},
|
39
41
|
ignoreArrayIndexes: {
|
40
|
-
type: "boolean"
|
42
|
+
type: "boolean",
|
43
|
+
default: false
|
41
44
|
}
|
42
45
|
},
|
43
46
|
additionalProperties: false
|
@@ -34,7 +34,7 @@ const DEFAULT_GROUPS = [
|
|
34
34
|
LOGICAL_OPERATORS,
|
35
35
|
RELATIONAL_OPERATORS
|
36
36
|
];
|
37
|
-
const TARGET_NODE_TYPE = /^(?:Binary|Logical)Expression
|
37
|
+
const TARGET_NODE_TYPE = /^(?:Binary|Logical)Expression$/u;
|
38
38
|
|
39
39
|
/**
|
40
40
|
* Normalizes options.
|
@@ -42,10 +42,10 @@ const TARGET_NODE_TYPE = /^(?:Binary|Logical)Expression$/;
|
|
42
42
|
* @param {Object|undefined} options - A options object to normalize.
|
43
43
|
* @returns {Object} Normalized option object.
|
44
44
|
*/
|
45
|
-
function normalizeOptions(options) {
|
46
|
-
const hasGroups =
|
45
|
+
function normalizeOptions(options = {}) {
|
46
|
+
const hasGroups = options.groups && options.groups.length > 0;
|
47
47
|
const groups = hasGroups ? options.groups : DEFAULT_GROUPS;
|
48
|
-
const allowSamePrecedence =
|
48
|
+
const allowSamePrecedence = options.allowSamePrecedence !== false;
|
49
49
|
|
50
50
|
return {
|
51
51
|
groups,
|
@@ -95,7 +95,8 @@ module.exports = {
|
|
95
95
|
uniqueItems: true
|
96
96
|
},
|
97
97
|
allowSamePrecedence: {
|
98
|
-
type: "boolean"
|
98
|
+
type: "boolean",
|
99
|
+
default: true
|
99
100
|
}
|
100
101
|
},
|
101
102
|
additionalProperties: false
|
@@ -88,7 +88,7 @@ module.exports = {
|
|
88
88
|
* or the reverse before non-tab/-space
|
89
89
|
* characters begin.
|
90
90
|
*/
|
91
|
-
let regex = /^(?=[\t ]*(\t | \t))
|
91
|
+
let regex = /^(?=[\t ]*(\t | \t))/u;
|
92
92
|
const lines = sourceCode.lines,
|
93
93
|
comments = sourceCode.getAllComments();
|
94
94
|
|
@@ -114,7 +114,7 @@ module.exports = {
|
|
114
114
|
* At least one space followed by a tab
|
115
115
|
* before non-tab/-space characters begin.
|
116
116
|
*/
|
117
|
-
regex = /^(?=[\t ]* \t)
|
117
|
+
regex = /^(?=[\t ]* \t)/u;
|
118
118
|
}
|
119
119
|
|
120
120
|
lines.forEach((line, i) => {
|
@@ -32,7 +32,7 @@ module.exports = {
|
|
32
32
|
return;
|
33
33
|
}
|
34
34
|
|
35
|
-
const match = node.raw.match(/^([^\\]|\\[^0-7])*\\([0-3][0-7]{1,2}|[4-7][0-7]|[0-7])/);
|
35
|
+
const match = node.raw.match(/^([^\\]|\\[^0-7])*\\([0-3][0-7]{1,2}|[4-7][0-7]|[0-7])/u);
|
36
36
|
|
37
37
|
if (match) {
|
38
38
|
const octalDigit = match[2];
|
package/lib/rules/no-octal.js
CHANGED
@@ -28,7 +28,7 @@ module.exports = {
|
|
28
28
|
return {
|
29
29
|
|
30
30
|
Literal(node) {
|
31
|
-
if (typeof node.value === "number" && /^0[0-7]
|
31
|
+
if (typeof node.value === "number" && /^0[0-7]/u.test(node.raw)) {
|
32
32
|
context.report({ node, message: "Octal literals should not be used." });
|
33
33
|
}
|
34
34
|
}
|
@@ -8,7 +8,7 @@
|
|
8
8
|
// Rule Definition
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const stopNodePattern = /(?:Statement|Declaration|Function(?:Expression)?|Program)
|
11
|
+
const stopNodePattern = /(?:Statement|Declaration|Function(?:Expression)?|Program)$/u;
|
12
12
|
|
13
13
|
module.exports = {
|
14
14
|
meta: {
|
@@ -55,7 +55,7 @@ module.exports = {
|
|
55
55
|
},
|
56
56
|
|
57
57
|
create(context) {
|
58
|
-
const props = context.options[0] &&
|
58
|
+
const props = context.options[0] && context.options[0].props;
|
59
59
|
const ignoredPropertyAssignmentsFor = context.options[0] && context.options[0].ignorePropertyModificationsFor || [];
|
60
60
|
|
61
61
|
/**
|
package/lib/rules/no-plusplus.js
CHANGED
@@ -24,7 +24,7 @@ module.exports = {
|
|
24
24
|
{
|
25
25
|
type: "object",
|
26
26
|
properties: {
|
27
|
-
builtinGlobals: { type: "boolean" }
|
27
|
+
builtinGlobals: { type: "boolean", default: false }
|
28
28
|
},
|
29
29
|
additionalProperties: false
|
30
30
|
}
|
@@ -33,7 +33,7 @@ module.exports = {
|
|
33
33
|
|
34
34
|
create(context) {
|
35
35
|
const options = {
|
36
|
-
builtinGlobals:
|
36
|
+
builtinGlobals: context.options[0] && context.options[0].builtinGlobals
|
37
37
|
};
|
38
38
|
|
39
39
|
/**
|
@@ -39,7 +39,7 @@ module.exports = {
|
|
39
39
|
* @private
|
40
40
|
*/
|
41
41
|
function checkRegex(node, value, valueStart) {
|
42
|
-
const multipleSpacesRegex = /( {2,})( [+*{?]|[^+*{?]|$)
|
42
|
+
const multipleSpacesRegex = /( {2,})( [+*{?]|[^+*{?]|$)/u,
|
43
43
|
regexResults = multipleSpacesRegex.exec(value);
|
44
44
|
|
45
45
|
if (regexResults !== null) {
|
@@ -14,7 +14,7 @@ const astUtils = require("../util/ast-utils");
|
|
14
14
|
// Helpers
|
15
15
|
//------------------------------------------------------------------------------
|
16
16
|
|
17
|
-
const SENTINEL_TYPE = /^(?:[a-zA-Z]+?Statement|ArrowFunctionExpression|FunctionExpression|ClassExpression)
|
17
|
+
const SENTINEL_TYPE = /^(?:[a-zA-Z]+?Statement|ArrowFunctionExpression|FunctionExpression|ClassExpression)$/u;
|
18
18
|
|
19
19
|
//------------------------------------------------------------------------------
|
20
20
|
// Rule Definition
|
@@ -15,7 +15,7 @@ const astUtils = require("../util/ast-utils");
|
|
15
15
|
// Helpers
|
16
16
|
//------------------------------------------------------------------------------
|
17
17
|
|
18
|
-
const SPACES = /\s+/
|
18
|
+
const SPACES = /\s+/gu;
|
19
19
|
|
20
20
|
/**
|
21
21
|
* Checks whether the property of 2 given member expression nodes are the same
|
@@ -179,7 +179,8 @@ module.exports = {
|
|
179
179
|
type: "object",
|
180
180
|
properties: {
|
181
181
|
props: {
|
182
|
-
type: "boolean"
|
182
|
+
type: "boolean",
|
183
|
+
default: true
|
183
184
|
}
|
184
185
|
},
|
185
186
|
additionalProperties: false
|
@@ -4,6 +4,19 @@
|
|
4
4
|
*/
|
5
5
|
"use strict";
|
6
6
|
|
7
|
+
/**
|
8
|
+
* Determines if a variable safely shadows undefined.
|
9
|
+
* This is the case when a variable named `undefined` is never assigned to a value (i.e. it always shares the same value
|
10
|
+
* as the global).
|
11
|
+
* @param {eslintScope.Variable} variable The variable to check
|
12
|
+
* @returns {boolean} true if this variable safely shadows `undefined`
|
13
|
+
*/
|
14
|
+
function safelyShadowsUndefined(variable) {
|
15
|
+
return variable.name === "undefined" &&
|
16
|
+
variable.references.every(ref => !ref.isWrite()) &&
|
17
|
+
variable.defs.every(def => def.node.type === "VariableDeclarator" && def.node.init === null);
|
18
|
+
}
|
19
|
+
|
7
20
|
//------------------------------------------------------------------------------
|
8
21
|
// Rule Definition
|
9
22
|
//------------------------------------------------------------------------------
|
@@ -24,12 +37,13 @@ module.exports = {
|
|
24
37
|
|
25
38
|
create(context) {
|
26
39
|
|
27
|
-
|
40
|
+
|
41
|
+
const RESTRICTED = new Set(["undefined", "NaN", "Infinity", "arguments", "eval"]);
|
28
42
|
|
29
43
|
return {
|
30
44
|
"VariableDeclaration, :function, CatchClause"(node) {
|
31
45
|
for (const variable of context.getDeclaredVariables(node)) {
|
32
|
-
if (variable.defs.length > 0 && RESTRICTED.
|
46
|
+
if (variable.defs.length > 0 && RESTRICTED.has(variable.name) && !safelyShadowsUndefined(variable)) {
|
33
47
|
context.report({
|
34
48
|
node: variable.defs[0].name,
|
35
49
|
message: "Shadowing of global property '{{idName}}'.",
|
package/lib/rules/no-shadow.js
CHANGED
@@ -30,8 +30,8 @@ module.exports = {
|
|
30
30
|
{
|
31
31
|
type: "object",
|
32
32
|
properties: {
|
33
|
-
builtinGlobals: { type: "boolean" },
|
34
|
-
hoist: { enum: ["all", "functions", "never"] },
|
33
|
+
builtinGlobals: { type: "boolean", default: false },
|
34
|
+
hoist: { enum: ["all", "functions", "never"], default: "functions" },
|
35
35
|
allow: {
|
36
36
|
type: "array",
|
37
37
|
items: {
|
@@ -47,7 +47,7 @@ module.exports = {
|
|
47
47
|
create(context) {
|
48
48
|
|
49
49
|
const options = {
|
50
|
-
builtinGlobals:
|
50
|
+
builtinGlobals: context.options[0] && context.options[0].builtinGlobals,
|
51
51
|
hoist: (context.options[0] && context.options[0].hoist) || "functions",
|
52
52
|
allow: (context.options[0] && context.options[0].allow) || []
|
53
53
|
};
|
package/lib/rules/no-sync.js
CHANGED
package/lib/rules/no-tabs.js
CHANGED
@@ -9,8 +9,8 @@
|
|
9
9
|
// Helpers
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const tabRegex = /\t+/
|
13
|
-
const anyNonWhitespaceRegex = /\S
|
12
|
+
const tabRegex = /\t+/gu;
|
13
|
+
const anyNonWhitespaceRegex = /\S/u;
|
14
14
|
|
15
15
|
//------------------------------------------------------------------------------
|
16
16
|
// Public Interface
|
@@ -30,7 +30,8 @@ module.exports = {
|
|
30
30
|
type: "object",
|
31
31
|
properties: {
|
32
32
|
allowIndentationTabs: {
|
33
|
-
type: "boolean"
|
33
|
+
type: "boolean",
|
34
|
+
default: false
|
34
35
|
}
|
35
36
|
},
|
36
37
|
additionalProperties: false
|
@@ -32,10 +32,12 @@ module.exports = {
|
|
32
32
|
type: "object",
|
33
33
|
properties: {
|
34
34
|
skipBlankLines: {
|
35
|
-
type: "boolean"
|
35
|
+
type: "boolean",
|
36
|
+
default: false
|
36
37
|
},
|
37
38
|
ignoreComments: {
|
38
|
-
type: "boolean"
|
39
|
+
type: "boolean",
|
40
|
+
default: false
|
39
41
|
}
|
40
42
|
},
|
41
43
|
additionalProperties: false
|
@@ -52,7 +54,7 @@ module.exports = {
|
|
52
54
|
|
53
55
|
const options = context.options[0] || {},
|
54
56
|
skipBlankLines = options.skipBlankLines || false,
|
55
|
-
ignoreComments =
|
57
|
+
ignoreComments = options.ignoreComments || false;
|
56
58
|
|
57
59
|
/**
|
58
60
|
* Report the error message
|
@@ -109,8 +111,8 @@ module.exports = {
|
|
109
111
|
* fetch the source code and do matching via regexps.
|
110
112
|
*/
|
111
113
|
|
112
|
-
const re = new RegExp(NONBLANK),
|
113
|
-
skipMatch = new RegExp(SKIP_BLANK),
|
114
|
+
const re = new RegExp(NONBLANK, "u"),
|
115
|
+
skipMatch = new RegExp(SKIP_BLANK, "u"),
|
114
116
|
lines = sourceCode.lines,
|
115
117
|
linebreaks = sourceCode.getText().match(astUtils.createGlobalLinebreakMatcher()),
|
116
118
|
comments = sourceCode.getAllComments(),
|
package/lib/rules/no-undef.js
CHANGED
@@ -31,13 +31,16 @@ module.exports = {
|
|
31
31
|
}
|
32
32
|
},
|
33
33
|
allowAfterThis: {
|
34
|
-
type: "boolean"
|
34
|
+
type: "boolean",
|
35
|
+
default: false
|
35
36
|
},
|
36
37
|
allowAfterSuper: {
|
37
|
-
type: "boolean"
|
38
|
+
type: "boolean",
|
39
|
+
default: false
|
38
40
|
},
|
39
41
|
enforceInMethodNames: {
|
40
|
-
type: "boolean"
|
42
|
+
type: "boolean",
|
43
|
+
default: false
|
41
44
|
}
|
42
45
|
},
|
43
46
|
additionalProperties: false
|
@@ -16,11 +16,11 @@ const Traverser = require("../util/traverser"),
|
|
16
16
|
// Helpers
|
17
17
|
//------------------------------------------------------------------------------
|
18
18
|
|
19
|
-
const SENTINEL_PATTERN = /(?:(?:Call|Class|Function|Member|New|Yield)Expression|Statement|Declaration)
|
20
|
-
const LOOP_PATTERN = /^(?:DoWhile|For|While)Statement
|
21
|
-
const GROUP_PATTERN = /^(?:BinaryExpression|ConditionalExpression)
|
22
|
-
const SKIP_PATTERN = /^(?:ArrowFunction|Class|Function)Expression
|
23
|
-
const DYNAMIC_PATTERN = /^(?:Call|Member|New|TaggedTemplate|Yield)Expression
|
19
|
+
const SENTINEL_PATTERN = /(?:(?:Call|Class|Function|Member|New|Yield)Expression|Statement|Declaration)$/u;
|
20
|
+
const LOOP_PATTERN = /^(?:DoWhile|For|While)Statement$/u; // for-in/of statements don't have `test` property.
|
21
|
+
const GROUP_PATTERN = /^(?:BinaryExpression|ConditionalExpression)$/u;
|
22
|
+
const SKIP_PATTERN = /^(?:ArrowFunction|Class|Function)Expression$/u;
|
23
|
+
const DYNAMIC_PATTERN = /^(?:Call|Member|New|TaggedTemplate|Yield)Expression$/u;
|
24
24
|
|
25
25
|
/**
|
26
26
|
* @typedef {Object} LoopConditionInfo
|
@@ -9,9 +9,9 @@
|
|
9
9
|
// Helpers
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const SENTINEL_NODE_TYPE_RETURN_THROW = /^(?:Program|(?:Function|Class)(?:Declaration|Expression)|ArrowFunctionExpression)
|
13
|
-
const SENTINEL_NODE_TYPE_BREAK = /^(?:Program|(?:Function|Class)(?:Declaration|Expression)|ArrowFunctionExpression|DoWhileStatement|WhileStatement|ForOfStatement|ForInStatement|ForStatement|SwitchStatement)
|
14
|
-
const SENTINEL_NODE_TYPE_CONTINUE = /^(?:Program|(?:Function|Class)(?:Declaration|Expression)|ArrowFunctionExpression|DoWhileStatement|WhileStatement|ForOfStatement|ForInStatement|ForStatement)
|
12
|
+
const SENTINEL_NODE_TYPE_RETURN_THROW = /^(?:Program|(?:Function|Class)(?:Declaration|Expression)|ArrowFunctionExpression)$/u;
|
13
|
+
const SENTINEL_NODE_TYPE_BREAK = /^(?:Program|(?:Function|Class)(?:Declaration|Expression)|ArrowFunctionExpression|DoWhileStatement|WhileStatement|ForOfStatement|ForInStatement|ForStatement|SwitchStatement)$/u;
|
14
|
+
const SENTINEL_NODE_TYPE_CONTINUE = /^(?:Program|(?:Function|Class)(?:Declaration|Expression)|ArrowFunctionExpression|DoWhileStatement|WhileStatement|ForOfStatement|ForInStatement|ForStatement)$/u;
|
15
15
|
|
16
16
|
|
17
17
|
//------------------------------------------------------------------------------
|
@@ -24,13 +24,16 @@ module.exports = {
|
|
24
24
|
type: "object",
|
25
25
|
properties: {
|
26
26
|
allowShortCircuit: {
|
27
|
-
type: "boolean"
|
27
|
+
type: "boolean",
|
28
|
+
default: false
|
28
29
|
},
|
29
30
|
allowTernary: {
|
30
|
-
type: "boolean"
|
31
|
+
type: "boolean",
|
32
|
+
default: false
|
31
33
|
},
|
32
34
|
allowTaggedTemplates: {
|
33
|
-
type: "boolean"
|
35
|
+
type: "boolean",
|
36
|
+
default: false
|
34
37
|
}
|
35
38
|
},
|
36
39
|
additionalProperties: false
|
@@ -85,7 +88,7 @@ module.exports = {
|
|
85
88
|
grandparent = ancestors[ancestors.length - 2];
|
86
89
|
|
87
90
|
return (parent.type === "Program" || parent.type === "BlockStatement" &&
|
88
|
-
(/Function
|
91
|
+
(/Function/u.test(grandparent.type))) &&
|
89
92
|
directives(parent).indexOf(node) >= 0;
|
90
93
|
}
|
91
94
|
|
@@ -113,7 +116,7 @@ module.exports = {
|
|
113
116
|
return true;
|
114
117
|
}
|
115
118
|
|
116
|
-
return /^(?:Assignment|Call|New|Update|Yield|Await)Expression
|
119
|
+
return /^(?:Assignment|Call|New|Update|Yield|Await)Expression$/u.test(node.type) ||
|
117
120
|
(node.type === "UnaryExpression" && ["delete", "void"].indexOf(node.operator) >= 0);
|
118
121
|
}
|
119
122
|
|
@@ -67,7 +67,7 @@ module.exports = {
|
|
67
67
|
create(context) {
|
68
68
|
const sourceCode = context.getSourceCode();
|
69
69
|
|
70
|
-
const REST_PROPERTY_TYPE = /^(?:RestElement|(?:Experimental)?RestProperty)
|
70
|
+
const REST_PROPERTY_TYPE = /^(?:RestElement|(?:Experimental)?RestProperty)$/u;
|
71
71
|
|
72
72
|
const config = {
|
73
73
|
vars: "all",
|
@@ -88,15 +88,15 @@ module.exports = {
|
|
88
88
|
config.caughtErrors = firstOption.caughtErrors || config.caughtErrors;
|
89
89
|
|
90
90
|
if (firstOption.varsIgnorePattern) {
|
91
|
-
config.varsIgnorePattern = new RegExp(firstOption.varsIgnorePattern);
|
91
|
+
config.varsIgnorePattern = new RegExp(firstOption.varsIgnorePattern); // eslint-disable-line require-unicode-regexp
|
92
92
|
}
|
93
93
|
|
94
94
|
if (firstOption.argsIgnorePattern) {
|
95
|
-
config.argsIgnorePattern = new RegExp(firstOption.argsIgnorePattern);
|
95
|
+
config.argsIgnorePattern = new RegExp(firstOption.argsIgnorePattern); // eslint-disable-line require-unicode-regexp
|
96
96
|
}
|
97
97
|
|
98
98
|
if (firstOption.caughtErrorsIgnorePattern) {
|
99
|
-
config.caughtErrorsIgnorePattern = new RegExp(firstOption.caughtErrorsIgnorePattern);
|
99
|
+
config.caughtErrorsIgnorePattern = new RegExp(firstOption.caughtErrorsIgnorePattern); // eslint-disable-line require-unicode-regexp
|
100
100
|
}
|
101
101
|
}
|
102
102
|
}
|
@@ -143,7 +143,7 @@ module.exports = {
|
|
143
143
|
// Helpers
|
144
144
|
//--------------------------------------------------------------------------
|
145
145
|
|
146
|
-
const STATEMENT_TYPE = /(?:Statement|Declaration)
|
146
|
+
const STATEMENT_TYPE = /(?:Statement|Declaration)$/u;
|
147
147
|
|
148
148
|
/**
|
149
149
|
* Determines if a given variable is being exported from a module.
|
@@ -596,7 +596,7 @@ module.exports = {
|
|
596
596
|
* @private
|
597
597
|
*/
|
598
598
|
function getColumnInComment(variable, comment) {
|
599
|
-
const namePattern = new RegExp(`[\\s,]${lodash.escapeRegExp(variable.name)}(?:$|[\\s,:])`, "
|
599
|
+
const namePattern = new RegExp(`[\\s,]${lodash.escapeRegExp(variable.name)}(?:$|[\\s,:])`, "gu");
|
600
600
|
|
601
601
|
// To ignore the first text "global".
|
602
602
|
namePattern.lastIndex = comment.value.indexOf("global") + 6;
|
@@ -9,8 +9,8 @@
|
|
9
9
|
// Helpers
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const SENTINEL_TYPE = /^(?:(?:Function|Class)(?:Declaration|Expression)|ArrowFunctionExpression|CatchClause|ImportDeclaration|ExportNamedDeclaration)
|
13
|
-
const FOR_IN_OF_TYPE = /^For(?:In|Of)Statement
|
12
|
+
const SENTINEL_TYPE = /^(?:(?:Function|Class)(?:Declaration|Expression)|ArrowFunctionExpression|CatchClause|ImportDeclaration|ExportNamedDeclaration)$/u;
|
13
|
+
const FOR_IN_OF_TYPE = /^For(?:In|Of)Statement$/u;
|
14
14
|
|
15
15
|
/**
|
16
16
|
* Parses a given value as options.
|
@@ -26,9 +26,9 @@ module.exports = {
|
|
26
26
|
{
|
27
27
|
type: "object",
|
28
28
|
properties: {
|
29
|
-
ignoreDestructuring: { type: "boolean" },
|
30
|
-
ignoreImport: { type: "boolean" },
|
31
|
-
ignoreExport: { type: "boolean" }
|
29
|
+
ignoreDestructuring: { type: "boolean", default: false },
|
30
|
+
ignoreImport: { type: "boolean", default: false },
|
31
|
+
ignoreExport: { type: "boolean", default: false }
|
32
32
|
},
|
33
33
|
additionalProperties: false
|
34
34
|
}
|