mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
feat(linter/unicorn): add fixer to text-encoding-identifier-case (#5154)
This commit is contained in:
parent
7eb052e0d4
commit
27db769b8a
2 changed files with 55 additions and 3 deletions
|
|
@ -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#"<META CHARSET="ASCII" />"#,
|
||||
];
|
||||
|
||||
Tester::new(TextEncodingIdentifierCase::NAME, pass, fail).test_and_snapshot();
|
||||
let fix = vec"#, 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#"<not-meta charset="utf-8" />"#, r#"<not-meta charset="utf8" />"#),
|
||||
(r#"<meta not-charset="utf-8" />"#, r#"<meta not-charset="utf8" />"#),
|
||||
(r#"<meta charset="ASCII" />"#, r#"<meta charset="ascii" />"#),
|
||||
(r#"<META CHARSET="ASCII" />"#, r#"<META CHARSET="ascii" />"#),
|
||||
];
|
||||
|
||||
Tester::new(TextEncodingIdentifierCase::NAME, pass, fail).expect_fix(fix).test_and_snapshot();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 │ <not-meta charset="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 │ <meta not-charset="utf-8" />
|
||||
· ───────
|
||||
╰────
|
||||
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 │ <meta charset="ASCII" />
|
||||
· ───────
|
||||
╰────
|
||||
help: Replace `ASCII` with `ascii`.
|
||||
|
||||
⚠ eslint-plugin-unicorn(text-encoding-identifier-case): Prefer `ascii` over `ASCII`.
|
||||
╭─[text_encoding_identifier_case.tsx:1:15]
|
||||
1 │ <META CHARSET="ASCII" />
|
||||
· ───────
|
||||
╰────
|
||||
help: Replace `ASCII` with `ascii`.
|
||||
|
|
|
|||
Loading…
Reference in a new issue