Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Arend van Beelen jr. <[email protected]>
  • Loading branch information
Conaclos and arendjr committed Aug 7, 2024
1 parent ee63ffc commit 94a4af7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use biome_analyze::{
context::RuleContext, declare_lint_rule, ActionCategory, Ast, FixKind, Rule, RuleDiagnostic,
RuleSource, RuleSourceKind,
RuleSource,
};
use biome_console::markup;
use biome_js_syntax::{JsRegexLiteralExpression, JsSyntaxKind, JsSyntaxToken};
Expand Down Expand Up @@ -227,20 +227,23 @@ impl Rule for NoUselessEscapeInRegex {
},
);
Some(if matches!(escaped, b'p' | b'P' | b'k') {
diag.note("The escape sequence is only useful when the Regular Expression is unicode-aware. To be unicode-aware, the `u` or `v` flag must be used.")
diag.note("The escape sequence is only useful if the regular expression is unicode-aware. To be unicode-aware, the `u` or `v` flag should be used.")
} else if *in_char_class {
match escaped {
b'^' => {
diag.note("The character must only be escaped when it is the first character of the class.")
diag.note("The character should only be escaped if it is the first character of the class.")
}
b'B' => {
diag.note("The escape sequence has only a meaning outside of a characvter class.")
diag.note("The escape sequence only has meaning outside a character class.")
}
b'.' | b'$' | b'*' | b'+' | b'?' | b'{' | b'}' | b'[' | b'(' | b')' => {
diag.note("The character must only be escaped when it is outside of a characvter class.")
b'(' | b')' | b'[' | b'{' | b'}' | b'/' | b'|' => {
diag.note("The character should only be escaped if it is outside a character class or under the `v` flag.")
}
b'.' | b'$' | b'*' | b'+' | b'?' => {
diag.note("The character should only be escaped if it is outside a character class.")
}
b'-' => {
diag.note("The character must be escaped only when it appears in the niddle of the character class.")
diag.note("The character should only be escaped if it appears in the middle of the character class or under the `v` flag.")
}
_ => diag,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ invalid.js:2:3 lint/nursery/noUselessEscapeInRegex FIXABLE ━━━━━━
3 │ /[ab\?]/;
4 │ /[ab\.]/;
i The character must be escaped only when it appears in the niddle of the character class.
i The character should only be escaped if it appears in the middle of the character class or under the `v` flag.
i Safe fix: Unescape the character.
Expand All @@ -105,7 +105,7 @@ invalid.js:3:5 lint/nursery/noUselessEscapeInRegex FIXABLE ━━━━━━
4 │ /[ab\.]/;
5 │ /[a\|b]/;
i The character must only be escaped when it is outside of a characvter class.
i The character should only be escaped if it is outside a character class.
i Safe fix: Unescape the character.
Expand All @@ -126,7 +126,7 @@ invalid.js:4:5 lint/nursery/noUselessEscapeInRegex FIXABLE ━━━━━━
5 │ /[a\|b]/;
6 │ /\-/;
i The character must only be escaped when it is outside of a characvter class.
i The character should only be escaped if it is outside a character class.
i Safe fix: Unescape the character.
Expand All @@ -147,6 +147,8 @@ invalid.js:5:4 lint/nursery/noUselessEscapeInRegex FIXABLE ━━━━━━
6 │ /\-/;
7 │ /[\-]/;
i The character should only be escaped if it is outside a character class or under the `v` flag.
i Safe fix: Unescape the character.
5 │ /[a\|b]/;
Expand Down Expand Up @@ -185,7 +187,7 @@ invalid.js:7:3 lint/nursery/noUselessEscapeInRegex FIXABLE ━━━━━━
8 │ /[\-]/;
9 │ /[\(paren]/;
i The character must be escaped only when it appears in the niddle of the character class.
i The character should only be escaped if it appears in the middle of the character class or under the `v` flag.
i Safe fix: Unescape the character.
Expand All @@ -206,7 +208,7 @@ invalid.js:8:3 lint/nursery/noUselessEscapeInRegex FIXABLE ━━━━━━
9 │ /[\(paren]/;
10 │ /[\[]/;
i The character must be escaped only when it appears in the niddle of the character class.
i The character should only be escaped if it appears in the middle of the character class or under the `v` flag.
i Safe fix: Unescape the character.
Expand All @@ -227,7 +229,7 @@ invalid.js:9:3 lint/nursery/noUselessEscapeInRegex FIXABLE ━━━━━━
10 │ /[\[]/;
11 │ /[\/]/; // A character class containing '/'
i The character must only be escaped when it is outside of a characvter class.
i The character should only be escaped if it is outside a character class or under the `v` flag.
i Safe fix: Unescape the character.
Expand All @@ -248,7 +250,7 @@ invalid.js:10:3 lint/nursery/noUselessEscapeInRegex FIXABLE ━━━━━━
11 │ /[\/]/; // A character class containing '/'
12 │ /[\B]/;
i The character must only be escaped when it is outside of a characvter class.
i The character should only be escaped if it is outside a character class or under the `v` flag.
i Safe fix: Unescape the character.
Expand All @@ -269,6 +271,8 @@ invalid.js:11:3 lint/nursery/noUselessEscapeInRegex FIXABLE ━━━━━━
12 │ /[\B]/;
13 │ /[a][\-b]/;
i The character should only be escaped if it is outside a character class or under the `v` flag.
i Safe fix: Unescape the character.
11 │ /[\/]/;·//·A·character·class·containing·'/'
Expand All @@ -288,7 +292,7 @@ invalid.js:12:3 lint/nursery/noUselessEscapeInRegex FIXABLE ━━━━━━
13 │ /[a][\-b]/;
14 │ /\-[]/;
i The escape sequence has only a meaning outside of a characvter class.
i The escape sequence only has meaning outside a character class.
i Safe fix: Unescape the character.
Expand All @@ -309,7 +313,7 @@ invalid.js:13:6 lint/nursery/noUselessEscapeInRegex FIXABLE ━━━━━━
14 │ /\-[]/;
15 │ /[a\^]/;
i The character must be escaped only when it appears in the niddle of the character class.
i The character should only be escaped if it appears in the middle of the character class or under the `v` flag.
i Safe fix: Unescape the character.
Expand Down Expand Up @@ -349,7 +353,7 @@ invalid.js:15:4 lint/nursery/noUselessEscapeInRegex FIXABLE ━━━━━━
16 │ /[^\^]/;
17 │ /[^\^]/u;
i The character must only be escaped when it is the first character of the class.
i The character should only be escaped if it is the first character of the class.
i Safe fix: Unescape the character.
Expand All @@ -370,7 +374,7 @@ invalid.js:16:4 lint/nursery/noUselessEscapeInRegex FIXABLE ━━━━━━
17 │ /[^\^]/u;
18 │ /[\$]/v;
i The character must only be escaped when it is the first character of the class.
i The character should only be escaped if it is the first character of the class.
i Safe fix: Unescape the character.
Expand All @@ -391,7 +395,7 @@ invalid.js:17:4 lint/nursery/noUselessEscapeInRegex FIXABLE ━━━━━━
18 │ /[\$]/v;
19 │ /[\&\&]/v;
i The character must only be escaped when it is the first character of the class.
i The character should only be escaped if it is the first character of the class.
i Safe fix: Unescape the character.
Expand All @@ -412,7 +416,7 @@ invalid.js:18:3 lint/nursery/noUselessEscapeInRegex FIXABLE ━━━━━━
19 │ /[\&\&]/v;
20 │ /[\!\!]/v;
i The character must only be escaped when it is outside of a characvter class.
i The character should only be escaped if it is outside a character class.
i Safe fix: Unescape the character.
Expand Down Expand Up @@ -509,7 +513,7 @@ invalid.js:23:3 lint/nursery/noUselessEscapeInRegex FIXABLE ━━━━━━
24 │ /[\+\+]/v;
25 │ /[\,\,]/v;
i The character must only be escaped when it is outside of a characvter class.
i The character should only be escaped if it is outside a character class.
i Safe fix: Unescape the character.
Expand All @@ -530,7 +534,7 @@ invalid.js:24:3 lint/nursery/noUselessEscapeInRegex FIXABLE ━━━━━━
25 │ /[\,\,]/v;
26 │ /[\,\,]/v;
i The character must only be escaped when it is outside of a characvter class.
i The character should only be escaped if it is outside a character class.
i Safe fix: Unescape the character.
Expand Down Expand Up @@ -684,7 +688,7 @@ invalid.js:32:3 lint/nursery/noUselessEscapeInRegex FIXABLE ━━━━━━
33 │ /[\@\@]/v;
34 │ /[\`\`]/v;
i The character must only be escaped when it is outside of a characvter class.
i The character should only be escaped if it is outside a character class.
i Safe fix: Unescape the character.
Expand Down Expand Up @@ -762,7 +766,7 @@ invalid.js:36:4 lint/nursery/noUselessEscapeInRegex FIXABLE ━━━━━━
37 │ /[_\^\^]/v;
38 │ /[\&\&&\&]/v;
i The character must only be escaped when it is the first character of the class.
i The character should only be escaped if it is the first character of the class.
i Safe fix: Unescape the character.
Expand All @@ -783,7 +787,7 @@ invalid.js:37:4 lint/nursery/noUselessEscapeInRegex FIXABLE ━━━━━━
38 │ /[\&\&&\&]/v;
39 │ /[\p{ASCII}--\.]/v;
i The character must only be escaped when it is the first character of the class.
i The character should only be escaped if it is the first character of the class.
i Safe fix: Unescape the character.
Expand Down Expand Up @@ -823,7 +827,7 @@ invalid.js:39:14 lint/nursery/noUselessEscapeInRegex FIXABLE ━━━━━
40 │ /[\p{ASCII}&&\.]/v;
41 │ /[\.--[.&]]/v;
i The character must only be escaped when it is outside of a characvter class.
i The character should only be escaped if it is outside a character class.
i Safe fix: Unescape the character.
Expand All @@ -844,7 +848,7 @@ invalid.js:40:14 lint/nursery/noUselessEscapeInRegex FIXABLE ━━━━━
41 │ /[\.--[.&]]/v;
42 │ /[\.&&[.&]]/v;
i The character must only be escaped when it is outside of a characvter class.
i The character should only be escaped if it is outside a character class.
i Safe fix: Unescape the character.
Expand All @@ -865,7 +869,7 @@ invalid.js:41:3 lint/nursery/noUselessEscapeInRegex FIXABLE ━━━━━━
42 │ /[\.&&[.&]]/v;
43 │ /[\.--\.--\.]/v;
i The character must only be escaped when it is outside of a characvter class.
i The character should only be escaped if it is outside a character class.
i Safe fix: Unescape the character.
Expand All @@ -886,7 +890,7 @@ invalid.js:42:3 lint/nursery/noUselessEscapeInRegex FIXABLE ━━━━━━
43 │ /[\.--\.--\.]/v;
44 │ /[\.&&\.&&\.]/v;
i The character must only be escaped when it is outside of a characvter class.
i The character should only be escaped if it is outside a character class.
i Safe fix: Unescape the character.
Expand All @@ -907,7 +911,7 @@ invalid.js:43:3 lint/nursery/noUselessEscapeInRegex FIXABLE ━━━━━━
44 │ /[\.&&\.&&\.]/v;
45 │ /[[\.&]--[\.&]]/v;
i The character must only be escaped when it is outside of a characvter class.
i The character should only be escaped if it is outside a character class.
i Safe fix: Unescape the character.
Expand All @@ -928,7 +932,7 @@ invalid.js:44:3 lint/nursery/noUselessEscapeInRegex FIXABLE ━━━━━━
45 │ /[[\.&]--[\.&]]/v;
46 │ /[[\.&]&&[\.&]]/v;
i The character must only be escaped when it is outside of a characvter class.
i The character should only be escaped if it is outside a character class.
i Safe fix: Unescape the character.
Expand All @@ -949,7 +953,7 @@ invalid.js:45:4 lint/nursery/noUselessEscapeInRegex FIXABLE ━━━━━━
46 │ /[[\.&]&&[\.&]]/v;
47 │
i The character must only be escaped when it is outside of a characvter class.
i The character should only be escaped if it is outside a character class.
i Safe fix: Unescape the character.
Expand All @@ -970,7 +974,7 @@ invalid.js:46:4 lint/nursery/noUselessEscapeInRegex FIXABLE ━━━━━━
47 │
48 │ // Unlike ESLint, we report `\k` when it is not in a unicode-aware regex
i The character must only be escaped when it is outside of a characvter class.
i The character should only be escaped if it is outside a character class.
i Safe fix: Unescape the character.
Expand All @@ -988,7 +992,7 @@ invalid.js:49:8 lint/nursery/noUselessEscapeInRegex FIXABLE ━━━━━━
> 49 │ /(?<a>)\k<a>/;
│ ^^
i The escape sequence is only useful when the Regular Expression is unicode-aware. To be unicode-aware, the `u` or `v` flag must be used.
i The escape sequence is only useful if the regular expression is unicode-aware. To be unicode-aware, the `u` or `v` flag should be used.
i Safe fix: Unescape the character.
Expand Down

0 comments on commit 94a4af7

Please sign in to comment.