@putout/plugin-remove-useless-escape 1.7.0 → 2.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 +1 -1
- package/lib/remove-useless-escape.js +11 -3
- package/package.json +5 -5
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
|
-
`putout
|
|
6
|
+
🐊[`Putout`](https://github.com/coderaiser/putout) plugin adds ability to find and remove useless escape.
|
|
7
7
|
|
|
8
8
|
## Install
|
|
9
9
|
|
|
@@ -22,6 +22,7 @@ module.exports.fix = (path) => {
|
|
|
22
22
|
if (path.isRegExpLiteral()) {
|
|
23
23
|
const {pattern, flags} = path.node;
|
|
24
24
|
const unescaped = unescapeRegExp(pattern);
|
|
25
|
+
|
|
25
26
|
const regExpNode = assign(RegExpLiteral(unescaped, flags), {
|
|
26
27
|
value: unescaped,
|
|
27
28
|
extra: {
|
|
@@ -76,6 +77,7 @@ const match = (a) => a.match(emojiRegex()) || [];
|
|
|
76
77
|
const hasA = (a) => /\\\^/.test(a);
|
|
77
78
|
const hasDoubleQuote = (a) => createCheckRegExp('"').test(a);
|
|
78
79
|
const hasQuote = (a) => createCheckRegExp(`'`).test(a);
|
|
80
|
+
const hasComa = (a) => createCheckRegExp(',').test(a);
|
|
79
81
|
|
|
80
82
|
const hasEmoji = (a) => {
|
|
81
83
|
for (const emoji of match(a)) {
|
|
@@ -105,6 +107,9 @@ function isEscaped(raw) {
|
|
|
105
107
|
if (hasA(raw))
|
|
106
108
|
return true;
|
|
107
109
|
|
|
110
|
+
if (hasComa(raw))
|
|
111
|
+
return true;
|
|
112
|
+
|
|
108
113
|
return false;
|
|
109
114
|
}
|
|
110
115
|
|
|
@@ -115,7 +120,8 @@ function unEscape(raw) {
|
|
|
115
120
|
.replace(/\\'/g, `'`)
|
|
116
121
|
.replace(/\\\+/g, '+')
|
|
117
122
|
.replace(createEncodedRegExp(`"`), '"')
|
|
118
|
-
.replace(/\\\^/g, '^')
|
|
123
|
+
.replace(/\\\^/g, '^')
|
|
124
|
+
.replace(/(\\),/g, ',');
|
|
119
125
|
|
|
120
126
|
for (const emoji of match(raw)) {
|
|
121
127
|
raw = raw.replace(createEncodedRegExp(emoji), emoji);
|
|
@@ -127,13 +133,15 @@ function unEscape(raw) {
|
|
|
127
133
|
function unescapeRegExp(raw) {
|
|
128
134
|
return raw
|
|
129
135
|
.replace(/\\:/g, ':')
|
|
130
|
-
.replace(/\+\\\//g, '+/')
|
|
136
|
+
.replace(/\+\\\//g, '+/')
|
|
137
|
+
.replace(/(\\),/g, ',');
|
|
131
138
|
}
|
|
132
139
|
|
|
133
140
|
const isRegExpColon = (a) => /\\:/.test(a) && !/\\\\:/.test(a);
|
|
134
141
|
const isRegExpSlash = (a) => /\+\\\//.test(a);
|
|
142
|
+
const isComa = (a) => /(\\),/.test(a);
|
|
135
143
|
|
|
136
144
|
function isEscapedRegExp(raw) {
|
|
137
|
-
return isRegExpColon(raw) || isRegExpSlash(raw);
|
|
145
|
+
return isRegExpColon(raw) || isRegExpSlash(raw) || isComa(raw);
|
|
138
146
|
}
|
|
139
147
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-remove-useless-escape",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
5
5
|
"description": "putout plugin adds ability to find and remove useless escape",
|
|
6
6
|
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-useless-escape",
|
|
@@ -36,19 +36,19 @@
|
|
|
36
36
|
],
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@putout/plugin-madrun": "^10.2.0",
|
|
39
|
-
"@putout/test": "^
|
|
39
|
+
"@putout/test": "^4.0.0",
|
|
40
40
|
"c8": "^7.5.0",
|
|
41
41
|
"eslint": "^8.0.1",
|
|
42
42
|
"eslint-plugin-node": "^11.0.0",
|
|
43
|
-
"eslint-plugin-putout": "^
|
|
43
|
+
"eslint-plugin-putout": "^12.0.0",
|
|
44
44
|
"madrun": "^8.0.1"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"putout": ">=
|
|
47
|
+
"putout": ">=22"
|
|
48
48
|
},
|
|
49
49
|
"license": "MIT",
|
|
50
50
|
"engines": {
|
|
51
|
-
"node": ">=
|
|
51
|
+
"node": ">=14"
|
|
52
52
|
},
|
|
53
53
|
"publishConfig": {
|
|
54
54
|
"access": "public"
|