Skip to content

feat(vitest): [titleValidity] add rule - #3191

Draft
ysknsid25 wants to merge 3 commits into
flint-fyi:mainfrom
ysknsid25:feat/vitest-title-validity
Draft

feat(vitest): [titleValidity] add rule#3191
ysknsid25 wants to merge 3 commits into
flint-fyi:mainfrom
ysknsid25:feat/vitest-title-validity

Conversation

@ysknsid25

@ysknsid25 ysknsid25 commented Aug 9, 2026

Copy link
Copy Markdown

PR Checklist

Overview

The implementation and tests closely mirror the Vitest implementation.

For review:

@changeset-bot

changeset-bot Bot commented Aug 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1c6177e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@flint.fyi/rule-data Patch
@flint.fyi/vitest Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify

netlify Bot commented Aug 9, 2026

Copy link
Copy Markdown

Deploy Preview for flint-fyi ready!

Name Link
🔨 Latest commit 1c6177e
🔍 Latest deploy log https://app.netlify.com/projects/flint-fyi/deploys/6a792feafc183b000847133a
😎 Deploy Preview https://deploy-preview-3191--flint-fyi.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions

This comment has been minimized.

@michaelfaith michaelfaith left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! Some feedback from my side.

"@flint.fyi/vitest": patch
---

[titleValidity] add rule.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[titleValidity] add rule.
Added `titleValidity` rule, which aims to enforce valid titles for `describe()`, `it()` and `test()` titles.

Comment on lines +141 to +145
declare const value: unknown;

describe(typeof value, () => {
// ...
});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example is not what the vitest equivalent option permits (or what the description above describes.

Not set by default.

A string or a `[pattern, message]` pair applies to `describe`, `it`, and `test` alike.
An object applies a separate pattern per function:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
An object applies a separate pattern per function:
Using an object with `describe`, `it`, and/or `test` properties, you can apply a different match pattern for each function:

Regular expressions that titles must match, optionally with a custom message.
Not set by default.

A string or a `[pattern, message]` pair applies to `describe`, `it`, and `test` alike.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we've deviated from the API of the eslint equivalent of this option? I.e. having a pattern/message array instead of having an array of regexes?

],
});

ruleTester.describe(rule, {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are there multiple calls to ruleTester.describe? Each rule should have one top-level describe.

message: mustNotMatch.message ? "mustNotMatchCustom" : "mustNotMatch",
range,
});
return;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why return here? If the title both matches something it shouldn't and doesn't match something it should, wouldn't we want to report both? Rather than only reporting one, they fix that, and then we report the other...

const [pattern, message] =
typeof matcher === "string" ? ([matcher] as const) : matcher;

return { message, pattern: new RegExp(pattern, "u") };

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to cache these RegExp objects. We'll end up remaking RegExp objects with the same patterns, over and over and over again, which has a non-trivial impact over time.

Comment on lines +255 to +258
const disallowedMatch = new RegExp(
`\\b(${options.disallowedWords.join("|")})\\b`,
"iu",
).exec(title);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're just creating this RegExp using it and then throwing it away. Can we not create it in the setup scope and reuse it with every call?

Comment on lines +273 to +275
const trimmed = text
.replace(/^(['"`])\s+/u, "$1")
.replace(/\s+(['"`])$/u, "$1");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this could be simplified into a single regex (and that regex pulled out to the module scope so we're only creating one instance). And would this be easier by just identifying which quote type the original used and surround title.trim() with those?

presets: ["logical", "logicalStrict"],
},
messages: {
accidentalSpace: {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
accidentalSpace: {
unnecessarySpace: {

We don't know whether it's accidental or not. But we do know it's unnecessary

@michaelfaith michaelfaith added the status: waiting for author Needs an action taken by the original poster label Aug 10, 2026
@codecov

codecov Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.36620% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
packages/vitest/src/rules/titleValidity.ts 94.36% 1 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

@ysknsid25
ysknsid25 marked this pull request as draft August 10, 2026 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting for author Needs an action taken by the original poster

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🚀 Feature: [vitest] Create titleValidity rule

3 participants