eslint-plugin-unicorn 45.0.0 → 45.0.2
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/package.json +5 -5
- package/readme.md +3 -1
- package/rules/better-regex.js +3 -1
- package/rules/catch-error-name.js +1 -1
- package/rules/consistent-function-scoping.js +1 -1
- package/rules/empty-brace-spaces.js +1 -1
- package/rules/error-message.js +1 -1
- package/rules/explicit-length-check.js +1 -1
- package/rules/fix/add-parenthesizes-to-return-or-throw-expression.js +1 -1
- package/rules/fix/append-argument.js +1 -1
- package/rules/fix/remove-argument.js +1 -1
- package/rules/import-style.js +1 -1
- package/rules/no-array-callback-reference.js +1 -1
- package/rules/no-array-for-each.js +1 -1
- package/rules/no-array-method-this-argument.js +1 -1
- package/rules/no-array-push-push.js +1 -1
- package/rules/no-for-loop.js +1 -1
- package/rules/no-invalid-remove-event-listener.js +1 -1
- package/rules/no-lonely-if.js +1 -1
- package/rules/no-nested-ternary.js +1 -1
- package/rules/no-new-array.js +1 -1
- package/rules/no-new-buffer.js +1 -1
- package/rules/no-static-only-class.js +1 -1
- package/rules/no-thenable.js +1 -1
- package/rules/no-unreadable-array-destructuring.js +1 -1
- package/rules/no-useless-spread.js +21 -3
- package/rules/no-useless-undefined.js +1 -1
- package/rules/no-zero-fractions.js +1 -1
- package/rules/prefer-add-event-listener.js +1 -1
- package/rules/prefer-array-find.js +1 -1
- package/rules/prefer-at.js +1 -1
- package/rules/prefer-default-parameters.js +1 -1
- package/rules/prefer-dom-node-remove.js +1 -1
- package/rules/prefer-export-from.js +1 -1
- package/rules/prefer-json-parse-buffer.js +1 -1
- package/rules/prefer-math-trunc.js +1 -1
- package/rules/prefer-module.js +1 -1
- package/rules/prefer-native-coercion-functions.js +1 -1
- package/rules/prefer-object-from-entries.js +1 -1
- package/rules/prefer-optional-catch-binding.js +1 -1
- package/rules/prefer-prototype-methods.js +1 -1
- package/rules/prefer-reflect-apply.js +1 -1
- package/rules/prefer-regexp-test.js +1 -1
- package/rules/prefer-set-has.js +1 -1
- package/rules/prefer-set-size.js +1 -1
- package/rules/prefer-spread.js +1 -1
- package/rules/prefer-string-replace-all.js +12 -6
- package/rules/prefer-string-slice.js +1 -1
- package/rules/prefer-string-starts-ends-with.js +1 -1
- package/rules/prefer-switch.js +1 -1
- package/rules/prefer-ternary.js +1 -1
- package/rules/prefer-top-level-await.js +1 -1
- package/rules/prevent-abbreviations.js +6 -1
- package/rules/relative-url-style.js +1 -1
- package/rules/shared/simple-array-search-rule.js +1 -1
- package/rules/switch-case-braces.js +1 -1
- package/rules/utils/get-call-expression-arguments-text.js +1 -1
- package/rules/utils/get-switch-case-head-location.js +1 -1
- package/rules/utils/global-reference-tracker.js +1 -1
- package/rules/utils/is-function-self-used-inside.js +1 -1
- package/rules/utils/is-new-expression-with-parentheses.js +1 -1
- package/rules/utils/is-number.js +1 -1
- package/rules/utils/is-same-reference.js +1 -1
- package/rules/utils/parentheses.js +1 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-unicorn",
|
|
3
|
-
"version": "45.0.
|
|
3
|
+
"version": "45.0.2",
|
|
4
4
|
"description": "More than 100 powerful ESLint rules",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "sindresorhus/eslint-plugin-unicorn",
|
|
@@ -47,18 +47,18 @@
|
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@babel/helper-validator-identifier": "^7.19.1",
|
|
50
|
+
"@eslint-community/eslint-utils": "^4.1.2",
|
|
50
51
|
"ci-info": "^3.6.1",
|
|
51
52
|
"clean-regexp": "^1.0.0",
|
|
52
|
-
"eslint-utils": "^3.0.0",
|
|
53
53
|
"esquery": "^1.4.0",
|
|
54
54
|
"indent-string": "^4.0.0",
|
|
55
55
|
"is-builtin-module": "^3.2.0",
|
|
56
|
-
"jsesc": "3.0.2",
|
|
56
|
+
"jsesc": "^3.0.2",
|
|
57
57
|
"lodash": "^4.17.21",
|
|
58
58
|
"pluralize": "^8.0.0",
|
|
59
59
|
"read-pkg-up": "^7.0.1",
|
|
60
60
|
"regexp-tree": "^0.1.24",
|
|
61
|
-
"regjsparser": "0.9.1",
|
|
61
|
+
"regjsparser": "^0.9.1",
|
|
62
62
|
"safe-regex": "^2.1.1",
|
|
63
63
|
"semver": "^7.3.8",
|
|
64
64
|
"strip-indent": "^3.0.0"
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"enquirer": "^2.3.6",
|
|
76
76
|
"eslint": "^8.28.0",
|
|
77
77
|
"eslint-ava-rule-tester": "^4.0.0",
|
|
78
|
-
"eslint-doc-generator": "^0.
|
|
78
|
+
"eslint-doc-generator": "^1.0.0",
|
|
79
79
|
"eslint-plugin-eslint-plugin": "^5.0.6",
|
|
80
80
|
"eslint-plugin-internal-rules": "file:./scripts/internal-rules/",
|
|
81
81
|
"eslint-remote-tester": "^3.0.0",
|
package/readme.md
CHANGED
|
@@ -17,7 +17,9 @@ npm install --save-dev eslint eslint-plugin-unicorn
|
|
|
17
17
|
|
|
18
18
|
## Usage
|
|
19
19
|
|
|
20
|
-
Use a [preset config](#preset-configs) or configure each
|
|
20
|
+
Use a [preset config](#preset-configs) or configure each rule in `package.json`.
|
|
21
|
+
|
|
22
|
+
If you don't use the preset, ensure you use the same `env` and `parserOptions` config as below.
|
|
21
23
|
|
|
22
24
|
```json
|
|
23
25
|
{
|
package/rules/better-regex.js
CHANGED
|
@@ -6,8 +6,10 @@ const {newExpressionSelector} = require('./selectors/index.js');
|
|
|
6
6
|
const {isStringLiteral} = require('./ast/index.js');
|
|
7
7
|
|
|
8
8
|
const MESSAGE_ID = 'better-regex';
|
|
9
|
+
const MESSAGE_ID_PARSE_ERROR = 'better-regex/parse-error';
|
|
9
10
|
const messages = {
|
|
10
11
|
[MESSAGE_ID]: '{{original}} can be optimized to {{optimized}}.',
|
|
12
|
+
[MESSAGE_ID_PARSE_ERROR]: 'Problem parsing {{original}}: {{error}}',
|
|
11
13
|
};
|
|
12
14
|
|
|
13
15
|
const newRegExp = newExpressionSelector({name: 'RegExp', minimumArguments: 1});
|
|
@@ -39,11 +41,11 @@ const create = context => {
|
|
|
39
41
|
} catch (error) {
|
|
40
42
|
return {
|
|
41
43
|
node,
|
|
44
|
+
messageId: MESSAGE_ID_PARSE_ERROR,
|
|
42
45
|
data: {
|
|
43
46
|
original,
|
|
44
47
|
error: error.message,
|
|
45
48
|
},
|
|
46
|
-
message: 'Problem parsing {{original}}: {{error}}',
|
|
47
49
|
};
|
|
48
50
|
}
|
|
49
51
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {findVariable} = require('eslint-utils');
|
|
2
|
+
const {findVariable} = require('@eslint-community/eslint-utils');
|
|
3
3
|
const avoidCapture = require('./utils/avoid-capture.js');
|
|
4
4
|
const {renameVariable} = require('./fix/index.js');
|
|
5
5
|
const {matches, methodCallSelector} = require('./selectors/index.js');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {getFunctionHeadLocation, getFunctionNameWithKind} = require('eslint-utils');
|
|
2
|
+
const {getFunctionHeadLocation, getFunctionNameWithKind} = require('@eslint-community/eslint-utils');
|
|
3
3
|
const getReferences = require('./utils/get-references.js');
|
|
4
4
|
const {isNodeMatches} = require('./utils/is-node-matches.js');
|
|
5
5
|
|
package/rules/error-message.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {isParenthesized, getStaticValue} = require('eslint-utils');
|
|
2
|
+
const {isParenthesized, getStaticValue} = require('@eslint-community/eslint-utils');
|
|
3
3
|
const {checkVueTemplate} = require('./utils/rule.js');
|
|
4
4
|
const isLogicalExpression = require('./utils/is-logical-expression.js');
|
|
5
5
|
const {isBooleanNode, getBooleanAncestor} = require('./utils/boolean.js');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {isSemicolonToken} = require('eslint-utils');
|
|
2
|
+
const {isSemicolonToken} = require('@eslint-community/eslint-utils');
|
|
3
3
|
|
|
4
4
|
function * addParenthesizesToReturnOrThrowExpression(fixer, node, sourceCode) {
|
|
5
5
|
if (node.type !== 'ReturnStatement' && node.type !== 'ThrowStatement') {
|
package/rules/import-style.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
const {defaultsDeep} = require('lodash');
|
|
3
|
-
const {getStringIfConstant} = require('eslint-utils');
|
|
3
|
+
const {getStringIfConstant} = require('@eslint-community/eslint-utils');
|
|
4
4
|
const {callExpressionSelector} = require('./selectors/index.js');
|
|
5
5
|
|
|
6
6
|
const MESSAGE_ID = 'importStyle';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {isParenthesized} = require('eslint-utils');
|
|
2
|
+
const {isParenthesized} = require('@eslint-community/eslint-utils');
|
|
3
3
|
const {methodCallSelector, notFunctionSelector} = require('./selectors/index.js');
|
|
4
4
|
const {isNodeMatches} = require('./utils/is-node-matches.js');
|
|
5
5
|
|
|
@@ -6,7 +6,7 @@ const {
|
|
|
6
6
|
isClosingParenToken,
|
|
7
7
|
findVariable,
|
|
8
8
|
hasSideEffect,
|
|
9
|
-
} = require('eslint-utils');
|
|
9
|
+
} = require('@eslint-community/eslint-utils');
|
|
10
10
|
const {methodCallSelector, referenceIdentifierSelector} = require('./selectors/index.js');
|
|
11
11
|
const {extendFixRange} = require('./fix/index.js');
|
|
12
12
|
const needsSemicolon = require('./utils/needs-semicolon.js');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {hasSideEffect} = require('eslint-utils');
|
|
2
|
+
const {hasSideEffect} = require('@eslint-community/eslint-utils');
|
|
3
3
|
const {methodCallSelector, notFunctionSelector} = require('./selectors/index.js');
|
|
4
4
|
const {removeArgument} = require('./fix/index.js');
|
|
5
5
|
const {getParentheses, getParenthesizedText} = require('./utils/parentheses.js');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {hasSideEffect, isCommaToken, isSemicolonToken} = require('eslint-utils');
|
|
2
|
+
const {hasSideEffect, isCommaToken, isSemicolonToken} = require('@eslint-community/eslint-utils');
|
|
3
3
|
const {methodCallSelector} = require('./selectors/index.js');
|
|
4
4
|
const getCallExpressionArgumentsText = require('./utils/get-call-expression-arguments-text.js');
|
|
5
5
|
const isSameReference = require('./utils/is-same-reference.js');
|
package/rules/no-for-loop.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {isClosingParenToken, getStaticValue} = require('eslint-utils');
|
|
2
|
+
const {isClosingParenToken, getStaticValue} = require('@eslint-community/eslint-utils');
|
|
3
3
|
const avoidCapture = require('./utils/avoid-capture.js');
|
|
4
4
|
const getScopes = require('./utils/get-scopes.js');
|
|
5
5
|
const singular = require('./utils/singular.js');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {getFunctionHeadLocation} = require('eslint-utils');
|
|
2
|
+
const {getFunctionHeadLocation} = require('@eslint-community/eslint-utils');
|
|
3
3
|
const getDocumentationUrl = require('./utils/get-documentation-url.js');
|
|
4
4
|
const {methodCallSelector, matches} = require('./selectors/index.js');
|
|
5
5
|
|
package/rules/no-lonely-if.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {isParenthesized, isNotSemicolonToken} = require('eslint-utils');
|
|
2
|
+
const {isParenthesized, isNotSemicolonToken} = require('@eslint-community/eslint-utils');
|
|
3
3
|
const needsSemicolon = require('./utils/needs-semicolon.js');
|
|
4
4
|
const {removeSpacesAfter} = require('./fix/index.js');
|
|
5
5
|
const {matches} = require('./selectors/index.js');
|
package/rules/no-new-array.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {isParenthesized, getStaticValue} = require('eslint-utils');
|
|
2
|
+
const {isParenthesized, getStaticValue} = require('@eslint-community/eslint-utils');
|
|
3
3
|
const needsSemicolon = require('./utils/needs-semicolon.js');
|
|
4
4
|
const {newExpressionSelector} = require('./selectors/index.js');
|
|
5
5
|
const isNumber = require('./utils/is-number.js');
|
package/rules/no-new-buffer.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {getStaticValue} = require('eslint-utils');
|
|
2
|
+
const {getStaticValue} = require('@eslint-community/eslint-utils');
|
|
3
3
|
const {newExpressionSelector} = require('./selectors/index.js');
|
|
4
4
|
const {switchNewExpressionToCallExpression} = require('./fix/index.js');
|
|
5
5
|
const isNumber = require('./utils/is-number.js');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {isSemicolonToken} = require('eslint-utils');
|
|
2
|
+
const {isSemicolonToken} = require('@eslint-community/eslint-utils');
|
|
3
3
|
const getClassHeadLocation = require('./utils/get-class-head-location.js');
|
|
4
4
|
const assertToken = require('./utils/assert-token.js');
|
|
5
5
|
const {removeSpacesAfter} = require('./fix/index.js');
|
package/rules/no-thenable.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {getStaticValue, getPropertyName} = require('eslint-utils');
|
|
2
|
+
const {getStaticValue, getPropertyName} = require('@eslint-community/eslint-utils');
|
|
3
3
|
const {methodCallSelector} = require('./selectors/index.js');
|
|
4
4
|
|
|
5
5
|
const MESSAGE_ID_OBJECT = 'no-thenable-object';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {isParenthesized} = require('eslint-utils');
|
|
2
|
+
const {isParenthesized} = require('@eslint-community/eslint-utils');
|
|
3
3
|
const shouldAddParenthesesToMemberExpressionObject = require('./utils/should-add-parentheses-to-member-expression-object.js');
|
|
4
4
|
const {fixSpaceAroundKeyword} = require('./fix/index.js');
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {isCommaToken} = require('eslint-utils');
|
|
2
|
+
const {isCommaToken} = require('@eslint-community/eslint-utils');
|
|
3
3
|
const {
|
|
4
4
|
matches,
|
|
5
5
|
newExpressionSelector,
|
|
@@ -15,6 +15,7 @@ const isOnSameLine = require('./utils/is-on-same-line.js');
|
|
|
15
15
|
const {
|
|
16
16
|
isParenthesized,
|
|
17
17
|
} = require('./utils/parentheses.js');
|
|
18
|
+
const {isNewExpression} = require('./ast/index.js');
|
|
18
19
|
|
|
19
20
|
const SPREAD_IN_LIST = 'spread-in-list';
|
|
20
21
|
const ITERABLE_TO_ARRAY = 'iterable-to-array';
|
|
@@ -279,11 +280,28 @@ const create = context => {
|
|
|
279
280
|
},
|
|
280
281
|
[uselessArrayCloneSelector](node) {
|
|
281
282
|
const arrayExpression = node.parent.parent;
|
|
282
|
-
|
|
283
|
+
const problem = {
|
|
283
284
|
node: arrayExpression,
|
|
284
285
|
messageId: CLONE_ARRAY,
|
|
285
|
-
fix: fixer => unwrapSingleArraySpread(fixer, arrayExpression, sourceCode),
|
|
286
286
|
};
|
|
287
|
+
|
|
288
|
+
if (
|
|
289
|
+
// `[...new Array(1)]` -> `new Array(1)` is not safe to fix since there are holes
|
|
290
|
+
isNewExpression(node, {name: 'Array'})
|
|
291
|
+
// `[...foo.slice(1)]` -> `foo.slice(1)` is not safe to fix since `foo` can be a string
|
|
292
|
+
|| (
|
|
293
|
+
node.type === 'CallExpression'
|
|
294
|
+
&& node.callee.type === 'MemberExpression'
|
|
295
|
+
&& node.callee.property.type === 'Identifier'
|
|
296
|
+
&& node.callee.property.name === 'slice'
|
|
297
|
+
)
|
|
298
|
+
) {
|
|
299
|
+
return problem;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return Object.assign(problem, {
|
|
303
|
+
fix: fixer => unwrapSingleArraySpread(fixer, arrayExpression, sourceCode),
|
|
304
|
+
});
|
|
287
305
|
},
|
|
288
306
|
};
|
|
289
307
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {isParenthesized} = require('eslint-utils');
|
|
2
|
+
const {isParenthesized} = require('@eslint-community/eslint-utils');
|
|
3
3
|
const needsSemicolon = require('./utils/needs-semicolon.js');
|
|
4
4
|
const {isDecimalInteger} = require('./utils/numeric.js');
|
|
5
5
|
const toLocation = require('./utils/to-location.js');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {isParenthesized} = require('eslint-utils');
|
|
2
|
+
const {isParenthesized} = require('@eslint-community/eslint-utils');
|
|
3
3
|
const eventTypes = require('./shared/dom-events.js');
|
|
4
4
|
const {STATIC_REQUIRE_SOURCE_SELECTOR} = require('./selectors/index.js');
|
|
5
5
|
const {isUndefined, isNullLiteral} = require('./ast/index.js');
|
package/rules/prefer-at.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {isOpeningBracketToken, isClosingBracketToken, getStaticValue} = require('eslint-utils');
|
|
2
|
+
const {isOpeningBracketToken, isClosingBracketToken, getStaticValue} = require('@eslint-community/eslint-utils');
|
|
3
3
|
const {
|
|
4
4
|
isParenthesized,
|
|
5
5
|
getParenthesizedRange,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {isParenthesized, hasSideEffect} = require('eslint-utils');
|
|
2
|
+
const {isParenthesized, hasSideEffect} = require('@eslint-community/eslint-utils');
|
|
3
3
|
const {methodCallSelector, notDomNodeSelector} = require('./selectors/index.js');
|
|
4
4
|
const needsSemicolon = require('./utils/needs-semicolon.js');
|
|
5
5
|
const isValueNotUsable = require('./utils/is-value-not-usable.js');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {findVariable, getStaticValue, getPropertyName} = require('eslint-utils');
|
|
2
|
+
const {findVariable, getStaticValue, getPropertyName} = require('@eslint-community/eslint-utils');
|
|
3
3
|
const {methodCallSelector} = require('./selectors/index.js');
|
|
4
4
|
const {removeArgument} = require('./fix/index.js');
|
|
5
5
|
|
package/rules/prefer-module.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {isOpeningParenToken} = require('eslint-utils');
|
|
2
|
+
const {isOpeningParenToken} = require('@eslint-community/eslint-utils');
|
|
3
3
|
const isShadowed = require('./utils/is-shadowed.js');
|
|
4
4
|
const assertToken = require('./utils/assert-token.js');
|
|
5
5
|
const {referenceIdentifierSelector} = require('./selectors/index.js');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {getFunctionHeadLocation, getFunctionNameWithKind} = require('eslint-utils');
|
|
2
|
+
const {getFunctionHeadLocation, getFunctionNameWithKind} = require('@eslint-community/eslint-utils');
|
|
3
3
|
const {not} = require('./selectors/index.js');
|
|
4
4
|
|
|
5
5
|
const MESSAGE_ID = 'prefer-native-coercion-functions';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {isCommaToken, isArrowToken, isClosingParenToken} = require('eslint-utils');
|
|
2
|
+
const {isCommaToken, isArrowToken, isClosingParenToken} = require('@eslint-community/eslint-utils');
|
|
3
3
|
const getDocumentationUrl = require('./utils/get-documentation-url.js');
|
|
4
4
|
const {matches, methodCallSelector} = require('./selectors/index.js');
|
|
5
5
|
const {removeParentheses} = require('./fix/index.js');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {isOpeningParenToken, isClosingParenToken} = require('eslint-utils');
|
|
2
|
+
const {isOpeningParenToken, isClosingParenToken} = require('@eslint-community/eslint-utils');
|
|
3
3
|
const assertToken = require('./utils/assert-token.js');
|
|
4
4
|
|
|
5
5
|
const MESSAGE_ID_WITH_NAME = 'with-name';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {isParenthesized, getStaticValue} = require('eslint-utils');
|
|
2
|
+
const {isParenthesized, getStaticValue} = require('@eslint-community/eslint-utils');
|
|
3
3
|
const {checkVueTemplate} = require('./utils/rule.js');
|
|
4
4
|
const {methodCallSelector} = require('./selectors/index.js');
|
|
5
5
|
const {isRegexLiteral, isNewExpression} = require('./ast/index.js');
|
package/rules/prefer-set-has.js
CHANGED
package/rules/prefer-set-size.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {findVariable} = require('eslint-utils');
|
|
2
|
+
const {findVariable} = require('@eslint-community/eslint-utils');
|
|
3
3
|
const {memberExpressionSelector} = require('./selectors/index.js');
|
|
4
4
|
const {fixSpaceAroundKeyword} = require('./fix/index.js');
|
|
5
5
|
const {isNewExpression} = require('./ast/index.js');
|
package/rules/prefer-spread.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {isParenthesized, getStaticValue, isCommaToken, hasSideEffect} = require('eslint-utils');
|
|
2
|
+
const {isParenthesized, getStaticValue, isCommaToken, hasSideEffect} = require('@eslint-community/eslint-utils');
|
|
3
3
|
const {methodCallSelector} = require('./selectors/index.js');
|
|
4
4
|
const needsSemicolon = require('./utils/needs-semicolon.js');
|
|
5
5
|
const {getParenthesizedRange, getParenthesizedText} = require('./utils/parentheses.js');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {getStaticValue} = require('eslint-utils');
|
|
2
|
+
const {getStaticValue} = require('@eslint-community/eslint-utils');
|
|
3
3
|
const {parse: parseRegExp} = require('regjsparser');
|
|
4
4
|
const escapeString = require('./utils/escape-string.js');
|
|
5
5
|
const {methodCallSelector} = require('./selectors/index.js');
|
|
@@ -27,11 +27,17 @@ function getPatternReplacement(node) {
|
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
let tree;
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
tree = parseRegExp(pattern, flags, {
|
|
34
|
+
unicodePropertyEscape: true,
|
|
35
|
+
namedGroups: true,
|
|
36
|
+
lookbehind: true,
|
|
37
|
+
});
|
|
38
|
+
} catch {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
35
41
|
|
|
36
42
|
const parts = tree.type === 'alternative' ? tree.body : [tree];
|
|
37
43
|
if (parts.some(part => part.type !== 'value')) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {getStaticValue} = require('eslint-utils');
|
|
2
|
+
const {getStaticValue} = require('@eslint-community/eslint-utils');
|
|
3
3
|
const {getParenthesizedText, getParenthesizedRange} = require('./utils/parentheses.js');
|
|
4
4
|
const {methodCallSelector} = require('./selectors/index.js');
|
|
5
5
|
const isNumber = require('./utils/is-number.js');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {isParenthesized, getStaticValue} = require('eslint-utils');
|
|
2
|
+
const {isParenthesized, getStaticValue} = require('@eslint-community/eslint-utils');
|
|
3
3
|
const {methodCallSelector} = require('./selectors/index.js');
|
|
4
4
|
const escapeString = require('./utils/escape-string.js');
|
|
5
5
|
const shouldAddParenthesesToMemberExpressionObject = require('./utils/should-add-parentheses-to-member-expression-object.js');
|
package/rules/prefer-switch.js
CHANGED
package/rules/prefer-ternary.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {isParenthesized} = require('eslint-utils');
|
|
2
|
+
const {isParenthesized} = require('@eslint-community/eslint-utils');
|
|
3
3
|
const avoidCapture = require('./utils/avoid-capture.js');
|
|
4
4
|
const needsSemicolon = require('./utils/needs-semicolon.js');
|
|
5
5
|
const isSameReference = require('./utils/is-same-reference.js');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {findVariable, getFunctionHeadLocation} = require('eslint-utils');
|
|
2
|
+
const {findVariable, getFunctionHeadLocation} = require('@eslint-community/eslint-utils');
|
|
3
3
|
const {matches, not, memberExpressionSelector} = require('./selectors/index.js');
|
|
4
4
|
|
|
5
5
|
const ERROR_PROMISE = 'promise';
|
|
@@ -448,7 +448,12 @@ const create = context => {
|
|
|
448
448
|
node: definition.name,
|
|
449
449
|
};
|
|
450
450
|
|
|
451
|
-
if (
|
|
451
|
+
if (
|
|
452
|
+
variableReplacements.total === 1
|
|
453
|
+
&& shouldFix(variable)
|
|
454
|
+
&& variableReplacements.samples[0]
|
|
455
|
+
&& !variable.references.some(reference => reference.vueUsedInTemplate)
|
|
456
|
+
) {
|
|
452
457
|
const [replacement] = variableReplacements.samples;
|
|
453
458
|
|
|
454
459
|
for (const scope of scopes) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {hasSideEffect, isParenthesized, findVariable} = require('eslint-utils');
|
|
3
|
+
const {hasSideEffect, isParenthesized, findVariable} = require('@eslint-community/eslint-utils');
|
|
4
4
|
const {matches, methodCallSelector} = require('../selectors/index.js');
|
|
5
5
|
const isFunctionSelfUsedInside = require('../utils/is-function-self-used-inside.js');
|
|
6
6
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {isColonToken} = require('eslint-utils');
|
|
2
|
+
const {isColonToken} = require('@eslint-community/eslint-utils');
|
|
3
3
|
const getSwitchCaseHeadLocation = require('./utils/get-switch-case-head-location.js');
|
|
4
4
|
const getIndentString = require('./utils/get-indent-string.js');
|
|
5
5
|
const {replaceNodeOrTokenAndSpacesBefore} = require('./fix/index.js');
|
package/rules/utils/is-number.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const {isParenthesized, isOpeningParenToken, isClosingParenToken} = require('eslint-utils');
|
|
2
|
+
const {isParenthesized, isOpeningParenToken, isClosingParenToken} = require('@eslint-community/eslint-utils');
|
|
3
3
|
|
|
4
4
|
/*
|
|
5
5
|
Get how many times the node is parenthesized.
|
|
@@ -9,11 +9,6 @@ Get how many times the node is parenthesized.
|
|
|
9
9
|
@returns {number}
|
|
10
10
|
*/
|
|
11
11
|
function getParenthesizedTimes(node, sourceCode) {
|
|
12
|
-
// Workaround for https://github.com/mysticatea/eslint-utils/pull/25
|
|
13
|
-
if (!node.parent) {
|
|
14
|
-
return 0;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
12
|
let times = 0;
|
|
18
13
|
|
|
19
14
|
while (isParenthesized(times + 1, node, sourceCode)) {
|