Skip to content

feat(rstest): add consistent-test-it rule - #2110

Merged
fansenze merged 3 commits into
mainfrom
feat/rstest-consistent-test-it
Sep 9, 2026
Merged

fansenze merged 3 commits into
mainfrom
feat/rstest-consistent-test-it

Conversation

@elecmonkey

@elecmonkey elecmonkey commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

Summary

Add rstest/consistent-test-it, which enforces a consistent choice between test and it when registering tests. By default it prefers test outside describe calls and it inside them, while fn and withinDescribe can be used to require a single convention or override the suite convention.

The rule resolves Rstest globals, imports from @rstest/core and rstack/test, namespace imports, destructured require bindings, import.meta.rstest, const aliases, fixture extension chains, modifiers, and parameterized .each / .for registrations. 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/playwright test registrations are exempt because that package exposes test but no it, 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's consistent-test-it.

Related Links

Related #935

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@fansenze fansenze left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Found three issues with autofix safety and parser performance.

Comment thread internal/plugins/rstest/utils/parse_rstest_fn.go Outdated
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.
@elecmonkey
elecmonkey requested a review from fansenze September 8, 2026 15:54

@fansenze fansenze left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The two unsafe autofix cases now pass, and the shared parser's performance has recovered. Two follow-ups remain:

Comment thread internal/plugins/rstest/rules/consistent_test_it/consistent_test_it.go Outdated
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
fansenze merged commit a3b2192 into main Sep 9, 2026
14 checks passed
@fansenze
fansenze deleted the feat/rstest-consistent-test-it branch September 9, 2026 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants