diff --git a/crates/oxc_linter/src/rules/unicorn/text_encoding_identifier_case.rs b/crates/oxc_linter/src/rules/unicorn/text_encoding_identifier_case.rs
index 4d5e89859f09e..fa4c86bf50389 100644
--- a/crates/oxc_linter/src/rules/unicorn/text_encoding_identifier_case.rs
+++ b/crates/oxc_linter/src/rules/unicorn/text_encoding_identifier_case.rs
@@ -46,7 +46,7 @@ declare_oxc_lint!(
/// ```
TextEncodingIdentifierCase,
style,
- pending
+ fix
);
impl Rule for TextEncodingIdentifierCase {
@@ -72,7 +72,10 @@ impl Rule for TextEncodingIdentifierCase {
return;
}
- ctx.diagnostic(text_encoding_identifier_case_diagnostic(span, replacement, s));
+ ctx.diagnostic_with_fix(
+ text_encoding_identifier_case_diagnostic(span, replacement, s),
+ |fixer| fixer.replace(Span::new(span.start + 1, span.end - 1), replacement),
+ );
}
}
@@ -169,5 +172,31 @@ fn test() {
r#""#,
];
- Tester::new(TextEncodingIdentifierCase::NAME, pass, fail).test_and_snapshot();
+ let fix = vec![
+ (r#""UTF-8""#, r#""utf8""#),
+ (r#""utf-8""#, r#""utf8""#),
+ (r"'utf-8'", r"'utf8'"),
+ (r#""Utf8""#, r#""utf8""#),
+ (r#""ASCII""#, r#""ascii""#),
+ (r#"fs.readFile?.(file, "UTF-8")"#, r#"fs.readFile?.(file, "utf8")"#),
+ (r#"fs?.readFile(file, "UTF-8")"#, r#"fs?.readFile(file, "utf8")"#),
+ (r#"readFile(file, "UTF-8")"#, r#"readFile(file, "utf8")"#),
+ (r#"fs.readFile(...file, "UTF-8")"#, r#"fs.readFile(...file, "utf8")"#),
+ (r#"new fs.readFile(file, "UTF-8")"#, r#"new fs.readFile(file, "utf8")"#),
+ (r#"fs.readFile(file, {encoding: "UTF-8"})"#, r#"fs.readFile(file, {encoding: "utf8"})"#),
+ (r#"fs.readFile("UTF-8")"#, r#"fs.readFile("utf8")"#),
+ (r#"fs.readFile(file, "UTF-8", () => {})"#, r#"fs.readFile(file, "utf8", () => {})"#),
+ (r#"fs.readFileSync(file, "UTF-8")"#, r#"fs.readFileSync(file, "utf8")"#),
+ (r#"fs[readFile](file, "UTF-8")"#, r#"fs[readFile](file, "utf8")"#),
+ (r#"fs["readFile"](file, "UTF-8")"#, r#"fs["readFile"](file, "utf8")"#),
+ (r#"await fs.readFile(file, "UTF-8",)"#, r#"await fs.readFile(file, "utf8",)"#),
+ (r#"fs.promises.readFile(file, "UTF-8",)"#, r#"fs.promises.readFile(file, "utf8",)"#),
+ (r#"whatever.readFile(file, "UTF-8",)"#, r#"whatever.readFile(file, "utf8",)"#),
+ (r#""#, r#""#),
+ (r#""#, r#""#),
+ (r#""#, r#""#),
+ (r#""#, r#""#),
+ ];
+
+ Tester::new(TextEncodingIdentifierCase::NAME, pass, fail).expect_fix(fix).test_and_snapshot();
}
diff --git a/crates/oxc_linter/src/snapshots/text_encoding_identifier_case.snap b/crates/oxc_linter/src/snapshots/text_encoding_identifier_case.snap
index 698c0d3d024ea..4d44cad5143c5 100644
--- a/crates/oxc_linter/src/snapshots/text_encoding_identifier_case.snap
+++ b/crates/oxc_linter/src/snapshots/text_encoding_identifier_case.snap
@@ -6,135 +6,158 @@ source: crates/oxc_linter/src/tester.rs
1 │ "UTF-8"
· ───────
╰────
+ help: Replace `UTF-8` with `utf8`.
⚠ eslint-plugin-unicorn(text-encoding-identifier-case): Prefer `utf8` over `utf-8`.
╭─[text_encoding_identifier_case.tsx:1:1]
1 │ "utf-8"
· ───────
╰────
+ help: Replace `utf-8` with `utf8`.
⚠ eslint-plugin-unicorn(text-encoding-identifier-case): Prefer `utf8` over `utf-8`.
╭─[text_encoding_identifier_case.tsx:1:1]
1 │ 'utf-8'
· ───────
╰────
+ help: Replace `utf-8` with `utf8`.
⚠ eslint-plugin-unicorn(text-encoding-identifier-case): Prefer `utf8` over `Utf8`.
╭─[text_encoding_identifier_case.tsx:1:1]
1 │ "Utf8"
· ──────
╰────
+ help: Replace `Utf8` with `utf8`.
⚠ eslint-plugin-unicorn(text-encoding-identifier-case): Prefer `ascii` over `ASCII`.
╭─[text_encoding_identifier_case.tsx:1:1]
1 │ "ASCII"
· ───────
╰────
+ help: Replace `ASCII` with `ascii`.
⚠ eslint-plugin-unicorn(text-encoding-identifier-case): Prefer `utf8` over `UTF-8`.
╭─[text_encoding_identifier_case.tsx:1:21]
1 │ fs.readFile?.(file, "UTF-8")
· ───────
╰────
+ help: Replace `UTF-8` with `utf8`.
⚠ eslint-plugin-unicorn(text-encoding-identifier-case): Prefer `utf8` over `UTF-8`.
╭─[text_encoding_identifier_case.tsx:1:20]
1 │ fs?.readFile(file, "UTF-8")
· ───────
╰────
+ help: Replace `UTF-8` with `utf8`.
⚠ eslint-plugin-unicorn(text-encoding-identifier-case): Prefer `utf8` over `UTF-8`.
╭─[text_encoding_identifier_case.tsx:1:16]
1 │ readFile(file, "UTF-8")
· ───────
╰────
+ help: Replace `UTF-8` with `utf8`.
⚠ eslint-plugin-unicorn(text-encoding-identifier-case): Prefer `utf8` over `UTF-8`.
╭─[text_encoding_identifier_case.tsx:1:22]
1 │ fs.readFile(...file, "UTF-8")
· ───────
╰────
+ help: Replace `UTF-8` with `utf8`.
⚠ eslint-plugin-unicorn(text-encoding-identifier-case): Prefer `utf8` over `UTF-8`.
╭─[text_encoding_identifier_case.tsx:1:23]
1 │ new fs.readFile(file, "UTF-8")
· ───────
╰────
+ help: Replace `UTF-8` with `utf8`.
⚠ eslint-plugin-unicorn(text-encoding-identifier-case): Prefer `utf8` over `UTF-8`.
╭─[text_encoding_identifier_case.tsx:1:30]
1 │ fs.readFile(file, {encoding: "UTF-8"})
· ───────
╰────
+ help: Replace `UTF-8` with `utf8`.
⚠ eslint-plugin-unicorn(text-encoding-identifier-case): Prefer `utf8` over `UTF-8`.
╭─[text_encoding_identifier_case.tsx:1:13]
1 │ fs.readFile("UTF-8")
· ───────
╰────
+ help: Replace `UTF-8` with `utf8`.
⚠ eslint-plugin-unicorn(text-encoding-identifier-case): Prefer `utf8` over `UTF-8`.
╭─[text_encoding_identifier_case.tsx:1:19]
1 │ fs.readFile(file, "UTF-8", () => {})
· ───────
╰────
+ help: Replace `UTF-8` with `utf8`.
⚠ eslint-plugin-unicorn(text-encoding-identifier-case): Prefer `utf8` over `UTF-8`.
╭─[text_encoding_identifier_case.tsx:1:23]
1 │ fs.readFileSync(file, "UTF-8")
· ───────
╰────
+ help: Replace `UTF-8` with `utf8`.
⚠ eslint-plugin-unicorn(text-encoding-identifier-case): Prefer `utf8` over `UTF-8`.
╭─[text_encoding_identifier_case.tsx:1:20]
1 │ fs[readFile](file, "UTF-8")
· ───────
╰────
+ help: Replace `UTF-8` with `utf8`.
⚠ eslint-plugin-unicorn(text-encoding-identifier-case): Prefer `utf8` over `UTF-8`.
╭─[text_encoding_identifier_case.tsx:1:22]
1 │ fs["readFile"](file, "UTF-8")
· ───────
╰────
+ help: Replace `UTF-8` with `utf8`.
⚠ eslint-plugin-unicorn(text-encoding-identifier-case): Prefer `utf8` over `UTF-8`.
╭─[text_encoding_identifier_case.tsx:1:25]
1 │ await fs.readFile(file, "UTF-8",)
· ───────
╰────
+ help: Replace `UTF-8` with `utf8`.
⚠ eslint-plugin-unicorn(text-encoding-identifier-case): Prefer `utf8` over `UTF-8`.
╭─[text_encoding_identifier_case.tsx:1:28]
1 │ fs.promises.readFile(file, "UTF-8",)
· ───────
╰────
+ help: Replace `UTF-8` with `utf8`.
⚠ eslint-plugin-unicorn(text-encoding-identifier-case): Prefer `utf8` over `UTF-8`.
╭─[text_encoding_identifier_case.tsx:1:25]
1 │ whatever.readFile(file, "UTF-8",)
· ───────
╰────
+ help: Replace `UTF-8` with `utf8`.
⚠ eslint-plugin-unicorn(text-encoding-identifier-case): Prefer `utf8` over `utf-8`.
╭─[text_encoding_identifier_case.tsx:1:19]
1 │
· ───────
╰────
+ help: Replace `utf-8` with `utf8`.
⚠ eslint-plugin-unicorn(text-encoding-identifier-case): Prefer `utf8` over `utf-8`.
╭─[text_encoding_identifier_case.tsx:1:19]
1 │
· ───────
╰────
+ help: Replace `utf-8` with `utf8`.
⚠ eslint-plugin-unicorn(text-encoding-identifier-case): Prefer `ascii` over `ASCII`.
╭─[text_encoding_identifier_case.tsx:1:15]
1 │
· ───────
╰────
+ help: Replace `ASCII` with `ascii`.
⚠ eslint-plugin-unicorn(text-encoding-identifier-case): Prefer `ascii` over `ASCII`.
╭─[text_encoding_identifier_case.tsx:1:15]
1 │
· ───────
╰────
+ help: Replace `ASCII` with `ascii`.