Skip to content

Commit

Permalink
feat(linter/eslint-plugin-unicorn): implement fixer for prefer-string…
Browse files Browse the repository at this point in the history
…-trim-start-end

Part of oxc-project#4179
  • Loading branch information
jelly committed Jul 15, 2024
1 parent 0296f2c commit 5c9bc58
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,14 @@ impl Rule for PreferStringTrimStartEnd {
return;
}

ctx.diagnostic(prefer_string_trim_start_end_diagnostic(
span,
get_replacement(name.as_str()),
name.as_str(),
));
ctx.diagnostic_with_fix(
prefer_string_trim_start_end_diagnostic(
span,
get_replacement(name.as_str()),
name.as_str(),
),
|fixer| fixer.replace(span, get_replacement(name.as_str())),
);
}
}

Expand Down Expand Up @@ -113,5 +116,14 @@ fn test() {
r"foo?.trimLeft()",
];

Tester::new(PreferStringTrimStartEnd::NAME, pass, fail).test_and_snapshot();
let fix = vec![
(r"foo.trimLeft()", r"foo.trimStart()"),
(r"foo.trimRight()", r"foo.trimEnd()"),
(r"trimLeft.trimRight()", r"trimLeft.trimEnd()"),
(r"foo.trimLeft.trimRight()", r"foo.trimLeft.trimEnd()"),
(r#""foo".trimLeft()"#, r#""foo".trimStart()"#),
(r"foo?.trimLeft()", r"foo?.trimStart()"),
];

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

0 comments on commit 5c9bc58

Please sign in to comment.