@putout/plugin-remove-useless-escape 7.0.0 → 9.0.0

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/README.md CHANGED
@@ -27,7 +27,6 @@ npm i @putout/plugin-remove-useless-escape
27
27
  const t = 'hello \"world\"';
28
28
  const s1 = `hello \"world\"`;
29
29
  const s = `hello \'world\'`;
30
- const reg = /\w\:/g;
31
30
  ```
32
31
 
33
32
  ## ✅ Example of correct code
@@ -36,7 +35,6 @@ const reg = /\w\:/g;
36
35
  const t = 'hello "world"';
37
36
  const s1 = `hello "world"`;
38
37
  const s = `hello 'world'`;
39
- const reg = /\w:/g;
40
38
  ```
41
39
 
42
40
  ## Comparison
@@ -1,16 +1,8 @@
1
- 'use strict';
1
+ import emojiRegex from 'emoji-regex';
2
2
 
3
- const emojiRegex = require('emoji-regex');
3
+ export const report = () => 'Unnecessary escape character';
4
4
 
5
- const {types, operator} = require('putout');
6
-
7
- const {replaceWith} = operator;
8
- const {RegExpLiteral} = types;
9
- const {assign} = Object;
10
-
11
- module.exports.report = () => 'Unnecessary escape character';
12
-
13
- module.exports.fix = (path) => {
5
+ export const fix = (path) => {
14
6
  if (path.isStringLiteral()) {
15
7
  const {raw} = path.node;
16
8
 
@@ -19,38 +11,13 @@ module.exports.fix = (path) => {
19
11
  return;
20
12
  }
21
13
 
22
- if (path.isRegExpLiteral()) {
23
- const {pattern, flags} = path.node;
24
-
25
- const unescaped = unescapeRegExp(pattern);
26
- const raw = `/${unescaped}/`;
27
-
28
- const regExpNode = assign(RegExpLiteral(unescaped, flags), {
29
- value: unescaped,
30
- raw,
31
- extra: {
32
- raw,
33
- rawValue: unescaped,
34
- },
35
- });
36
-
37
- replaceWith(path, regExpNode);
38
- return;
39
- }
40
-
41
14
  for (const tmpl of path.node.quasis) {
42
15
  const {raw} = tmpl.value;
43
16
  tmpl.value.raw = unEscape(raw);
44
17
  }
45
18
  };
46
19
 
47
- module.exports.traverse = ({push}) => ({
48
- 'RegExpLiteral'(path) {
49
- const {raw} = path.node;
50
-
51
- if (isEscapedRegExp(raw))
52
- push(path);
53
- },
20
+ export const traverse = ({push}) => ({
54
21
  '"__"'(path) {
55
22
  const {raw} = path.node;
56
23
 
@@ -155,24 +122,3 @@ function unEscape(raw) {
155
122
 
156
123
  return raw;
157
124
  }
158
-
159
- const unescapeRegExp = (raw) => raw
160
- .replaceAll('\\:', ':')
161
- .replaceAll('\\+\\/', '+/')
162
- .replaceAll('\\,', ',')
163
- .replaceAll('\\`', '`');
164
-
165
- const is = (a) => (b) => b.includes(`\\${a}`) && !b.includes(`\\\\${a}`);
166
- const isRegExpColon = is(':');
167
- const isComa = is(',');
168
- const isRegExpSlash = (a) => a.includes('\\\\\\\\');
169
-
170
- function isEscapedRegExp(raw) {
171
- if (raw.includes('\\/'))
172
- return false;
173
-
174
- if (raw.includes('\\`'))
175
- return true;
176
-
177
- return isRegExpColon(raw) || isRegExpSlash(raw) || isComa(raw);
178
- }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@putout/plugin-remove-useless-escape",
3
- "version": "7.0.0",
4
- "type": "commonjs",
3
+ "version": "9.0.0",
4
+ "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin adds ability to find and remove useless escape",
7
7
  "homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-useless-escape#readme",
@@ -36,22 +36,22 @@
36
36
  "escape"
37
37
  ],
38
38
  "devDependencies": {
39
- "@putout/eslint-flat": "^2.0.0",
39
+ "@putout/eslint-flat": "^3.0.0",
40
40
  "@putout/plugin-madrun": "*",
41
41
  "@putout/plugin-regexp": "*",
42
- "@putout/test": "^12.0.0",
42
+ "@putout/test": "^14.0.0",
43
43
  "c8": "^10.0.0",
44
- "eslint": "^9.0.0",
44
+ "eslint": "v10.0.0-alpha.0",
45
45
  "eslint-plugin-n": "^17.0.0",
46
- "eslint-plugin-putout": "^25.0.1",
47
- "madrun": "^10.0.0"
46
+ "eslint-plugin-putout": "^29.0.0",
47
+ "madrun": "^11.0.0"
48
48
  },
49
49
  "peerDependencies": {
50
- "putout": ">=38"
50
+ "putout": ">=41"
51
51
  },
52
52
  "license": "MIT",
53
53
  "engines": {
54
- "node": ">=18"
54
+ "node": ">=20"
55
55
  },
56
56
  "publishConfig": {
57
57
  "access": "public"