-
-
Notifications
You must be signed in to change notification settings - Fork 725
feat(linter): add import/no-extraneous-dependencies rule #15703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(linter): add import/no-extraneous-dependencies rule #15703
Conversation
Port eslint-plugin-import's extraneous dependency check so oxlint flags missing or miscategorized packages using project package.json files. Adds fixtures, snapshots, registration, and the regex dependency. Tests: cargo test -p oxc_linter no_extraneous_dependencies -- --nocapture.
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements the ESLint import/no-extraneous-dependencies rule for oxc_linter, ensuring that all imported modules are declared in the nearest package.json file. The implementation resolves package.json files, supports multiple dependency types (dev, optional, peer, bundled), and provides glob-based file pattern matching for configuration.
Key changes:
- Added comprehensive dependency validation logic that checks imports/requires against package.json declarations
- Implemented support for
packageDirconfiguration (string or array) to specify custom package.json locations - Added
includeInternalandincludeTypesoptions with regex-based internal module detection
Reviewed Changes
Copilot reviewed 8 out of 13 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
crates/oxc_linter/src/rules/import/no_extraneous_dependencies.rs |
Main rule implementation with AST visitors, package.json parsing, and dependency classification logic |
crates/oxc_linter/src/rules.rs |
Registers the new rule in the import plugin module |
crates/oxc_linter/src/generated/rule_runner_impls.rs |
Auto-generated runner configuration for the rule |
crates/oxc_linter/Cargo.toml |
Adds regex dependency for internal module pattern matching |
Cargo.toml |
Adds regex 1.12.2 to workspace dependencies |
Cargo.lock |
Updates lock file with regex dependency |
crates/oxc_linter/src/snapshots/import_no_extraneous_dependencies.snap |
Snapshot tests for standard dependency violations |
crates/oxc_linter/src/snapshots/import_no_extraneous_dependencies@_glob.snap |
Snapshot tests for glob pattern matching |
crates/oxc_linter/fixtures/import/no_extraneous_dependencies/package.json |
Test fixture with various dependency types |
crates/oxc_linter/fixtures/import/no_extraneous_dependencies/custom_pkg/package.json |
Test fixture for custom packageDir configuration |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
crates/oxc_linter/src/rules/import/no_extraneous_dependencies.rs
Outdated
Show resolved
Hide resolved
crates/oxc_linter/src/rules/import/no_extraneous_dependencies.rs
Outdated
Show resolved
Hide resolved
crates/oxc_linter/src/rules/import/no_extraneous_dependencies.rs
Outdated
Show resolved
Hide resolved
crates/oxc_linter/src/rules/import/no_extraneous_dependencies.rs
Outdated
Show resolved
Hide resolved
crates/oxc_linter/src/rules/import/no_extraneous_dependencies.rs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 6 out of 10 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
import/no-extraneous-dependenciesrule intooxc_linter, resolving the nearestpackage.json, honoring includeInternal/includeTypes toggles, glob-based allowances for dev/optional/peer/bundled dependencies, and skipping Node built-ins/internal modules by regexpackageDiras either a string or an array to stay compatible with ESLint config, add the requiredfast-globdependency, and register the rule in the generated runner and rule listTesting
cargo test -p oxc_linter import::no-extraneous-dependenciesjust test