@putout/plugin-remove-useless-escape 6.0.0 → 8.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.
@@ -1,16 +1,13 @@
1
- 'use strict';
2
-
3
- const emojiRegex = require('emoji-regex');
4
-
5
- const {types, operator} = require('putout');
1
+ import emojiRegex from 'emoji-regex';
2
+ import {types, operator} from 'putout';
6
3
 
7
4
  const {replaceWith} = operator;
8
- const {RegExpLiteral} = types;
5
+ const {regExpLiteral} = types;
9
6
  const {assign} = Object;
10
7
 
11
- module.exports.report = () => 'Unnecessary escape character';
8
+ export const report = () => 'Unnecessary escape character';
12
9
 
13
- module.exports.fix = (path) => {
10
+ export const fix = (path) => {
14
11
  if (path.isStringLiteral()) {
15
12
  const {raw} = path.node;
16
13
 
@@ -25,7 +22,7 @@ module.exports.fix = (path) => {
25
22
  const unescaped = unescapeRegExp(pattern);
26
23
  const raw = `/${unescaped}/`;
27
24
 
28
- const regExpNode = assign(RegExpLiteral(unescaped, flags), {
25
+ const regExpNode = assign(regExpLiteral(unescaped, flags), {
29
26
  value: unescaped,
30
27
  raw,
31
28
  extra: {
@@ -44,7 +41,7 @@ module.exports.fix = (path) => {
44
41
  }
45
42
  };
46
43
 
47
- module.exports.traverse = ({push}) => ({
44
+ export const traverse = ({push}) => ({
48
45
  'RegExpLiteral'(path) {
49
46
  const {raw} = path.node;
50
47
 
@@ -156,12 +153,11 @@ function unEscape(raw) {
156
153
  return raw;
157
154
  }
158
155
 
159
- function unescapeRegExp(raw) {
160
- return raw
161
- .replaceAll('\\:', ':')
162
- .replaceAll('\\+\\/', '+/')
163
- .replaceAll('\\,', ',');
164
- }
156
+ const unescapeRegExp = (raw) => raw
157
+ .replaceAll('\\:', ':')
158
+ .replaceAll('\\+\\/', '+/')
159
+ .replaceAll('\\,', ',')
160
+ .replaceAll('\\`', '`');
165
161
 
166
162
  const is = (a) => (b) => b.includes(`\\${a}`) && !b.includes(`\\\\${a}`);
167
163
  const isRegExpColon = is(':');
@@ -172,5 +168,8 @@ function isEscapedRegExp(raw) {
172
168
  if (raw.includes('\\/'))
173
169
  return false;
174
170
 
171
+ if (raw.includes('\\`'))
172
+ return true;
173
+
175
174
  return isRegExpColon(raw) || isRegExpSlash(raw) || isComa(raw);
176
175
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@putout/plugin-remove-useless-escape",
3
- "version": "6.0.0",
4
- "type": "commonjs",
3
+ "version": "8.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",
@@ -11,7 +11,7 @@
11
11
  "changelog": false,
12
12
  "repository": {
13
13
  "type": "git",
14
- "url": "git://github.com/coderaiser/putout.git"
14
+ "url": "git+https://github.com/coderaiser/putout.git"
15
15
  },
16
16
  "scripts": {
17
17
  "test": "madrun test",
@@ -36,21 +36,22 @@
36
36
  "escape"
37
37
  ],
38
38
  "devDependencies": {
39
+ "@putout/eslint-flat": "^3.0.0",
39
40
  "@putout/plugin-madrun": "*",
40
41
  "@putout/plugin-regexp": "*",
41
- "@putout/test": "^9.0.0",
42
- "c8": "^9.0.0",
42
+ "@putout/test": "^13.0.0",
43
+ "c8": "^10.0.0",
43
44
  "eslint": "^9.0.0",
44
45
  "eslint-plugin-n": "^17.0.0",
45
- "eslint-plugin-putout": "^22.0.0",
46
- "madrun": "^10.0.0"
46
+ "eslint-plugin-putout": "^26.0.0",
47
+ "madrun": "^11.0.0"
47
48
  },
48
49
  "peerDependencies": {
49
- "putout": ">=35"
50
+ "putout": ">=40"
50
51
  },
51
52
  "license": "MIT",
52
53
  "engines": {
53
- "node": ">=18"
54
+ "node": ">=20"
54
55
  },
55
56
  "publishConfig": {
56
57
  "access": "public"