oxc-project/oxc · warning · OxcDiagnostic

{un_prefixed_name} should not match {raw_pattern}

Error message

{un_prefixed_name} should not match {raw_pattern}

What it means

Diagnostic from the shared jest/vitest `valid-title` rule (must_not_match path). It fires when a title (prefix-stripped) DOES match the regex configured in `mustNotMatch` — the inverse convention check. Typical use: forbid 'should'/'and' style titles or given/when/then filler that a style guide bans.

Source

Thrown at crates/oxc_linter/src/rules/shared/jest_vitest/valid_title.rs:60

    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())
        .with_help("Make sure the title does not match the `mustNotMatch` of your config file")
        .with_label(span)
}

pub const DOCUMENTATION: &str = r"
### What it does

Checks that the titles of Jest and Vitest blocks are valid.

Titles must be:
- not empty,
- strings,
- not prefixed with their block name,
- have no leading or trailing spaces.

### Why is this bad?

Titles that are not valid can be misleading and make it harder to understand the purpose of the test.

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Rewrite the title to avoid the banned pattern: 'adds two numbers' instead of 'should add numbers'.
  2. Scope or refine the regex so legitimate words are not caught (anchors, word boundaries).
  3. If the convention does not fit a subsystem, override `mustNotMatch` in that package's oxlint config rather than disabling the rule wholesale.

Example fix

// before
// config: "valid-title": ["error", { "mustNotMatch": "^should" }]
it('should add numbers', () => { /* ... */ });

// after
it('adds two numbers', () => { /* ... */ });
Defensive patterns

Strategy: validation

Validate before calling

const mustNotMatch = /^should/i; // mirror oxlint mustNotMatch
for (const [fn, title] of collectTestCalls(src)) {
  if (mustNotMatch.test(title)) console.warn(`title '${title}' matches mustNotMatch`);
}

Prevention

When it happens

Trigger: Configure `mustNotMatch` as a pattern string or `[pattern, flags]`, e.g. `{ "mustNotMatch": ["^should", "i"] }` or a ban on ' and '; a title like `it('should add numbers', fn)` matches and yields '{title} should not match {rawPattern}'.

Common situations: Teams migrating from 'should' phrasing to imperative titles and enforcing the ban; anti-pattern title bans ('works', 'handles the case') rolled out across a monorepo; false positives when the banned word appears inside an allowed phrase.

Related errors


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