Skip to content

Commit 6df56d6

Browse files
committed
feature: @putout/plugin-regexp: remove-useless-escape: add
1 parent 84419ff commit 6df56d6

31 files changed

+157
-89
lines changed

packages/plugin-regexp/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ npm i @putout/plugin-regexp -D
2727
-[optimize](#optimize);
2828
-[remove-useless-group](#remove-useless-group);
2929
-[remove-useless-regexp](#remove-useless-regexp);
30+
-[remove-useless-escape](#remove-useless-escape);
3031
-[remove-duplicates-from-character-class](#remove-duplicates-from-character-class);
3132

3233
## Config
@@ -43,6 +44,7 @@ npm i @putout/plugin-regexp -D
4344
"regexp/convert-to-string": "on",
4445
"regexp/convert-replace-to-replace-all": "on",
4546
"regexp/remove-useless-group": "on",
47+
"regexp/remove-useless-escape": "on",
4648
"regexp/remove-useless-regexp": "on",
4749
"regexp/remove-duplicates-from-character-class": "on"
4850
}
@@ -216,6 +218,29 @@ Simplify code according to [string-replace-all](https://github.com/tc39/proposal
216218
/hello/.test(str);
217219
```
218220

221+
## remove-useless-escape
222+
223+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/af9d1c774c3691aface974406717b32a/e9fc8a985e0195ecc27d70c748e5d4497be91265).
224+
225+
### ❌ Example of incorrect code
226+
227+
```js
228+
const cleanText = code.replaceAll(/[,;\(\)]/g, '');
229+
```
230+
231+
### ✅ Example of correct code
232+
233+
```js
234+
const cleanText = code.replaceAll(/[,;()]/g, '');
235+
```
236+
237+
### Comparison
238+
239+
Linter | Rule | Fix
240+
--------|-------|------------|
241+
🐊 **Putout**| [`regexp/remove-useless-escape`](https://github.com/coderaiser/putout/tree/master/packages/plugin-regexp/#remove-useless-escape)| ✅
242+
**ESLint** | [`no-useless-escape`](https://eslint.org/docs/rules/no-useless-escape) | ❌
243+
219244
## remove-useless-regexp
220245

221246
### ❌ Example of incorrect code

packages/plugin-regexp/eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {defineConfig} from 'eslint/config';
44
export default defineConfig([
55
safeAlign, {
66
rules: {
7-
'no-useless-return': 'off',
7+
'no-useless-escape': 'off',
88
},
99
},
1010
]);

packages/plugin-regexp/lib/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as removeUselessEscape from './remove-useless-escape/index.js';
12
import * as removeDuplicatesFromCharacterClass from './remove-duplicates-from-character-class/index.js';
23
import * as applyCharacterClass from './apply-character-class/index.js';
34
import * as applyGlobalRegexpToReplaceAll from './apply-global-regexp-to-replace-all/index.js';
@@ -22,4 +23,5 @@ export const rules = {
2223
'apply-global-regexp-to-replace-all': applyGlobalRegexpToReplaceAll,
2324
'apply-character-class': applyCharacterClass,
2425
'remove-duplicates-from-character-class': removeDuplicatesFromCharacterClass,
26+
'remove-useless-escape': removeUselessEscape,
2527
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/^\w+:/;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/^\w+\:/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const badMiddle = /\},\n(s+)?\{/;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const badMiddle = /\}\,\n(s+)?\{/;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/[\^+({*\].]/.test(raw)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
m.replace(/`/g, '\\`');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
m.replace(/\`/g, '\\`')

0 commit comments

Comments
 (0)