mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
fix(linter) fix panic in no hex escape (#1540)
🦀🦶🔫 lol https://twitter.com/boshen_c/status/1719033308682870891 closes #1539
This commit is contained in:
parent
32b19561a8
commit
41bb0060eb
2 changed files with 14 additions and 2 deletions
|
|
@ -44,7 +44,7 @@ declare_oxc_lint!(
|
||||||
fn check_escape(value: &str) -> Option<String> {
|
fn check_escape(value: &str) -> Option<String> {
|
||||||
let mut in_escape = false;
|
let mut in_escape = false;
|
||||||
let mut matched = Vec::new();
|
let mut matched = Vec::new();
|
||||||
for (index, c) in value.chars().enumerate() {
|
for (index, c) in value.char_indices() {
|
||||||
if c == '\\' && !in_escape {
|
if c == '\\' && !in_escape {
|
||||||
in_escape = true;
|
in_escape = true;
|
||||||
} else if c == 'x' && in_escape {
|
} else if c == 'x' && in_escape {
|
||||||
|
|
@ -68,6 +68,7 @@ fn check_escape(value: &str) -> Option<String> {
|
||||||
Some(fixed)
|
Some(fixed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Rule for NoHexEscape {
|
impl Rule for NoHexEscape {
|
||||||
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
|
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
|
||||||
match node.kind() {
|
match node.kind() {
|
||||||
|
|
@ -137,7 +138,12 @@ fn test() {
|
||||||
r"const foo = `\\\\xd8\\\\x3d\\\\xdc\\\\xa9`",
|
r"const foo = `\\\\xd8\\\\x3d\\\\xdc\\\\xa9`",
|
||||||
r"const foo = `foo\\\\x12foo\\\\x34`",
|
r"const foo = `foo\\\\x12foo\\\\x34`",
|
||||||
];
|
];
|
||||||
let fail = vec![r#"const foo = "\xb1""#];
|
|
||||||
|
let fail = vec![
|
||||||
|
r#"const foo = "\xb1""#,
|
||||||
|
r"wrapId(/(^|[<nonId>])(?:алг|арг(?:\x20*рез)?|ввод|ВКЛЮЧИТЬ|вс[её]|выбор|вывод|выход|дано|для|до|дс|если|иначе|исп|использовать|кон(?:(?:\x20+|_)исп)?|кц(?:(?:\x20+|_)при)?|надо|нач|нс|нц|от|пауза|пока|при|раза?|рез|стоп|таб|то|утв|шаг)(?=[<nonId>]|$)/.source)",
|
||||||
|
];
|
||||||
|
|
||||||
let fix = vec![
|
let fix = vec![
|
||||||
(r"const foo = '\xb1'", r"const foo = '\u00b1'", None),
|
(r"const foo = '\xb1'", r"const foo = '\u00b1'", None),
|
||||||
(r"const foo = '\\\xb1'", r"const foo = '\\\u00b1'", None),
|
(r"const foo = '\\\xb1'", r"const foo = '\\\u00b1'", None),
|
||||||
|
|
|
||||||
|
|
@ -8,4 +8,10 @@ expression: no_hex_escape
|
||||||
· ──────
|
· ──────
|
||||||
╰────
|
╰────
|
||||||
|
|
||||||
|
⚠ eslint-plugin-unicorn(no-hex-escape): Use Unicode escapes instead of hexadecimal escapes.
|
||||||
|
╭─[no_hex_escape.tsx:1:1]
|
||||||
|
1 │ wrapId(/(^|[<nonId>])(?:алг|арг(?:\x20*рез)?|ввод|ВКЛЮЧИТЬ|вс[её]|выбор|вывод|выход|дано|для|до|дс|если|иначе|исп|использовать|кон(?:(?:\x20+|_)исп)?|кц(?:(?:\x20+|_)при)?|надо|нач|нс|нц|от|пауза|пока|при|раза?|рез|стоп|таб|то|утв|шаг)(?=[<nonId>]|$)/.source)
|
||||||
|
· ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||||
|
╰────
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue