@putout/plugin-remove-useless-escape 2.1.0 → 3.1.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/README.md +3 -3
- package/lib/remove-useless-escape.js +18 -7
- package/package.json +9 -8
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-remove-useless-escape.svg?style=flat&longCache=true
|
|
4
4
|
[NPMURL]: https://npmjs.org/package/@putout/plugin-remove-useless-escape"npm"
|
|
5
5
|
|
|
6
|
-
🐊[
|
|
6
|
+
🐊[**Putout**](https://github.com/coderaiser/putout) plugin adds ability to find and remove useless escape.
|
|
7
7
|
|
|
8
8
|
## Install
|
|
9
9
|
|
|
@@ -21,7 +21,7 @@ npm i @putout/plugin-remove-useless-escape
|
|
|
21
21
|
}
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
## ❌
|
|
24
|
+
## ❌ Example of incorrect code
|
|
25
25
|
|
|
26
26
|
```js
|
|
27
27
|
const t = 'hello \"world\"';
|
|
@@ -30,7 +30,7 @@ const s = `hello \'world\'`;
|
|
|
30
30
|
const reg = /\w\:/g;
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
## ✅
|
|
33
|
+
## ✅ Example of correct code
|
|
34
34
|
|
|
35
35
|
```js
|
|
36
36
|
const t = 'hello "world"';
|
|
@@ -47,8 +47,9 @@ module.exports.traverse = ({push}) => ({
|
|
|
47
47
|
'RegExpLiteral'(path) {
|
|
48
48
|
const {raw} = path.node;
|
|
49
49
|
|
|
50
|
-
if (isEscapedRegExp(raw))
|
|
50
|
+
if (isEscapedRegExp(raw)) {
|
|
51
51
|
push(path);
|
|
52
|
+
}
|
|
52
53
|
},
|
|
53
54
|
'"__"'(path) {
|
|
54
55
|
const {raw} = path.node;
|
|
@@ -97,6 +98,12 @@ function isEscaped(raw) {
|
|
|
97
98
|
if (!raw.includes('\\'))
|
|
98
99
|
return false;
|
|
99
100
|
|
|
101
|
+
if (/\\\\/g.test(raw))
|
|
102
|
+
return false;
|
|
103
|
+
|
|
104
|
+
if (/\\\//g.test(raw))
|
|
105
|
+
return true;
|
|
106
|
+
|
|
100
107
|
if (raw.includes('\\+') && !raw.includes('\\\\+'))
|
|
101
108
|
return true;
|
|
102
109
|
|
|
@@ -119,10 +126,11 @@ const createEncodedRegExp = (a) => RegExp(`\\\\${a}`, 'g');
|
|
|
119
126
|
|
|
120
127
|
function unEscape(raw) {
|
|
121
128
|
raw = raw
|
|
122
|
-
.
|
|
123
|
-
.
|
|
129
|
+
.replaceAll('\\\'', `'`)
|
|
130
|
+
.replaceAll('\\/', '/')
|
|
131
|
+
.replaceAll('\\+', '+')
|
|
124
132
|
.replace(createEncodedRegExp(`"`), '"')
|
|
125
|
-
.
|
|
133
|
+
.replaceAll('\\^', '^')
|
|
126
134
|
.replace(/(\\),/, ',');
|
|
127
135
|
|
|
128
136
|
for (const emoji of match(raw)) {
|
|
@@ -134,9 +142,9 @@ function unEscape(raw) {
|
|
|
134
142
|
|
|
135
143
|
function unescapeRegExp(raw) {
|
|
136
144
|
return raw
|
|
137
|
-
.
|
|
138
|
-
.
|
|
139
|
-
.
|
|
145
|
+
.replaceAll('\\:', ':')
|
|
146
|
+
.replaceAll('\\+\\/', '+/')
|
|
147
|
+
.replaceAll('\\,', ',');
|
|
140
148
|
}
|
|
141
149
|
|
|
142
150
|
const is = (a) => (b) => b.includes(`\\${a}`) && !b.includes(`\\\\${a}`);
|
|
@@ -145,6 +153,9 @@ const isComa = is(',');
|
|
|
145
153
|
const isRegExpSlash = (a) => a.includes('\\\\\\\\');
|
|
146
154
|
|
|
147
155
|
function isEscapedRegExp(raw) {
|
|
156
|
+
if (raw.includes('\\/'))
|
|
157
|
+
return false;
|
|
158
|
+
|
|
148
159
|
return isRegExpColon(raw) || isRegExpSlash(raw) || isComa(raw);
|
|
149
160
|
}
|
|
150
161
|
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-remove-useless-escape",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.1",
|
|
4
|
+
"type": "commonjs",
|
|
4
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
5
6
|
"description": "putout plugin adds ability to find and remove useless escape",
|
|
6
|
-
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-useless-escape",
|
|
7
|
+
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-useless-escape#readme",
|
|
7
8
|
"main": "lib/remove-useless-escape.js",
|
|
8
9
|
"release": false,
|
|
9
10
|
"tag": false,
|
|
@@ -23,7 +24,7 @@
|
|
|
23
24
|
"report": "madrun report"
|
|
24
25
|
},
|
|
25
26
|
"dependencies": {
|
|
26
|
-
"emoji-regex": "^
|
|
27
|
+
"emoji-regex": "^10.0.1"
|
|
27
28
|
},
|
|
28
29
|
"keywords": [
|
|
29
30
|
"putout",
|
|
@@ -36,19 +37,19 @@
|
|
|
36
37
|
],
|
|
37
38
|
"devDependencies": {
|
|
38
39
|
"@putout/plugin-madrun": "*",
|
|
39
|
-
"@putout/test": "^
|
|
40
|
+
"@putout/test": "^5.0.0",
|
|
40
41
|
"c8": "^7.5.0",
|
|
41
42
|
"eslint": "^8.0.1",
|
|
42
43
|
"eslint-plugin-node": "^11.0.0",
|
|
43
|
-
"eslint-plugin-putout": "^
|
|
44
|
-
"madrun": "^
|
|
44
|
+
"eslint-plugin-putout": "^14.0.0",
|
|
45
|
+
"madrun": "^9.0.0"
|
|
45
46
|
},
|
|
46
47
|
"peerDependencies": {
|
|
47
|
-
"putout": ">=
|
|
48
|
+
"putout": ">=25"
|
|
48
49
|
},
|
|
49
50
|
"license": "MIT",
|
|
50
51
|
"engines": {
|
|
51
|
-
"node": ">=
|
|
52
|
+
"node": ">=16"
|
|
52
53
|
},
|
|
53
54
|
"publishConfig": {
|
|
54
55
|
"access": "public"
|