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.
Files changed (64) hide show
  1. package/package.json +5 -5
  2. package/readme.md +3 -1
  3. package/rules/better-regex.js +3 -1
  4. package/rules/catch-error-name.js +1 -1
  5. package/rules/consistent-function-scoping.js +1 -1
  6. package/rules/empty-brace-spaces.js +1 -1
  7. package/rules/error-message.js +1 -1
  8. package/rules/explicit-length-check.js +1 -1
  9. package/rules/fix/add-parenthesizes-to-return-or-throw-expression.js +1 -1
  10. package/rules/fix/append-argument.js +1 -1
  11. package/rules/fix/remove-argument.js +1 -1
  12. package/rules/import-style.js +1 -1
  13. package/rules/no-array-callback-reference.js +1 -1
  14. package/rules/no-array-for-each.js +1 -1
  15. package/rules/no-array-method-this-argument.js +1 -1
  16. package/rules/no-array-push-push.js +1 -1
  17. package/rules/no-for-loop.js +1 -1
  18. package/rules/no-invalid-remove-event-listener.js +1 -1
  19. package/rules/no-lonely-if.js +1 -1
  20. package/rules/no-nested-ternary.js +1 -1
  21. package/rules/no-new-array.js +1 -1
  22. package/rules/no-new-buffer.js +1 -1
  23. package/rules/no-static-only-class.js +1 -1
  24. package/rules/no-thenable.js +1 -1
  25. package/rules/no-unreadable-array-destructuring.js +1 -1
  26. package/rules/no-useless-spread.js +21 -3
  27. package/rules/no-useless-undefined.js +1 -1
  28. package/rules/no-zero-fractions.js +1 -1
  29. package/rules/prefer-add-event-listener.js +1 -1
  30. package/rules/prefer-array-find.js +1 -1
  31. package/rules/prefer-at.js +1 -1
  32. package/rules/prefer-default-parameters.js +1 -1
  33. package/rules/prefer-dom-node-remove.js +1 -1
  34. package/rules/prefer-export-from.js +1 -1
  35. package/rules/prefer-json-parse-buffer.js +1 -1
  36. package/rules/prefer-math-trunc.js +1 -1
  37. package/rules/prefer-module.js +1 -1
  38. package/rules/prefer-native-coercion-functions.js +1 -1
  39. package/rules/prefer-object-from-entries.js +1 -1
  40. package/rules/prefer-optional-catch-binding.js +1 -1
  41. package/rules/prefer-prototype-methods.js +1 -1
  42. package/rules/prefer-reflect-apply.js +1 -1
  43. package/rules/prefer-regexp-test.js +1 -1
  44. package/rules/prefer-set-has.js +1 -1
  45. package/rules/prefer-set-size.js +1 -1
  46. package/rules/prefer-spread.js +1 -1
  47. package/rules/prefer-string-replace-all.js +12 -6
  48. package/rules/prefer-string-slice.js +1 -1
  49. package/rules/prefer-string-starts-ends-with.js +1 -1
  50. package/rules/prefer-switch.js +1 -1
  51. package/rules/prefer-ternary.js +1 -1
  52. package/rules/prefer-top-level-await.js +1 -1
  53. package/rules/prevent-abbreviations.js +6 -1
  54. package/rules/relative-url-style.js +1 -1
  55. package/rules/shared/simple-array-search-rule.js +1 -1
  56. package/rules/switch-case-braces.js +1 -1
  57. package/rules/utils/get-call-expression-arguments-text.js +1 -1
  58. package/rules/utils/get-switch-case-head-location.js +1 -1
  59. package/rules/utils/global-reference-tracker.js +1 -1
  60. package/rules/utils/is-function-self-used-inside.js +1 -1
  61. package/rules/utils/is-new-expression-with-parentheses.js +1 -1
  62. package/rules/utils/is-number.js +1 -1
  63. package/rules/utils/is-same-reference.js +1 -1
  64. 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.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.24.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 rules in `package.json`.
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
  {
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  'use strict';
2
- const {isOpeningBraceToken} = require('eslint-utils');
2
+ const {isOpeningBraceToken} = require('@eslint-community/eslint-utils');
3
3
  const {matches} = require('./selectors/index.js');
4
4
 
5
5
  const MESSAGE_ID = 'empty-brace-spaces';
@@ -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 isShadowed = require('./utils/is-shadowed.js');
4
4
  const {callOrNewExpressionSelector} = require('./selectors/index.js');
5
5
 
@@ -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') {
@@ -1,5 +1,5 @@
1
1
  'use strict';
2
- const {isCommaToken} = require('eslint-utils');
2
+ const {isCommaToken} = require('@eslint-community/eslint-utils');
3
3
 
4
4
  function appendArgument(fixer, node, text, sourceCode) {
5
5
  // This function should also work for `NewExpression`
@@ -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 {getParentheses} = require('../utils/parentheses.js');
4
4
 
5
5
  function removeArgument(fixer, node, sourceCode) {
@@ -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');
@@ -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
 
@@ -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');
@@ -1,5 +1,5 @@
1
1
  'use strict';
2
- const {isParenthesized} = require('eslint-utils');
2
+ const {isParenthesized} = require('@eslint-community/eslint-utils');
3
3
 
4
4
  const MESSAGE_ID_TOO_DEEP = 'too-deep';
5
5
  const MESSAGE_ID_SHOULD_PARENTHESIZED = 'should-parenthesized';
@@ -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');
@@ -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');
@@ -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
- return {
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 {isCommaToken} = require('eslint-utils');
2
+ const {isCommaToken} = require('@eslint-community/eslint-utils');
3
3
  const {replaceNodeOrTokenAndSpacesBefore} = require('./fix/index.js');
4
4
  const {isUndefined} = require('./ast/index.js');
5
5
 
@@ -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');
@@ -1,5 +1,5 @@
1
1
  'use strict';
2
- const {isParenthesized, findVariable} = require('eslint-utils');
2
+ const {isParenthesized, findVariable} = require('@eslint-community/eslint-utils');
3
3
  const {
4
4
  not,
5
5
  methodCallSelector,
@@ -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 {findVariable} = require('eslint-utils');
2
+ const {findVariable} = require('@eslint-community/eslint-utils');
3
3
 
4
4
  const MESSAGE_ID = 'preferDefaultParameters';
5
5
  const MESSAGE_ID_SUGGEST = 'preferDefaultParametersSuggest';
@@ -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');
@@ -3,7 +3,7 @@ const {
3
3
  isCommaToken,
4
4
  isOpeningBraceToken,
5
5
  isClosingBraceToken,
6
- } = require('eslint-utils');
6
+ } = require('@eslint-community/eslint-utils');
7
7
 
8
8
  const MESSAGE_ID_ERROR = 'error';
9
9
  const MESSAGE_ID_SUGGESTION = 'suggestion';
@@ -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
 
@@ -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 {fixSpaceAroundKeyword} = require('./fix/index.js');
4
4
 
5
5
  const ERROR_BITWISE = 'error-bitwise';
@@ -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 {getPropertyName} = require('eslint-utils');
2
+ const {getPropertyName} = require('@eslint-community/eslint-utils');
3
3
  const {
4
4
  methodCallSelector,
5
5
  emptyObjectSelector,
@@ -1,5 +1,5 @@
1
1
  'use strict';
2
- const {getPropertyName} = require('eslint-utils');
2
+ const {getPropertyName} = require('@eslint-community/eslint-utils');
3
3
  const {not, methodCallSelector} = require('./selectors/index.js');
4
4
  const {isNullLiteral} = require('./ast/index.js');
5
5
 
@@ -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');
@@ -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 getVariableIdentifiers = require('./utils/get-variable-identifiers.js');
4
4
  const {
5
5
  matches,
@@ -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');
@@ -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
- const tree = parseRegExp(pattern, flags, {
31
- unicodePropertyEscape: true,
32
- namedGroups: true,
33
- lookbehind: true,
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');
@@ -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 isSameReference = require('./utils/is-same-reference.js');
4
4
  const getIndentString = require('./utils/get-indent-string.js');
5
5
 
@@ -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 (variableReplacements.total === 1 && shouldFix(variable) && variableReplacements.samples[0]) {
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,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 {replaceStringLiteral} = require('./fix/index.js');
5
5
 
@@ -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');
@@ -1,5 +1,5 @@
1
1
  'use strict';
2
- const {isOpeningParenToken} = require('eslint-utils');
2
+ const {isOpeningParenToken} = require('@eslint-community/eslint-utils');
3
3
 
4
4
  /**
5
5
  Get the text of the arguments list of `CallExpression`.
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const {isColonToken} = require('eslint-utils');
3
+ const {isColonToken} = require('@eslint-community/eslint-utils');
4
4
 
5
5
  /**
6
6
  @typedef {line: number, column: number} Position
@@ -1,5 +1,5 @@
1
1
  'use strict';
2
- const {ReferenceTracker} = require('eslint-utils');
2
+ const {ReferenceTracker} = require('@eslint-community/eslint-utils');
3
3
 
4
4
  const createTraceMap = (object, type) => {
5
5
  let map = {[type]: true};
@@ -1,5 +1,5 @@
1
1
  'use strict';
2
- const {findVariable} = require('eslint-utils');
2
+ const {findVariable} = require('@eslint-community/eslint-utils');
3
3
 
4
4
  const getReferences = (scope, nodeOrName) => {
5
5
  const {references = []} = findVariable(scope, nodeOrName) || {};
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const {isOpeningParenToken, isClosingParenToken} = require('eslint-utils');
3
+ const {isOpeningParenToken, isClosingParenToken} = require('@eslint-community/eslint-utils');
4
4
 
5
5
  /**
6
6
  Determine if a constructor function is newed-up with parens.
@@ -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 {isNumberLiteral} = require('../ast/index.js');
4
4
 
5
5
  const isStaticProperties = (node, object, properties) =>
@@ -1,5 +1,5 @@
1
1
  'use strict';
2
- const {getStaticValue} = require('eslint-utils');
2
+ const {getStaticValue} = require('@eslint-community/eslint-utils');
3
3
 
4
4
  // Copied from https://github.com/eslint/eslint/blob/94ba68d76a6940f68ff82eea7332c6505f93df76/lib/rules/utils/ast-utils.js#L392
5
5
 
@@ -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)) {