Extend no-module-scope-test-setup to flag top-level describe scope#1087
Open
craigmarker wants to merge 10 commits intomainfrom
Open
Extend no-module-scope-test-setup to flag top-level describe scope#1087craigmarker wants to merge 10 commits intomainfrom
craigmarker wants to merge 10 commits intomainfrom
Conversation
JavaScript Coverage ReportTotal Coverage: 88.68% Coverage Policy:
Coverage Details |
📊 Combined Coverage Report
Coverage PolicyBaseline (Existing Code):
New/Changed Code: ≥90% STRICTLY ENFORCED Long-term Goal: Maintain and improve coverage baselines 📝 Coverage Guidelines
🔗 Quick Links |
8b66822 to
f6e4627
Compare
The outermost describe() in a test file is just structural — variables declared there are shared across all tests, same as module scope. Nested describes, however, are semantic groups (e.g. "disabled phases") where shared state is intentional and encouraged. Rule changes: - Flag vars at top-level describe scope (no parent describe) - Allow vars at nested describe scope (semantic grouping) - Recognize function boundaries as valid scopes (fixes false positive on component definitions like FormWrapper) - Add beforeEach + render guidance to error message - Add ADR-style markdown documenting the rule's design decisions Fix all 64 violations across 18 test files by inlining data as props, converting shared objects to factory functions, or moving setup into beforeEach where it feeds side-effectful operations like render(). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
select-field, radio-field, categorical-filter, and use-interpolation-resolver have >5 tests sharing the same data. Mechanically inlining is worse than restructuring into nested describes that share state semantically. Disable the rule for now and track the restructure as a follow-up issue. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Five files had zero-arg factory functions that were just `defaultProps` with extra steps — no overrides, no variations between tests. Replace with inlined props so each test declares exactly what it needs. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
21e3794 to
e45984c
Compare
The no-module-scope-test-setup rule now flags describe-scope setup, which caught violations in six test files. Four files had only import ordering issues, fixed via eslint --fix. multi-cell.tests.tsx had a mockRecord object at describe scope; inlined directly into the record prop in each render call. retry-cell.tests.tsx has shared mocks and a render helper that are legitimately structured at describe scope (same pattern as datetime-filter.test.tsx). Suppress with eslint-disable for now; restructure in a follow-up. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
craigmarker
commented
Apr 10, 2026
| }; | ||
|
|
||
| render(<Row items={mockItems} overrides={overrides} />); | ||
| render(<Row items={[{ id: 'name', label: 'Name' }]} overrides={overrides} />); |
Contributor
Author
There was a problem hiding this comment.
This is a great example of a shared fixture being used for a test that doesn't need all that comes with the fixture.
buildFilterableColumns() always returned the same base array with no parameters. Each test that needed a variation did its own .map() or spread after calling it. Removed the factory and inlined each test's data directly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Inline `objectValue` in get-cell-value-for-column.test.ts: single-use variable referenced in both createMockRow and toHaveBeenCalledWith; deep equality makes the variable unnecessary - Add `isDetailViewLoading: false` default to buildProps() factory and accept Partial overrides param in detail-view-table-page.test.tsx - Inline `runtimeProps` in table-view-adapter.test.ts: threaded through the function call then referenced in assertion; toEqual uses deep equality Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add factory function guidance to both the lint error message and the markdown doc. The error message points to the doc with a single line; the doc covers the full pattern with component and plain-function examples, plus the rule against spreading factory results and adding props separately. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…st-setup Remove JSDoc from internal helpers that narrate what the code already says (getCalleeName, hasParentDescribe, isStandaloneFunction). Trim the opening restatement from the isModuleScope JSDoc. Add inline comments at the three non-obvious spots: the MemberExpression branch in getCalleeName, the standalone function check in isModuleScope, and the !hasParentDescribe inversion. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
The outermost describe() in a test file is just structural — variables declared there are shared across all tests, same as module scope. Nested describes, however, are semantic groups (e.g. "disabled phases") where shared state is intentional and encouraged.
Rule changes:
Fix all 64 violations across 18 test files by inlining data as props, converting shared objects to factory functions, or moving setup into beforeEach where it feeds side-effectful operations like render().
What type of PR is this? (check all applicable)
What changed?
Why?
How did you test it?
Potential risks
Release notes
Documentation Changes