{"record":{"id":"24d9c91050aa0b13","repo":"oxc-project/oxc","slug":"prefer-good-encoding-over-bad-encoding","errorCode":null,"errorMessage":"Prefer `{good_encoding}` over `{bad_encoding}`.","messagePattern":"Prefer `(.+?)` over `(.+?)`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/unicorn/text_encoding_identifier_case.rs","lineNumber":21,"sourceCode":"\nuse oxc_ast::{AstKind, ast::JSXAttributeName};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_semantic::NodeId;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn text_encoding_identifier_case_diagnostic(\n    span: Span,\n    good_encoding: &str,\n    bad_encoding: &str,\n) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Prefer `{good_encoding}` over `{bad_encoding}`.\")).with_label(span)\n}\n\n#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]\n#[serde(default, rename_all = \"camelCase\", deny_unknown_fields)]\npub struct TextEncodingIdentifierCase {\n    /// If `true`, prefer `utf-8` over `utf8`.\n    with_dash: bool,\n}\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// This rule enforces consistent casing for text encoding identifiers, specifically:\n    /// - `'utf8'` instead of `'UTF-8'` or `'utf-8'` (or `'utf-8'` if `withDash` is enabled)\n    /// - `'ascii'` instead of `'ASCII'`\n    ///\n    /// ### Why is this bad?\n    ///","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/text_encoding_identifier_case.rs#L3-L39","documentation":"Emitted by the unicorn/text-encoding-identifier-case rule at an encoding identifier (in `TextEncoder`/`TextDecoder` labels or JSX `charset`-style attributes) whose casing does not match the configured preference (lowercase by default). It fires on the identifier span purely for canonical casing consistency.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/unicorn/text_encoding_identifier_case.rs:21 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use the canonical casing, e.g. `'utf-8'` instead of `'UTF-8'` (or the inverse if configured)","The rule offers a fix that rewrites the identifier to the preferred casing"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}