oxc-project/oxc · error · OxcDiagnostic
The file {file_path} is a test file, but its name does not m
Error message
The file {file_path} is a test file, but its name does not match the expected pattern. What it means
Emitted by the vitest/consistent-test-filename rule during the run-once pass for every file that vitest treats as a test file but whose path does not match the configured naming pattern (e.g. `*.spec.ts` vs `*.test.ts`). It fires on the file as a whole, not on a specific AST node.
Source
Thrown at crates/oxc_linter/src/rules/vitest/consistent_test_filename.rs:20
use lazy_regex::{Regex, RegexBuilder};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use schemars::JsonSchema;
use serde::Deserialize;
use crate::{
context::LintContext,
rule::{DefaultRuleConfig, Rule},
};
fn consistent_test_filename_diagnostic(file_path: &str, pattern: &str) -> OxcDiagnostic {
let message = format!(
"The file {file_path} is a test file, but its name does not match the expected pattern."
);
let help = format!("Rename the file that match the pattern {pattern}");
OxcDiagnostic::warn(message).with_help(help)
}
#[derive(Debug, Default, Clone, Deserialize)]
pub struct ConsistentTestFilename(Box<ConsistentTestFilenameConfig>);
#[derive(Debug, Clone, Deserialize, JsonSchema)]
pub struct CompiledAllTestPattern(
#[serde(deserialize_with = "deserialize_matcher_pattern")] lazy_regex::Regex,
);
impl Default for CompiledAllTestPattern {
fn default() -> Self {
Self(
Regex::new(r".*\.(test|spec)\.[tj]sx?$")
.expect("default all-test pattern should be valid"),
)
}
}View on GitHub (pinned to e1e7af627c)
Solutions
- Rename the file to match the expected pattern shown in the help message
- Or adjust the rule's `pattern` option to accept your naming convention
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/vitest/consistent_test_filename.rs:20 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/7260865579f27cc9.
Report an issue: GitHub.