eslint-plugin-unicorn 45.0.1 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-unicorn",
3
- "version": "45.0.1",
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,7 +47,7 @@
47
47
  ],
48
48
  "dependencies": {
49
49
  "@babel/helper-validator-identifier": "^7.19.1",
50
- "@eslint-community/eslint-utils": "^4.1.0",
50
+ "@eslint-community/eslint-utils": "^4.1.2",
51
51
  "ci-info": "^3.6.1",
52
52
  "clean-regexp": "^1.0.0",
53
53
  "esquery": "^1.4.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
 
@@ -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')) {
@@ -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) {
@@ -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)) {