oxc-project/oxc · error · OxcDiagnostic

This {kind} default export is missing a name

Error message

This {kind} default export is missing a name

What it means

Raised by unicorn/no-anonymous-default-export when the default export is an anonymous function or class (inline `export default function() {}` or `class {}`). The helper maps the node kind to 'function'/'class' for the message; the faulting input is the anonymous default export declaration at the labeled span.

Source

Thrown at crates/oxc_linter/src/rules/unicorn/no_anonymous_default_export.rs:17

use oxc_ast::{
    AstKind,
    ast::{AssignmentExpression, AssignmentTarget, ExportDefaultDeclarationKind, Expression},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;

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

fn no_anonymous_default_export_diagnostic(span: Span, kind: ErrorNodeKind) -> OxcDiagnostic {
    let kind = match kind {
        ErrorNodeKind::Function => "function",
        ErrorNodeKind::Class => "class",
    };

    OxcDiagnostic::warn(format!("This {kind} default export is missing a name"))
        // TODO: suggest a name. https://github.com/sindresorhus/eslint-plugin-unicorn/blob/d3e4b805da31c6ed7275e2e2e770b6b0fbcf11c2/rules/no-anonymous-default-export.js#L41
        .with_label(span)
}

#[derive(Debug, Default, Clone)]
pub struct NoAnonymousDefaultExport;

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Disallows anonymous functions and classes as default exports.
    ///
    /// ### Why is this bad?
    ///
    /// Naming default exports improves searchability and ensures consistent
    /// identifiers for a module’s default export in both declaration and import.
    ///
    /// ### Examples

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Give the function or class a name: `export default function myFunction() {}`
  2. Assign the anonymous value to a named variable/const and export that instead
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/unicorn/no_anonymous_default_export.rs:17 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/accaece1133c40d7. Report an issue: GitHub.