oxc-project/oxc · info · OxcDiagnostic

Empty files are not allowed.

Error message

Empty files are not allowed.

What it means

Diagnostic from the oxlint rule `unicorn/no-empty-file` (category: correctness). A file counts as empty when every top-level statement is non-executable: only whitespace, comments, directives like `'use strict'`, empty statements `;`, empty blocks `{}`, or a lone hashbang. Such files are usually accidental (bad merges, emptied stubs, scaffolding leftovers) and mislead both readers and tooling. Files whose only content is a triple-slash directive (`/// <reference ...>`) are exempt; disable comments within the first 100 characters of the file are honored.

Source

Thrown at crates/oxc_linter/src/rules/unicorn/no_empty_file.rs:13

use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;

use crate::{
    context::{ContextHost, LintContext},
    loader::LINT_PARTIAL_LOADER_EXTENSIONS,
    rule::Rule,
    utils::is_empty_stmt,
};

fn no_empty_file_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Empty files are not allowed.")
        .with_help("Delete this file or add some code to it.")
        .with_label(span)
}

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

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Disallows files that do not contain any meaningful code.
    ///
    /// This includes files that consist only of:
    /// - Whitespace
    /// - Comments
    /// - Directives (e.g., `"use strict"`)
    /// - Empty statements (`;`)
    /// - Empty blocks (`{}`)

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Delete the file if nothing belongs in it
  2. Add the intended code (even a single export is enough)
  3. If a placeholder is genuinely required, ignore the path in .oxlintrc.json or put an inline disable comment at the top of the file
Defensive patterns

Strategy: validation

Validate before calling

# find candidate empty files before linting
find src -type f \( -name '*.js' -o -name '*.ts' \) -size -2c

Prevention

When it happens

Trigger: A source file containing only `// comment`, `;`, `{}`, `'use strict';`, a hashbang, or nothing at all. Any real statement, expression, or export makes the file pass; partial-loader extensions are skipped entirely.

Common situations: Placeholder `index.js` committed before code exists; a file emptied when its contents moved elsewhere; scaffolding/generators producing stub files; hygiene sweeps after enabling the unicorn preset.

Related errors


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