Skip to content

refactor: store error codes in OxcDiagnostic #4333

@DonIsaac

Description

@DonIsaac

Instead of inlining error codes into messages (e.g. eslint(eqeqeq): use '===' instead of '=='), they should be stored separately.
This will let us

  • configure codes automatically for lint rules
  • support hyperlinks in the future

Tasks

First, change OxcDiagnosticInner from

pub struct OxcDiagnosticInner {
    pub message: Cow<'static, str>,
    pub labels: Option<Vec<LabeledSpan>>,
    pub help: Option<Cow<'static, str>>,
    pub severity: Severity,
}

To:

pub struct OxcDiagnosticInner {
    pub message: Cow<'static, str>,
    pub labels: Option<Vec<LabeledSpan>>,
    pub help: Option<Cow<'static, str>>,
    pub severity: Severity,
    pub code_scope: Option<Cow<'static, str>>, // eg `eslint`
    pub code_num: Option<Cow<'static, str>>,   // eg `eqeqeq`
}

Next, update LintContext to set code_scope and code_num before running a rule.

Finally, update all lint rule diagnostics to remove their inlined error codes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-cleanupCategory - technical debt or refactoring. Solution not expected to change behavior

    Type

    No type

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions