mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
fix(linter): not ignore adjacent spans when fixing (#4217)
fixes: #4204
This commit is contained in:
parent
205c259119
commit
67240dce85
3 changed files with 9 additions and 15 deletions
|
|
@ -316,7 +316,7 @@ impl<'a> Fixer<'a> {
|
|||
if start > end {
|
||||
return;
|
||||
}
|
||||
if i64::from(start) <= last_pos {
|
||||
if i64::from(start) < last_pos {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -558,14 +558,13 @@ mod test {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn apply_one_fix_when_the_start_the_same_as_the_previous_end() {
|
||||
fn apply_two_fix_when_the_start_the_same_as_the_previous_end() {
|
||||
let result = get_fix_result(vec![
|
||||
create_message(remove_start(), Some(REMOVE_START)),
|
||||
create_message(replace_id(), Some(REPLACE_ID)),
|
||||
]);
|
||||
assert_eq!(result.fixed_code, TEST_CODE.replace("var ", ""));
|
||||
assert_eq!(result.messages.len(), 1);
|
||||
assert_eq!(result.messages[0].error.to_string(), "foo");
|
||||
assert_eq!(result.fixed_code, TEST_CODE.replace("var answer", "foo"));
|
||||
assert_eq!(result.messages.len(), 0);
|
||||
assert!(result.fixed);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -186,7 +186,7 @@ fn check_template(string: &str) -> Vec<usize> {
|
|||
|
||||
let mut offsets = vec![];
|
||||
let mut in_escape = false;
|
||||
let mut prev_char = '`';
|
||||
let mut prev_non_escape_char = '`';
|
||||
let mut byte_offset = 1;
|
||||
|
||||
let mut chars = string.chars().peekable();
|
||||
|
|
@ -199,7 +199,7 @@ fn check_template(string: &str) -> Vec<usize> {
|
|||
match c {
|
||||
c if c.is_ascii_digit() || c == '`' => { /* noop */ }
|
||||
'{' => {
|
||||
if prev_char != '$' {
|
||||
if prev_non_escape_char != '$' {
|
||||
offsets.push(byte_offset - c.len_utf8());
|
||||
}
|
||||
}
|
||||
|
|
@ -213,10 +213,11 @@ fn check_template(string: &str) -> Vec<usize> {
|
|||
}
|
||||
_ => {}
|
||||
}
|
||||
prev_non_escape_char = c;
|
||||
} else if c == '\\' {
|
||||
in_escape = true;
|
||||
} else {
|
||||
prev_char = c;
|
||||
prev_non_escape_char = c;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -400,7 +401,7 @@ fn test() {
|
|||
("var foo = '\\#';", "var foo = '#';", None),
|
||||
("var foo = '\\$';", "var foo = '$';", None),
|
||||
("var foo = '\\p';", "var foo = 'p';", None),
|
||||
("var foo = '\\p\\a\\@';", "var foo = 'p\\a@';", None),
|
||||
("var foo = '\\p\\a\\@';", "var foo = 'pa@';", None),
|
||||
("<foo attr={\"\\d\"}/>", "<foo attr={\"d\"}/>", None),
|
||||
("var foo = '\\`';", "var foo = '`';", None),
|
||||
("var foo = `\\\"`;", "var foo = `\"`;", None),
|
||||
|
|
|
|||
|
|
@ -181,12 +181,6 @@ source: crates/oxc_linter/src/tester.rs
|
|||
· ──
|
||||
╰────
|
||||
|
||||
⚠ eslint(no-useless-escape): Unnecessary escape character '{'
|
||||
╭─[no_useless_escape.tsx:1:14]
|
||||
1 │ var foo = `\$\{{${foo}`;
|
||||
· ──
|
||||
╰────
|
||||
|
||||
⚠ eslint(no-useless-escape): Unnecessary escape character '$'
|
||||
╭─[no_useless_escape.tsx:1:12]
|
||||
1 │ var foo = `\$a${foo}`;
|
||||
|
|
|
|||
Loading…
Reference in a new issue