@putout/plugin-remove-useless-escape 3.1.1 β†’ 4.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
@@ -39,6 +39,13 @@ const s = `hello 'world'`;
39
39
  const reg = /\w:/g;
40
40
  ```
41
41
 
42
+ ## Comparison
43
+
44
+ Linter | Rule | Fix
45
+ --------|-------|------------|
46
+ 🐊 **Putout**| [`remove-useless-escape`](https://github.com/coderaiser/putout/tree/master/packages/plugin-remove-useless-escape#readme)| βœ…
47
+ ⏣ **ESLint** | [`no-useless-escape`](https://eslint.org/docs/rules/no-useless-escape) | ❌
48
+
42
49
  ## License
43
50
 
44
51
  MIT
@@ -1,10 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  const emojiRegex = require('emoji-regex');
4
- const {
5
- types,
6
- operator,
7
- } = require('putout');
4
+
5
+ const {types, operator} = require('putout');
8
6
 
9
7
  const {replaceWith} = operator;
10
8
  const {RegExpLiteral} = types;
@@ -15,12 +13,15 @@ module.exports.report = () => 'Unnecessary escape character';
15
13
  module.exports.fix = (path) => {
16
14
  if (path.isStringLiteral()) {
17
15
  const {raw} = path.node;
16
+
18
17
  path.node.raw = unEscape(raw);
18
+
19
19
  return;
20
20
  }
21
21
 
22
22
  if (path.isRegExpLiteral()) {
23
23
  const {pattern, flags} = path.node;
24
+
24
25
  const unescaped = unescapeRegExp(pattern);
25
26
  const raw = `/${unescaped}/`;
26
27
 
@@ -47,9 +48,8 @@ module.exports.traverse = ({push}) => ({
47
48
  'RegExpLiteral'(path) {
48
49
  const {raw} = path.node;
49
50
 
50
- if (isEscapedRegExp(raw)) {
51
+ if (isEscapedRegExp(raw))
51
52
  push(path);
52
- }
53
53
  },
54
54
  '"__"'(path) {
55
55
  const {raw} = path.node;
@@ -62,13 +62,13 @@ module.exports.traverse = ({push}) => ({
62
62
  for (const tmpl of path.node.quasis) {
63
63
  const {raw} = tmpl.value;
64
64
 
65
- if (hasQuote(raw))
65
+ if (isEscaped(raw))
66
66
  return push(path);
67
67
 
68
- if (isEscaped(raw))
68
+ if (hasQuote(raw))
69
69
  return push(path);
70
70
 
71
- if (raw.includes('\\\''))
71
+ if (raw.includes(`\\'`) && !raw.includes(`\\\\'`))
72
72
  return push(path);
73
73
  }
74
74
  },
@@ -104,6 +104,12 @@ function isEscaped(raw) {
104
104
  if (/\\\//g.test(raw))
105
105
  return true;
106
106
 
107
+ if (raw.includes('\\$'))
108
+ return true;
109
+
110
+ if (raw.includes('\\{'))
111
+ return true;
112
+
107
113
  if (raw.includes('\\+') && !raw.includes('\\\\+'))
108
114
  return true;
109
115
 
@@ -116,21 +122,20 @@ function isEscaped(raw) {
116
122
  if (hasA(raw))
117
123
  return true;
118
124
 
119
- if (hasComa(raw))
120
- return true;
121
-
122
- return false;
125
+ return hasComa(raw);
123
126
  }
124
127
 
125
128
  const createEncodedRegExp = (a) => RegExp(`\\\\${a}`, 'g');
126
129
 
127
130
  function unEscape(raw) {
128
131
  raw = raw
129
- .replaceAll('\\\'', `'`)
132
+ .replaceAll(`\\'`, `'`)
130
133
  .replaceAll('\\/', '/')
131
134
  .replaceAll('\\+', '+')
132
135
  .replace(createEncodedRegExp(`"`), '"')
133
136
  .replaceAll('\\^', '^')
137
+ .replaceAll('\\$', '$')
138
+ .replaceAll('\\{', '{')
134
139
  .replace(/(\\),/, ',');
135
140
 
136
141
  for (const emoji of match(raw)) {
@@ -158,4 +163,3 @@ function isEscapedRegExp(raw) {
158
163
 
159
164
  return isRegExpColon(raw) || isRegExpSlash(raw) || isComa(raw);
160
165
  }
161
-
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@putout/plugin-remove-useless-escape",
3
- "version": "3.1.1",
3
+ "version": "4.0.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
- "description": "putout plugin adds ability to find and remove useless escape",
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",
8
8
  "main": "lib/remove-useless-escape.js",
9
9
  "release": false,
@@ -37,15 +37,16 @@
37
37
  ],
38
38
  "devDependencies": {
39
39
  "@putout/plugin-madrun": "*",
40
- "@putout/test": "^5.0.0",
41
- "c8": "^7.5.0",
40
+ "@putout/plugin-regexp": "*",
41
+ "@putout/test": "^7.0.0",
42
+ "c8": "^8.0.0",
42
43
  "eslint": "^8.0.1",
43
- "eslint-plugin-node": "^11.0.0",
44
- "eslint-plugin-putout": "^14.0.0",
44
+ "eslint-plugin-n": "^16.0.0",
45
+ "eslint-plugin-putout": "^21.0.0",
45
46
  "madrun": "^9.0.0"
46
47
  },
47
48
  "peerDependencies": {
48
- "putout": ">=25"
49
+ "putout": ">=33"
49
50
  },
50
51
  "license": "MIT",
51
52
  "engines": {