oxc-project/oxc · warning
Should not have leading or trailing spaces
Error message
Should not have leading or trailing spaces
What it means
Diagnostic from the shared jest/vitest `valid-title` rule (accidental_space_diagnostic). It fires when a test title has leading or trailing whitespace — `' saves a user '` — which is invisible in reports but breaks exact-name filtering and looks like a typo.
Source
Thrown at crates/oxc_linter/src/rules/shared/jest_vitest/valid_title.rs:42
OxcDiagnostic::warn("Title must be a string")
.with_help("Replace your title with a string")
.with_label(span)
}
fn empty_title_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Should not have an empty title")
.with_help("Write a meaningful title for your test")
.with_label(span)
}
fn duplicate_prefix_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Should not have duplicate prefix")
.with_help("The function name already has the prefix, try to remove the duplicate prefix")
.with_label(span)
}
fn accidental_space_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Should not have leading or trailing spaces")
.with_help("Remove the leading or trailing spaces")
.with_label(span)
}
fn disallowed_word_diagnostic(word: &str, span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("{word} is not allowed in test title"))
.with_help("It is included in the `disallowedWords` of your config file, try to remove it from your title")
.with_label(span)
}
pub fn must_match_diagnostic(message: &str, span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn(message.to_string())
.with_help("Make sure the title matches the `mustMatch` of your config file")
.with_label(span)
}
pub fn must_not_match_diagnostic(message: &str, span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn(message.to_string())View on GitHub (pinned to e1e7af627c)
Solutions
- Trim the title: `it('saves a user', fn)`.
- When composing titles programmatically, trim the result: `\`${base} ${case}\`.trim()`.
- Enable editor trim-on-save / whitespace visualization to catch stray spaces at authoring time.
Example fix
// before
it(' shows the dashboard ', () => { /* ... */ });
// after
it('shows the dashboard', () => { /* ... */ }); Defensive patterns
Strategy: validation
Validate before calling
const re = /\b(it|test|describe)(\.(skip|only|each))?\s*\(\s*(['"])[ \t]+|(['"])[ \t]+\s*,/;
if (re.test(src)) { console.error('title has leading/trailing spaces'); process.exitCode = 1; } Prevention
- Enable editor trim-whitespace-on-save for test files.
- Trim programmatically built titles: \`${base} ${name}\`.trim().
- Code-review generated tests for padded placeholders before committing.
When it happens
Trigger: String-literal titles whose trimmed value differs from the original: `it(' does nothing ', fn)`, `describe(' repo ', () => {})`, usually from sloppy paste or template building with stray spaces.
Common situations: Concatenated titles (`' ' + name`), copy-paste with trailing spaces editors don't render, and generator templates with padded placeholders.
Related errors
- Title must be a string
- Should not have an empty title
- Should not have duplicate prefix
- {word} is not allowed in test title
- {un_prefixed_name} should match {raw_pattern}
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/7049c141fc1fb08e.
Report an issue: GitHub.