feat(eslint-rules): add base-hook-no-forbidden-runtime rule#36253
Open
Hotell wants to merge 2 commits into
Open
feat(eslint-rules): add base-hook-no-forbidden-runtime rule#36253Hotell wants to merge 2 commits into
Hotell wants to merge 2 commits into
Conversation
Registers @nx/workspace-base-hook-no-forbidden-runtime. Rule is not yet enabled in any project config and is fully inert until wired up in a follow-up PR.
📊 Bundle size report✅ No changes found |
|
Pull request demo site: URL |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new workspace ESLint rule (@nx/workspace-base-hook-no-forbidden-runtime) intended to prevent v9 use*Base_unstable hooks from (directly or transitively) depending on forbidden runtime packages, with a dedicated typed + untyped test/fixture setup.
Changes:
- Introduces the
base-hook-no-forbidden-runtimerule with transitive import-graph reach analysis (value vs type reach) and a one-shot warning when type info is missing. - Adds RuleTester coverage plus a self-contained fixture workspace (stub packages + tsconfig) to validate transitive reach and cycle handling.
- Updates eslint-rules workspace config to exclude fixture files from lint compilation, and registers the rule in the workspace rules index.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/eslint-rules/tsconfig.lint.json | Excludes __fixtures__ from lint tsconfig to avoid fixture compilation/lint noise. |
| tools/eslint-rules/rules/base-hook-no-forbidden-runtime.ts | Implements the new rule, including import tracking, scope analysis, and transitive reach computation. |
| tools/eslint-rules/rules/base-hook-no-forbidden-runtime.spec.ts | Adds untyped + typed RuleTester suites covering direct forbidden imports, transitive reach, and cycles. |
| tools/eslint-rules/rules/fixtures/base-hook-no-forbidden-runtime/tsconfig.json | Fixture TS project config with path mappings to stub packages for typed tests. |
| tools/eslint-rules/rules/fixtures/base-hook-no-forbidden-runtime/stubs/watched-pkg/light.ts | Stub “light” module that should not reach the forbidden runtime. |
| tools/eslint-rules/rules/fixtures/base-hook-no-forbidden-runtime/stubs/watched-pkg/index.ts | Stub package entrypoint with mixed value/type re-exports to exercise reach semantics. |
| tools/eslint-rules/rules/fixtures/base-hook-no-forbidden-runtime/stubs/watched-pkg/heavy.ts | Stub “heavy” module that imports the forbidden runtime. |
| tools/eslint-rules/rules/fixtures/base-hook-no-forbidden-runtime/stubs/light-helper/index.ts | Stub helper package used by the “light” module. |
| tools/eslint-rules/rules/fixtures/base-hook-no-forbidden-runtime/stubs/heavy-runtime/index.ts | Stub forbidden runtime package used to validate direct + transitive blocking. |
| tools/eslint-rules/rules/fixtures/base-hook-no-forbidden-runtime/stubs/cyclic-pkg/index.ts | Stub cyclic package entrypoint to exercise cycle safety. |
| tools/eslint-rules/rules/fixtures/base-hook-no-forbidden-runtime/stubs/cyclic-pkg/b.ts | Part of a cyclic import graph in the fixture. |
| tools/eslint-rules/rules/fixtures/base-hook-no-forbidden-runtime/stubs/cyclic-pkg/a.ts | Part of a cyclic import graph in the fixture. |
| tools/eslint-rules/rules/fixtures/base-hook-no-forbidden-runtime/src/test.ts | Placeholder file so the typed Program contains the filename used in RuleTester cases. |
| tools/eslint-rules/rules/fixtures/base-hook-no-forbidden-runtime/src/dummy.ts | Additional placeholder/anchor file in the fixture project. |
| tools/eslint-rules/index.ts | Registers the new rule in the exported workspace rules map. |
Cache in-progress reach results to preserve transitive closure across import cycles, normalize diagnostic paths cross-platform, and add cyclic regression fixtures/tests.
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
Introduces a new workspace ESLint rule
@nx/workspace-base-hook-no-forbidden-runtimethat preventsuseFooBase/useFooBase_unstablehooks from pulling in heavy runtime dependencies. It walks the imports of the base-hook module and flags transitive dependencies on packages outside an allowlist.The rule is fully inert in this PR — it is registered with
@nx/workspacebut not enabled in any project config. Wiring happens in a follow-up PR.Plan reference
Part of the split of #36251 — see
prd/eslint-rules-base-hook-pr-split.spec.md(PR2).Fixtures
Self-contained fixture workspace under
tools/eslint-rules/rules/__fixtures__/base-hook-no-forbidden-runtime/includes a localtsconfig.jsonplus stub packages:light-helper,heavy-runtime,watched-pkg(withlight.ts/heavy.tspaths), andcyclic-pkg(a → b → index → a cycle) to verify cycle handling.Verification
→ 4 suites / 56 tests pass.
ESLint CLI perf (TIMING=200)
Measured on a combined branch (PR1 + PR2 + PR3 wiring) so the rule actually runs.
@nx/workspace-base-hook-no-forbidden-runtimereact-button(no*Basehook)react-combobox(1*Basehook)react-tags(1*Basehook)Negligible — the rule short-circuits on non-base-hook files and the import graph walk is bounded + cycle-safe.
Out of scope
@fluentui/eslint-plugin(separate PR).