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
- Delete the file if nothing belongs in it
- Add the intended code (even a single export is enough)
- 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
- Delete stub files immediately after scaffolding, or fill them in the same commit
- Watch for files emptied by moves/refactors — git history keeps the content
- Keep triple-slash reference files; they are exempt by design
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
- Unexpected '{term}' comment: {display}
- Expect must have a corresponding matcher call.
- Matchers must be called to assert.
- Expect has an unknown modifier.
- Async assertions must be awaited.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/0ad37eb1c0d37472.
Report an issue: GitHub.