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,13 +16,8 @@ const astUtils = require("../util/ast-utils");
|
|
16
16
|
//------------------------------------------------------------------------------
|
17
17
|
|
18
18
|
const DEFAULT_IGNORE_PATTERN = astUtils.COMMENTS_IGNORE_PATTERN,
|
19
|
-
WHITESPACE = /\s/
|
20
|
-
MAYBE_URL = /^\s*[^:/?#\s]+:\/\/[^?#]
|
21
|
-
DEFAULTS = {
|
22
|
-
ignorePattern: null,
|
23
|
-
ignoreInlineComments: false,
|
24
|
-
ignoreConsecutiveComments: false
|
25
|
-
};
|
19
|
+
WHITESPACE = /\s/gu,
|
20
|
+
MAYBE_URL = /^\s*[^:/?#\s]+:\/\/[^?#]/u; // TODO: Combine w/ max-len pattern?
|
26
21
|
|
27
22
|
/*
|
28
23
|
* Base schema body for defining the basic capitalization rule, ignorePattern,
|
@@ -44,6 +39,11 @@ const SCHEMA_BODY = {
|
|
44
39
|
},
|
45
40
|
additionalProperties: false
|
46
41
|
};
|
42
|
+
const DEFAULTS = {
|
43
|
+
ignorePattern: "",
|
44
|
+
ignoreInlineComments: false,
|
45
|
+
ignoreConsecutiveComments: false
|
46
|
+
};
|
47
47
|
|
48
48
|
/**
|
49
49
|
* Get normalized options for either block or line comments from the given
|
@@ -59,11 +59,7 @@ const SCHEMA_BODY = {
|
|
59
59
|
* @param {string} which Either "line" or "block".
|
60
60
|
* @returns {Object} The normalized options.
|
61
61
|
*/
|
62
|
-
function getNormalizedOptions(rawOptions, which) {
|
63
|
-
if (!rawOptions) {
|
64
|
-
return Object.assign({}, DEFAULTS);
|
65
|
-
}
|
66
|
-
|
62
|
+
function getNormalizedOptions(rawOptions = {}, which) {
|
67
63
|
return Object.assign({}, DEFAULTS, rawOptions[which] || rawOptions);
|
68
64
|
}
|
69
65
|
|
@@ -95,7 +91,7 @@ function createRegExpForIgnorePatterns(normalizedOptions) {
|
|
95
91
|
const ignorePatternStr = normalizedOptions[key].ignorePattern;
|
96
92
|
|
97
93
|
if (ignorePatternStr) {
|
98
|
-
const regExp = RegExp(`^\\s*(?:${ignorePatternStr})`);
|
94
|
+
const regExp = RegExp(`^\\s*(?:${ignorePatternStr})`); // eslint-disable-line require-unicode-regexp
|
99
95
|
|
100
96
|
normalizedOptions[key].ignorePatternRegExp = regExp;
|
101
97
|
}
|
@@ -214,7 +210,7 @@ module.exports = {
|
|
214
210
|
|
215
211
|
// 2. Check for custom ignore pattern.
|
216
212
|
const commentWithoutAsterisks = comment.value
|
217
|
-
.replace(/\*/
|
213
|
+
.replace(/\*/gu, "");
|
218
214
|
|
219
215
|
if (options.ignorePatternRegExp && options.ignorePatternRegExp.test(commentWithoutAsterisks)) {
|
220
216
|
return true;
|
@@ -38,7 +38,7 @@ module.exports = {
|
|
38
38
|
}
|
39
39
|
},
|
40
40
|
create(context) {
|
41
|
-
const config =
|
41
|
+
const config = Object.assign({}, context.options[0]);
|
42
42
|
const exceptMethods = new Set(config.exceptMethods || []);
|
43
43
|
|
44
44
|
const stack = [];
|
@@ -28,10 +28,12 @@ module.exports = {
|
|
28
28
|
type: "object",
|
29
29
|
properties: {
|
30
30
|
before: {
|
31
|
-
type: "boolean"
|
31
|
+
type: "boolean",
|
32
|
+
default: false
|
32
33
|
},
|
33
34
|
after: {
|
34
|
-
type: "boolean"
|
35
|
+
type: "boolean",
|
36
|
+
default: true
|
35
37
|
}
|
36
38
|
},
|
37
39
|
additionalProperties: false
|
@@ -50,8 +52,8 @@ module.exports = {
|
|
50
52
|
const tokensAndComments = sourceCode.tokensAndComments;
|
51
53
|
|
52
54
|
const options = {
|
53
|
-
before: context.options[0] ?
|
54
|
-
after: context.options[0] ?
|
55
|
+
before: context.options[0] ? context.options[0].before : false,
|
56
|
+
after: context.options[0] ? context.options[0].after : true
|
55
57
|
};
|
56
58
|
|
57
59
|
//--------------------------------------------------------------------------
|
@@ -118,6 +120,10 @@ module.exports = {
|
|
118
120
|
report(reportItem, "before", tokens.left);
|
119
121
|
}
|
120
122
|
|
123
|
+
if (tokens.right && astUtils.isClosingParenToken(tokens.right)) {
|
124
|
+
return;
|
125
|
+
}
|
126
|
+
|
121
127
|
if (tokens.right && !options.after && tokens.right.type === "Line") {
|
122
128
|
return;
|
123
129
|
}
|
package/lib/rules/complexity.js
CHANGED
@@ -63,13 +63,12 @@ module.exports = {
|
|
63
63
|
const option = context.options[0];
|
64
64
|
let THRESHOLD = 20;
|
65
65
|
|
66
|
-
if (
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
THRESHOLD = option.max;
|
71
|
-
}
|
72
|
-
if (typeof option === "number") {
|
66
|
+
if (
|
67
|
+
typeof option === "object" &&
|
68
|
+
(Object.prototype.hasOwnProperty.call(option, "maximum") || Object.prototype.hasOwnProperty.call(option, "max"))
|
69
|
+
) {
|
70
|
+
THRESHOLD = option.maximum || option.max;
|
71
|
+
} else if (typeof option === "number") {
|
73
72
|
THRESHOLD = option;
|
74
73
|
}
|
75
74
|
|
package/lib/rules/curly.js
CHANGED
@@ -191,7 +191,7 @@ module.exports = {
|
|
191
191
|
return true;
|
192
192
|
}
|
193
193
|
|
194
|
-
if (/^[([/`+-]
|
194
|
+
if (/^[([/`+-]/u.test(tokenAfter.value)) {
|
195
195
|
|
196
196
|
// If the next token starts with a character that would disrupt ASI, insert a semicolon.
|
197
197
|
return true;
|
@@ -4,7 +4,7 @@
|
|
4
4
|
*/
|
5
5
|
"use strict";
|
6
6
|
|
7
|
-
const DEFAULT_COMMENT_PATTERN = /^no default$/
|
7
|
+
const DEFAULT_COMMENT_PATTERN = /^no default$/iu;
|
8
8
|
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
// Rule Definition
|
@@ -39,7 +39,7 @@ module.exports = {
|
|
39
39
|
create(context) {
|
40
40
|
const options = context.options[0] || {};
|
41
41
|
const commentPattern = options.commentPattern
|
42
|
-
? new RegExp(options.commentPattern)
|
42
|
+
? new RegExp(options.commentPattern) // eslint-disable-line require-unicode-regexp
|
43
43
|
: DEFAULT_COMMENT_PATTERN;
|
44
44
|
|
45
45
|
const sourceCode = context.getSourceCode();
|
@@ -14,7 +14,7 @@ const astUtils = require("../util/ast-utils");
|
|
14
14
|
// Rule Definition
|
15
15
|
//------------------------------------------------------------------------------
|
16
16
|
|
17
|
-
const validIdentifier = /^[a-zA-Z_$][a-zA-Z0-9_$]
|
17
|
+
const validIdentifier = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/u;
|
18
18
|
const keywords = require("../util/keywords");
|
19
19
|
|
20
20
|
module.exports = {
|
@@ -33,10 +33,12 @@ module.exports = {
|
|
33
33
|
type: "object",
|
34
34
|
properties: {
|
35
35
|
allowKeywords: {
|
36
|
-
type: "boolean"
|
36
|
+
type: "boolean",
|
37
|
+
default: true
|
37
38
|
},
|
38
39
|
allowPattern: {
|
39
|
-
type: "string"
|
40
|
+
type: "string",
|
41
|
+
default: ""
|
40
42
|
}
|
41
43
|
},
|
42
44
|
additionalProperties: false
|
@@ -53,13 +55,13 @@ module.exports = {
|
|
53
55
|
|
54
56
|
create(context) {
|
55
57
|
const options = context.options[0] || {};
|
56
|
-
const allowKeywords = options.allowKeywords === void 0 ||
|
58
|
+
const allowKeywords = options.allowKeywords === void 0 || options.allowKeywords;
|
57
59
|
const sourceCode = context.getSourceCode();
|
58
60
|
|
59
61
|
let allowPattern;
|
60
62
|
|
61
63
|
if (options.allowPattern) {
|
62
|
-
allowPattern = new RegExp(options.allowPattern);
|
64
|
+
allowPattern = new RegExp(options.allowPattern); // eslint-disable-line require-unicode-regexp
|
63
65
|
}
|
64
66
|
|
65
67
|
/**
|
package/lib/rules/eol-last.js
CHANGED
@@ -97,7 +97,7 @@ module.exports = {
|
|
97
97
|
loc: location,
|
98
98
|
messageId: "unexpected",
|
99
99
|
fix(fixer) {
|
100
|
-
const finalEOLs = /(?:\r?\n)
|
100
|
+
const finalEOLs = /(?:\r?\n)+$/u,
|
101
101
|
match = finalEOLs.exec(sourceCode.text),
|
102
102
|
start = match.index,
|
103
103
|
end = sourceCode.text.length;
|
@@ -92,8 +92,8 @@ module.exports = {
|
|
92
92
|
return;
|
93
93
|
}
|
94
94
|
|
95
|
-
const textBetweenTokens = text.slice(prevToken.range[1], parenToken.range[0]).replace(/\/\*.*?\*\//
|
96
|
-
const hasWhitespace = /\s
|
95
|
+
const textBetweenTokens = text.slice(prevToken.range[1], parenToken.range[0]).replace(/\/\*.*?\*\//gu, "");
|
96
|
+
const hasWhitespace = /\s/u.test(textBetweenTokens);
|
97
97
|
const hasNewline = hasWhitespace && astUtils.LINEBREAK_MATCHER.test(textBetweenTokens);
|
98
98
|
|
99
99
|
/*
|
package/lib/rules/func-style.js
CHANGED
@@ -27,7 +27,8 @@ module.exports = {
|
|
27
27
|
type: "object",
|
28
28
|
properties: {
|
29
29
|
allowArrowFunctions: {
|
30
|
-
type: "boolean"
|
30
|
+
type: "boolean",
|
31
|
+
default: false
|
31
32
|
}
|
32
33
|
},
|
33
34
|
additionalProperties: false
|
@@ -43,7 +44,7 @@ module.exports = {
|
|
43
44
|
create(context) {
|
44
45
|
|
45
46
|
const style = context.options[0],
|
46
|
-
allowArrowFunctions = context.options[1] && context.options[1].allowArrowFunctions
|
47
|
+
allowArrowFunctions = context.options[1] && context.options[1].allowArrowFunctions,
|
47
48
|
enforceDeclarations = (style === "declaration"),
|
48
49
|
stack = [];
|
49
50
|
|
@@ -14,7 +14,7 @@ const astUtils = require("../util/ast-utils");
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Helpers
|
16
16
|
//------------------------------------------------------------------------------
|
17
|
-
const TARGET_NODE_TYPE = /^(?:Arrow)?FunctionExpression
|
17
|
+
const TARGET_NODE_TYPE = /^(?:Arrow)?FunctionExpression$/u;
|
18
18
|
|
19
19
|
/**
|
20
20
|
* Checks a given code path segment is reachable.
|
@@ -60,7 +60,8 @@ module.exports = {
|
|
60
60
|
type: "object",
|
61
61
|
properties: {
|
62
62
|
allowImplicit: {
|
63
|
-
type: "boolean"
|
63
|
+
type: "boolean",
|
64
|
+
default: false
|
64
65
|
}
|
65
66
|
},
|
66
67
|
additionalProperties: false
|
@@ -52,7 +52,7 @@ module.exports = {
|
|
52
52
|
*/
|
53
53
|
function matchesConfiguredErrorName(name) {
|
54
54
|
if (isPattern(errorArgument)) {
|
55
|
-
const regexp = new RegExp(errorArgument);
|
55
|
+
const regexp = new RegExp(errorArgument); // eslint-disable-line require-unicode-regexp
|
56
56
|
|
57
57
|
return regexp.test(name);
|
58
58
|
}
|
package/lib/rules/id-length.js
CHANGED
package/lib/rules/id-match.js
CHANGED
@@ -28,13 +28,16 @@ module.exports = {
|
|
28
28
|
type: "object",
|
29
29
|
properties: {
|
30
30
|
properties: {
|
31
|
-
type: "boolean"
|
31
|
+
type: "boolean",
|
32
|
+
default: false
|
32
33
|
},
|
33
34
|
onlyDeclarations: {
|
34
|
-
type: "boolean"
|
35
|
+
type: "boolean",
|
36
|
+
default: false
|
35
37
|
},
|
36
38
|
ignoreDestructuring: {
|
37
|
-
type: "boolean"
|
39
|
+
type: "boolean",
|
40
|
+
default: false
|
38
41
|
}
|
39
42
|
}
|
40
43
|
}
|
@@ -50,7 +53,7 @@ module.exports = {
|
|
50
53
|
// Options
|
51
54
|
//--------------------------------------------------------------------------
|
52
55
|
const pattern = context.options[0] || "^.+$",
|
53
|
-
regexp = new RegExp(pattern);
|
56
|
+
regexp = new RegExp(pattern); // eslint-disable-line require-unicode-regexp
|
54
57
|
|
55
58
|
const options = context.options[1] || {},
|
56
59
|
properties = !!options.properties,
|
@@ -975,7 +975,7 @@ module.exports = {
|
|
975
975
|
* @returns {boolean} the result
|
976
976
|
*/
|
977
977
|
function isWrappedInParenthesis(node) {
|
978
|
-
const regex = /^return\s*?\(\s*?\)
|
978
|
+
const regex = /^return\s*?\(\s*?\);*?/u;
|
979
979
|
|
980
980
|
const statementWithoutArgument = sourceCode.getText(node).replace(
|
981
981
|
sourceCode.getText(node.argument), ""
|
package/lib/rules/indent.js
CHANGED
@@ -442,7 +442,7 @@ class OffsetStorage {
|
|
442
442
|
const offset = (
|
443
443
|
offsetInfo.from &&
|
444
444
|
offsetInfo.from.loc.start.line === token.loc.start.line &&
|
445
|
-
!/^\s*?\n
|
445
|
+
!/^\s*?\n/u.test(token.value) &&
|
446
446
|
!offsetInfo.force
|
447
447
|
) ? 0 : offsetInfo.offset * this._indentSize;
|
448
448
|
|
@@ -518,7 +518,8 @@ module.exports = {
|
|
518
518
|
properties: {
|
519
519
|
SwitchCase: {
|
520
520
|
type: "integer",
|
521
|
-
minimum: 0
|
521
|
+
minimum: 0,
|
522
|
+
default: 0
|
522
523
|
},
|
523
524
|
VariableDeclarator: {
|
524
525
|
oneOf: [
|
@@ -582,7 +583,8 @@ module.exports = {
|
|
582
583
|
ObjectExpression: ELEMENT_LIST_SCHEMA,
|
583
584
|
ImportDeclaration: ELEMENT_LIST_SCHEMA,
|
584
585
|
flatTernaryExpressions: {
|
585
|
-
type: "boolean"
|
586
|
+
type: "boolean",
|
587
|
+
default: false
|
586
588
|
},
|
587
589
|
ignoredNodes: {
|
588
590
|
type: "array",
|
@@ -594,7 +596,8 @@ module.exports = {
|
|
594
596
|
}
|
595
597
|
},
|
596
598
|
ignoreComments: {
|
597
|
-
type: "boolean"
|
599
|
+
type: "boolean",
|
600
|
+
default: false
|
598
601
|
}
|
599
602
|
},
|
600
603
|
additionalProperties: false
|
@@ -650,7 +653,7 @@ module.exports = {
|
|
650
653
|
}
|
651
654
|
|
652
655
|
if (context.options[1]) {
|
653
|
-
|
656
|
+
Object.assign(options, context.options[1]);
|
654
657
|
|
655
658
|
if (typeof options.VariableDeclarator === "number" || options.VariableDeclarator === "first") {
|
656
659
|
options.VariableDeclarator = {
|
@@ -782,7 +785,7 @@ module.exports = {
|
|
782
785
|
* or the total number of linebreaks if the string is all whitespace.
|
783
786
|
*/
|
784
787
|
function countTrailingLinebreaks(string) {
|
785
|
-
const trailingWhitespace = string.match(/\s*$/)[0];
|
788
|
+
const trailingWhitespace = string.match(/\s*$/u)[0];
|
786
789
|
const linebreakMatches = trailingWhitespace.match(astUtils.createGlobalLinebreakMatcher());
|
787
790
|
|
788
791
|
return linebreakMatches === null ? 0 : linebreakMatches.length;
|
package/lib/rules/jsx-quotes.js
CHANGED
@@ -20,14 +20,14 @@ const QUOTE_SETTINGS = {
|
|
20
20
|
quote: "\"",
|
21
21
|
description: "singlequote",
|
22
22
|
convert(str) {
|
23
|
-
return str.replace(/'/
|
23
|
+
return str.replace(/'/gu, "\"");
|
24
24
|
}
|
25
25
|
},
|
26
26
|
"prefer-single": {
|
27
27
|
quote: "'",
|
28
28
|
description: "doublequote",
|
29
29
|
convert(str) {
|
30
|
-
return str.replace(/"/
|
30
|
+
return str.replace(/"/gu, "'");
|
31
31
|
}
|
32
32
|
}
|
33
33
|
};
|
package/lib/rules/key-spacing.js
CHANGED
@@ -501,7 +501,7 @@ module.exports = {
|
|
501
501
|
* @returns {Object} Whitespace before and after the property's colon.
|
502
502
|
*/
|
503
503
|
function getPropertyWhitespace(property) {
|
504
|
-
const whitespace = /(\s*):(\s*)
|
504
|
+
const whitespace = /(\s*):(\s*)/u.exec(sourceCode.getText().slice(
|
505
505
|
property.key.range[1], property.value.range[0]
|
506
506
|
));
|
507
507
|
|
@@ -16,13 +16,13 @@ const astUtils = require("../util/ast-utils"),
|
|
16
16
|
// Constants
|
17
17
|
//------------------------------------------------------------------------------
|
18
18
|
|
19
|
-
const PREV_TOKEN = /^[)\]}>]
|
20
|
-
const NEXT_TOKEN = /^(?:[([{<~!]|\+\+?|--?)
|
21
|
-
const PREV_TOKEN_M = /^[)\]}>*]
|
22
|
-
const NEXT_TOKEN_M = /^[{*]
|
23
|
-
const TEMPLATE_OPEN_PAREN = /\$\{
|
24
|
-
const TEMPLATE_CLOSE_PAREN = /^\}
|
25
|
-
const CHECK_TYPE = /^(?:JSXElement|RegularExpression|String|Template)
|
19
|
+
const PREV_TOKEN = /^[)\]}>]$/u;
|
20
|
+
const NEXT_TOKEN = /^(?:[([{<~!]|\+\+?|--?)$/u;
|
21
|
+
const PREV_TOKEN_M = /^[)\]}>*]$/u;
|
22
|
+
const NEXT_TOKEN_M = /^[{*]$/u;
|
23
|
+
const TEMPLATE_OPEN_PAREN = /\$\{$/u;
|
24
|
+
const TEMPLATE_CLOSE_PAREN = /^\}/u;
|
25
|
+
const CHECK_TYPE = /^(?:JSXElement|RegularExpression|String|Template)$/u;
|
26
26
|
const KEYS = keywords.concat(["as", "async", "await", "from", "get", "let", "of", "set", "yield"]);
|
27
27
|
|
28
28
|
// check duplications.
|
@@ -80,16 +80,16 @@ module.exports = {
|
|
80
80
|
{
|
81
81
|
type: "object",
|
82
82
|
properties: {
|
83
|
-
before: { type: "boolean" },
|
84
|
-
after: { type: "boolean" },
|
83
|
+
before: { type: "boolean", default: true },
|
84
|
+
after: { type: "boolean", default: true },
|
85
85
|
overrides: {
|
86
86
|
type: "object",
|
87
87
|
properties: KEYS.reduce((retv, key) => {
|
88
88
|
retv[key] = {
|
89
89
|
type: "object",
|
90
90
|
properties: {
|
91
|
-
before: { type: "boolean" },
|
92
|
-
after: { type: "boolean" }
|
91
|
+
before: { type: "boolean", default: true },
|
92
|
+
after: { type: "boolean", default: true }
|
93
93
|
},
|
94
94
|
additionalProperties: false
|
95
95
|
};
|
@@ -228,9 +228,9 @@ module.exports = {
|
|
228
228
|
* Keys are keywords (there are for every keyword).
|
229
229
|
* Values are instances of `{"before": function, "after": function}`.
|
230
230
|
*/
|
231
|
-
function parseOptions(options) {
|
232
|
-
const before =
|
233
|
-
const after =
|
231
|
+
function parseOptions(options = {}) {
|
232
|
+
const before = options.before !== false;
|
233
|
+
const after = options.after !== false;
|
234
234
|
const defaultValue = {
|
235
235
|
before: before ? expectSpaceBefore : unexpectSpaceBefore,
|
236
236
|
after: after ? expectSpaceAfter : unexpectSpaceAfter
|
@@ -31,7 +31,8 @@ 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"
|
@@ -69,15 +70,15 @@ module.exports = {
|
|
69
70
|
ignorePattern = options.ignorePattern;
|
70
71
|
|
71
72
|
if (Object.prototype.hasOwnProperty.call(options, "applyDefaultIgnorePatterns")) {
|
72
|
-
applyDefaultIgnorePatterns = options.applyDefaultIgnorePatterns
|
73
|
+
applyDefaultIgnorePatterns = options.applyDefaultIgnorePatterns;
|
73
74
|
} else {
|
74
75
|
applyDefaultIgnorePatterns = options.applyDefaultPatterns !== false;
|
75
76
|
}
|
76
77
|
}
|
77
78
|
|
78
79
|
const defaultIgnoreRegExp = astUtils.COMMENTS_IGNORE_PATTERN;
|
79
|
-
const fallThroughRegExp = /^\s*falls?\s?through
|
80
|
-
const customIgnoreRegExp = new RegExp(ignorePattern);
|
80
|
+
const fallThroughRegExp = /^\s*falls?\s?through/u;
|
81
|
+
const customIgnoreRegExp = new RegExp(ignorePattern); // eslint-disable-line require-unicode-regexp
|
81
82
|
const sourceCode = context.getSourceCode();
|
82
83
|
|
83
84
|
//--------------------------------------------------------------------------
|
@@ -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"
|
@@ -121,19 +127,13 @@ module.exports = {
|
|
121
127
|
|
122
128
|
create(context) {
|
123
129
|
|
124
|
-
const options =
|
130
|
+
const options = Object.assign({}, context.options[0]);
|
125
131
|
const ignorePattern = options.ignorePattern;
|
126
132
|
const defaultIgnoreRegExp = astUtils.COMMENTS_IGNORE_PATTERN;
|
127
|
-
const customIgnoreRegExp = new RegExp(ignorePattern);
|
133
|
+
const customIgnoreRegExp = new RegExp(ignorePattern); // eslint-disable-line require-unicode-regexp
|
128
134
|
const applyDefaultIgnorePatterns = options.applyDefaultIgnorePatterns !== false;
|
129
135
|
|
130
|
-
|
131
|
-
options.beforeLineComment = options.beforeLineComment || false;
|
132
|
-
options.afterLineComment = options.afterLineComment || false;
|
133
136
|
options.beforeBlockComment = typeof options.beforeBlockComment !== "undefined" ? options.beforeBlockComment : true;
|
134
|
-
options.afterBlockComment = options.afterBlockComment || false;
|
135
|
-
options.allowBlockStart = options.allowBlockStart || false;
|
136
|
-
options.allowBlockEnd = options.allowBlockEnd || false;
|
137
137
|
|
138
138
|
const sourceCode = context.getSourceCode();
|
139
139
|
|
package/lib/rules/max-depth.js
CHANGED
@@ -59,11 +59,11 @@ module.exports = {
|
|
59
59
|
option = context.options[0];
|
60
60
|
let maxDepth = 4;
|
61
61
|
|
62
|
-
if (
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
maxDepth = option.max;
|
62
|
+
if (
|
63
|
+
typeof option === "object" &&
|
64
|
+
(Object.prototype.hasOwnProperty.call(option, "maximum") || Object.prototype.hasOwnProperty.call(option, "max"))
|
65
|
+
) {
|
66
|
+
maxDepth = option.maximum || option.max;
|
67
67
|
}
|
68
68
|
if (typeof option === "number") {
|
69
69
|
maxDepth = option;
|