Skip to content

Commit 39063ce

Browse files
committed
fix(linter): reword diagnostic message for no-control-regex (#10993)
1 parent 89cc21b commit 39063ce

File tree

4 files changed

+9
-11
lines changed

4 files changed

+9
-11
lines changed

crates/oxc_language_server/src/snapshots/fixtures_linter_regexp_feature@index.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ input_file: crates/oxc_language_server/fixtures/linter/regexp_feature/index.ts
44
---
55
code: "eslint(no-control-regex)"
66
code_description.href: "https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-control-regex.html"
7-
message: "Unexpected control character\nhelp: '\\u0000' is not a valid control character."
7+
message: "Unexpected control character\nhelp: '\\u0000' is a control character."
88
range: Range { start: Position { line: 1, character: 13 }, end: Position { line: 1, character: 32 } }
99
related_information[0].message: ""
1010
related_information[0].location.uri: "file://<variable>/fixtures/linter/regexp_feature/index.ts"

crates/oxc_linter/src/rules/eslint/no_control_regex.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn no_control_regex_diagnostic(control_chars: &[Character], span: Span) -> OxcDi
4040
let regexes = other_chars.iter().join(", ");
4141
writeln!(
4242
help,
43-
"'{regexes}' {} not {}valid control character{}.",
43+
"'{regexes}' {} {}control character{}.",
4444
if other_chars.len() > 1 { "are" } else { "is" },
4545
if other_chars.len() > 1 { "" } else { "a " },
4646
if other_chars.len() > 1 { "s" } else { "" },
@@ -52,7 +52,7 @@ fn no_control_regex_diagnostic(control_chars: &[Character], span: Span) -> OxcDi
5252
let regexes = octal_chars.iter().join(", ");
5353
writeln!(
5454
help,
55-
"'{regexes}' {} not {}valid control character{}. They look like backreferences, but there {} no corresponding capture group{}. If you are trying to match the octal character, consider using '\\xNN' or '\\u00NN' instead.",
55+
"'{regexes}' {} {}control character{}. They look like backreferences, but there {} no corresponding capture group{}.",
5656
if octal_chars.len() > 1 { "are" } else { "is" },
5757
if octal_chars.len() > 1 { "" } else { "a " },
5858
if octal_chars.len() > 1 { "s" } else { "" },
@@ -62,10 +62,8 @@ fn no_control_regex_diagnostic(control_chars: &[Character], span: Span) -> OxcDi
6262
}
6363

6464
if !null_chars.is_empty() {
65-
writeln!(
66-
help,
67-
"'\\0' matches the null character (U+0000), which is a control character. If you intend to match the null character, consider using '\\x00' or '\\u0000' for clarity."
68-
).unwrap();
65+
writeln!(help, "'\\0' matches the null character (U+0000), which is a control character.")
66+
.unwrap();
6967
}
7068

7169
debug_assert!(!help.is_empty());
-813 Bytes
Binary file not shown.

crates/oxc_linter/src/snapshots/eslint_no_control_regex@capture-group-indexing.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@ source: crates/oxc_linter/src/tester.rs
66
1const r = /\0/;
77
· ────
88
╰────
9-
help: '\0' matches the null character (U+0000), which is a control character. If you intend to match the null character, consider using '\x00' or '\u0000' for clarity.
9+
help: '\0' matches the null character (U+0000), which is a control character.
1010

1111
eslint(no-control-regex): Unexpected control character
1212
╭─[no_control_regex.tsx:1:11]
1313
1const r = /[a-z]\1/;
1414
· ─────────
1515
╰────
16-
help: '\1' is not a valid control character. They look like backreferences, but there is no corresponding capture group. If you are trying to match the octal character, consider using '\xNN' or '\u00NN' instead.
16+
help: '\1' is a control character. They look like backreferences, but there is no corresponding capture group.
1717

1818
eslint(no-control-regex): Unexpected control character
1919
╭─[no_control_regex.tsx:1:11]
2020
1const r = /([a-z])\2/;
2121
· ───────────
2222
╰────
23-
help: '\2' is not a valid control character. They look like backreferences, but there is no corresponding capture group. If you are trying to match the octal character, consider using '\xNN' or '\u00NN' instead.
23+
help: '\2' is a control character. They look like backreferences, but there is no corresponding capture group.
2424

2525
eslint(no-control-regex): Unexpected control character
2626
╭─[no_control_regex.tsx:1:11]
2727
1const r = /([a-z])\0/;
2828
· ───────────
2929
╰────
30-
help: '\0' matches the null character (U+0000), which is a control character. If you intend to match the null character, consider using '\x00' or '\u0000' for clarity.
30+
help: '\0' matches the null character (U+0000), which is a control character.

0 commit comments

Comments
 (0)