Skip to content

fix(linter): reword diagnostic message for no-control-regex #10993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ input_file: crates/oxc_language_server/fixtures/linter/regexp_feature/index.ts
---
code: "eslint(no-control-regex)"
code_description.href: "https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-control-regex.html"
message: "Unexpected control character\nhelp: '\\u0000' is not a valid control character."
message: "Unexpected control character\nhelp: '\\u0000' is a control character."
range: Range { start: Position { line: 1, character: 13 }, end: Position { line: 1, character: 32 } }
related_information[0].message: ""
related_information[0].location.uri: "file://<variable>/fixtures/linter/regexp_feature/index.ts"
Expand Down
10 changes: 4 additions & 6 deletions crates/oxc_linter/src/rules/eslint/no_control_regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn no_control_regex_diagnostic(control_chars: &[Character], span: Span) -> OxcDi
let regexes = other_chars.iter().join(", ");
writeln!(
help,
"'{regexes}' {} not {}valid control character{}.",
"'{regexes}' {} {}control character{}.",
if other_chars.len() > 1 { "are" } else { "is" },
if other_chars.len() > 1 { "" } else { "a " },
if other_chars.len() > 1 { "s" } else { "" },
Expand All @@ -52,7 +52,7 @@ fn no_control_regex_diagnostic(control_chars: &[Character], span: Span) -> OxcDi
let regexes = octal_chars.iter().join(", ");
writeln!(
help,
"'{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.",
"'{regexes}' {} {}control character{}. They look like backreferences, but there {} no corresponding capture group{}.",
if octal_chars.len() > 1 { "are" } else { "is" },
if octal_chars.len() > 1 { "" } else { "a " },
if octal_chars.len() > 1 { "s" } else { "" },
Expand All @@ -62,10 +62,8 @@ fn no_control_regex_diagnostic(control_chars: &[Character], span: Span) -> OxcDi
}

if !null_chars.is_empty() {
writeln!(
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."
).unwrap();
writeln!(help, "'\\0' matches the null character (U+0000), which is a control character.")
.unwrap();
}

debug_assert!(!help.is_empty());
Expand Down
Binary file modified crates/oxc_linter/src/snapshots/eslint_no_control_regex.snap
Binary file not shown.
8 changes: 4 additions & 4 deletions crates/oxc_linter/src/snapshots/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ source: crates/oxc_linter/src/tester.rs
1 │ const r = /\0/;
· ────
╰────
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.
help: '\0' matches the null character (U+0000), which is a control character.

⚠ eslint(no-control-regex): Unexpected control character
╭─[no_control_regex.tsx:1:11]
1 │ const r = /[a-z]\1/;
· ─────────
╰────
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.
help: '\1' is a control character. They look like backreferences, but there is no corresponding capture group.

⚠ eslint(no-control-regex): Unexpected control character
╭─[no_control_regex.tsx:1:11]
1 │ const r = /([a-z])\2/;
· ───────────
╰────
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.
help: '\2' is a control character. They look like backreferences, but there is no corresponding capture group.

⚠ eslint(no-control-regex): Unexpected control character
╭─[no_control_regex.tsx:1:11]
1 │ const r = /([a-z])\0/;
· ───────────
╰────
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.
help: '\0' matches the null character (U+0000), which is a control character.
Loading