Skip to content
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
5 changes: 4 additions & 1 deletion crates/oxc_linter/src/rules/unicorn/no_hex_escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ impl Rule for NoHexEscape {
match node.kind() {
AstKind::StringLiteral(StringLiteral { span, .. }) => {
let text = span.source_text(ctx.source_text());
let quote = text.chars().next().unwrap_or('\'');
if let Some(fixed) = check_escape(&text[1..text.len() - 1]) {
ctx.diagnostic_with_fix(no_hex_escape_diagnostic(*span), |fixer| {
fixer.replace(*span, format!("'{fixed}'"))
fixer.replace(*span, format!("{quote}{fixed}{quote}"))
});
}
}
Expand Down Expand Up @@ -211,6 +212,8 @@ fn test() {
r#"const unicodeMatch = "".toString().match(/[^\u0000-\u00FF]+/gim);"#,
None,
),
(r#"const foo = "it'\x80s""#, r#"const foo = "it'\u0080s""#, None),
(r#"const foo = 'it"\x80s'"#, r#"const foo = 'it"\u0080s'"#, None),
];

Tester::new(NoHexEscape::NAME, NoHexEscape::PLUGIN, pass, fail)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ source: crates/oxc_linter/src/tester.rs
1 │ const foo = "\xb1"
· ──────
╰────
help: Replace `"\xb1"` with `'\u00b1'`.
help: Replace `"\xb1"` with `"\u00b1"`.

⚠ eslint-plugin-unicorn(no-hex-escape): Use Unicode escapes instead of hexadecimal escapes.
╭─[no_hex_escape.tsx:1:41]
Expand Down
Loading