feat(rstest): add consistent-test-it rule - #2110
Merged
Merged
Conversation
fansenze
reviewed
Sep 8, 2026
fansenze
left a comment
Contributor
There was a problem hiding this comment.
Found three issues with autofix safety and parser performance.
Move the registration shadowing filter out of the shared Rstest call parser and into the rule, gated by a one-pass index of the file's declaration names, so every other parser user stops paying a per-call scope walk. Withhold the fix when a class static block hoists a `var` named after the preferred API, and when a CommonJS binding is declared with `let` or `var` and can therefore be reassigned after its declaration.
fansenze
reviewed
Sep 9, 2026
fansenze
left a comment
Contributor
There was a problem hiding this comment.
The two unsafe autofix cases now pass, and the shared parser's performance has recovered. Two follow-ups remain:
Memoize the scope walk per (scope, name), and keep member names out of
the declaration-name index. An unrelated `const helper = { it() {} }` or
a parameter named `it` made the file-wide index match, putting a full
walk on every registration; 5000 global registrations took about 1.2 s
and now take about 4 ms.
Spell `reassignable` as `mutable` in two test comments.
fansenze
approved these changes
Sep 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add
rstest/consistent-test-it, which enforces a consistent choice betweentestanditwhen registering tests. By default it preferstestoutsidedescribecalls anditinside them, whilefnandwithinDescribecan be used to require a single convention or override the suite convention.The rule resolves Rstest globals, imports from
@rstest/coreandrstack/test, namespace imports, destructuredrequirebindings,import.meta.rstest, const aliases, fixture extension chains, modifiers, and parameterized.each/.forregistrations. It reports non-registration references without treating imports as standalone violations, preserves existing bindings when fixing calls, and withholds fixes when the preferred name would be captured by another binding or when the call's binding could have been reassigned.@rstest/playwrighttest registrations are exempt because that package exposestestbut noit, which the shared Rstest call parser now reports as provenance. Spellings shadowed by a local TypeScript namespace are filtered by the rule rather than by the parser, so no other parser user pays for that scope walk.Credits
Port from
eslint-plugin-jest's and@vitest/eslint-plugin'sconsistent-test-it.Related Links
Related #935
Checklist