oxc-project/oxc · error · OxcDiagnostic

Prefer ` ` over ` `.

Error message

Prefer `{good_encoding}` over `{bad_encoding}`.

What it means

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.

Solutions

  1. Use the canonical casing, e.g. `'utf-8'` instead of `'UTF-8'` (or the inverse if configured)
  2. The rule offers a fix that rewrites the identifier to the preferred casing
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/unicorn/text_encoding_identifier_case.rs:21 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/24d9c91050aa0b13. Report an issue: GitHub.

Appendix: source

Thrown at crates/oxc_linter/src/rules/unicorn/text_encoding_identifier_case.rs:21

use oxc_ast::{AstKind, ast::JSXAttributeName};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_semantic::NodeId;
use oxc_span::{GetSpan, Span};

use crate::{
    AstNode,
    context::LintContext,
    rule::{DefaultRuleConfig, Rule},
};

fn text_encoding_identifier_case_diagnostic(
    span: Span,
    good_encoding: &str,
    bad_encoding: &str,
) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!("Prefer `{good_encoding}` over `{bad_encoding}`.")).with_label(span)
}

#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(default, rename_all = "camelCase", deny_unknown_fields)]
pub struct TextEncodingIdentifierCase {
    /// If `true`, prefer `utf-8` over `utf8`.
    with_dash: bool,
}

declare_oxc_lint!(
    /// ### What it does
    ///
    /// This rule enforces consistent casing for text encoding identifiers, specifically:
    /// - `'utf8'` instead of `'UTF-8'` or `'utf-8'` (or `'utf-8'` if `withDash` is enabled)
    /// - `'ascii'` instead of `'ASCII'`
    ///
    /// ### Why is this bad?
    ///

View on GitHub (pinned to e1e7af627c)