Skip to content

Commit

Permalink
feat(linter/eslint-plugin-unicorn): add fixer for prefer-code-point (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jelly authored Jul 20, 2024
1 parent 3c0c709 commit 5f1e070
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions crates/oxc_linter/src/rules/unicorn/prefer_code_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ impl Rule for PreferCodePoint {
_ => return,
};

ctx.diagnostic(prefer_code_point_diagnostic(span, replacement, current));
ctx.diagnostic_with_fix(
prefer_code_point_diagnostic(span, replacement, current),
|fixer| fixer.replace(span, replacement),
);
}
}

Expand Down Expand Up @@ -100,5 +103,15 @@ fn test() {
r"(( (( String )).fromCharCode( ((code)), ) ))",
];

Tester::new(PreferCodePoint::NAME, pass, fail).test_and_snapshot();
let fix = vec![
(r"string.charCodeAt(index)", r"string.codePointAt(index)"),
(
r"(( (( String )).fromCharCode( ((code)), ) ))",
r"(( (( String )).fromCodePoint( ((code)), ) ))",
),
(r#""🦄".charCodeAt(0)"#, r#""🦄".codePointAt(0)"#),
(r"String.fromCharCode(0x1f984);", r"String.fromCodePoint(0x1f984);"),
];

Tester::new(PreferCodePoint::NAME, pass, fail).expect_fix(fix).test_and_snapshot();
}

0 comments on commit 5f1e070

Please sign in to comment.