{"record":{"id":"7049c141fc1fb08e","repo":"oxc-project/oxc","slug":"should-not-have-leading-or-trailing-spaces","errorCode":null,"errorMessage":"Should not have leading or trailing spaces","messagePattern":"Should not have leading or trailing spaces","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/shared/jest_vitest/valid_title.rs","lineNumber":42,"sourceCode":"    OxcDiagnostic::warn(\"Title must be a string\")\n        .with_help(\"Replace your title with a string\")\n        .with_label(span)\n}\n\nfn empty_title_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Should not have an empty title\")\n        .with_help(\"Write a meaningful title for your test\")\n        .with_label(span)\n}\n\nfn duplicate_prefix_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Should not have duplicate prefix\")\n        .with_help(\"The function name already has the prefix, try to remove the duplicate prefix\")\n        .with_label(span)\n}\n\nfn accidental_space_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Should not have leading or trailing spaces\")\n        .with_help(\"Remove the leading or trailing spaces\")\n        .with_label(span)\n}\n\nfn disallowed_word_diagnostic(word: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"{word} is not allowed in test title\"))\n        .with_help(\"It is included in the `disallowedWords` of your config file, try to remove it from your title\")\n        .with_label(span)\n}\n\npub fn must_match_diagnostic(message: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(message.to_string())\n        .with_help(\"Make sure the title matches the `mustMatch` of your config file\")\n        .with_label(span)\n}\n\npub fn must_not_match_diagnostic(message: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(message.to_string())","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/shared/jest_vitest/valid_title.rs#L24-L60","documentation":"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.","triggerScenarios":"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.","commonSituations":"Concatenated titles (`' ' + name`), copy-paste with trailing spaces editors don't render, and generator templates with padded placeholders.","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."],"exampleFix":"// before\nit('  shows the dashboard  ', () => { /* ... */ });\n\n// after\nit('shows the dashboard', () => { /* ... */ });","handlingStrategy":"validation","validationCode":"const re = /\\b(it|test|describe)(\\.(skip|only|each))?\\s*\\(\\s*(['\"])[ \\t]+|(['\"])[ \\t]+\\s*,/;\nif (re.test(src)) { console.error('title has leading/trailing spaces'); process.exitCode = 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["jest","vitest","oxlint","testing","test-title","whitespace","valid-title"],"backgroundTag":"invalid-test-title","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}