]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/src/rules/no-useless-escape.md
import 8.41.0 source
[pve-eslint.git] / eslint / docs / src / rules / no-useless-escape.md
1 ---
2 title: no-useless-escape
3 rule_type: suggestion
4 ---
5
6
7
8
9
10 Escaping non-special characters in strings, template literals, and regular expressions doesn't have any effect, as demonstrated in the following example:
11
12 ```js
13 let foo = "hol\a"; // > foo = "hola"
14 let bar = `${foo}\!`; // > bar = "hola!"
15 let baz = /\:/ // same functionality with /:/
16 ```
17
18 ## Rule Details
19
20 This rule flags escapes that can be safely removed without changing behavior.
21
22 Examples of **incorrect** code for this rule:
23
24 ::: incorrect
25
26 ```js
27 /*eslint no-useless-escape: "error"*/
28
29 "\'";
30 '\"';
31 "\#";
32 "\e";
33 `\"`;
34 `\"${foo}\"`;
35 `\#{foo}`;
36 /\!/;
37 /\@/;
38 /[\[]/;
39 /[a-z\-]/;
40 ```
41
42 :::
43
44 Examples of **correct** code for this rule:
45
46 ::: correct
47
48 ```js
49 /*eslint no-useless-escape: "error"*/
50
51 "\"";
52 '\'';
53 "\x12";
54 "\u00a9";
55 "\371";
56 "xs\u2111";
57 `\``;
58 `\${${foo}}`;
59 `$\{${foo}}`;
60 /\\/g;
61 /\t/g;
62 /\w\$\*\^\./;
63 /[[]/;
64 /[\]]/;
65 /[a-z-]/;
66 ```
67
68 :::
69
70 ## When Not To Use It
71
72 If you don't want to be notified about unnecessary escapes, you can safely disable this rule.