-
-
Notifications
You must be signed in to change notification settings - Fork 794
feat(no_namespace_import): add allowlist option #8010
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: next
Are you sure you want to change the base?
feat(no_namespace_import): add allowlist option #8010
Conversation
Introduces an 'allowlist' option to the noNamespaceImport lint rule, allowing specific modules to use namespace imports without triggering diagnostics. Updates rule logic, options struct, and adds tests for valid and invalid cases with allowlist configuration.
🦋 Changeset detectedLatest commit: b4b97f8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 14 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
WalkthroughAdds an Suggested labels
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
crates/biome_js_analyze/tests/specs/performance/noNamespaceImport/invalidWithAllowlist.js (1)
1-3: Clarify the test comment.The comment only mentions "other-lib" but doesn't explain that line 2 (zod) should NOT trigger a diagnostic because it's in the allowlist. Consider updating for clarity:
-/* should generate diagnostic because "other-lib" is not in the allowlist */ +/* should generate diagnostic for "other-lib" (not in allowlist) but not for "zod" (in allowlist) */
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
crates/biome_js_analyze/tests/specs/performance/noNamespaceImport/invalidWithAllowlist.js.snapis excluded by!**/*.snapand included by**crates/biome_js_analyze/tests/specs/performance/noNamespaceImport/validWithAllowlist.js.snapis excluded by!**/*.snapand included by**
📒 Files selected for processing (6)
crates/biome_js_analyze/src/lint/performance/no_namespace_import.rs(3 hunks)crates/biome_js_analyze/tests/specs/performance/noNamespaceImport/invalidWithAllowlist.js(1 hunks)crates/biome_js_analyze/tests/specs/performance/noNamespaceImport/invalidWithAllowlist.options.json(1 hunks)crates/biome_js_analyze/tests/specs/performance/noNamespaceImport/validWithAllowlist.js(1 hunks)crates/biome_js_analyze/tests/specs/performance/noNamespaceImport/validWithAllowlist.options.json(1 hunks)crates/biome_rule_options/src/no_namespace_import.rs(1 hunks)
🧰 Additional context used
🧠 Learnings (14)
📚 Learning: 2025-10-15T09:22:15.851Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:15.851Z
Learning: Applies to crates/biome_formatter/tests/specs/**/options.json : Use options.json files colocated with test inputs to override formatting options for all files in that folder
Applied to files:
crates/biome_js_analyze/tests/specs/performance/noNamespaceImport/invalidWithAllowlist.options.jsoncrates/biome_js_analyze/tests/specs/performance/noNamespaceImport/validWithAllowlist.options.json
📚 Learning: 2025-08-05T14:43:29.581Z
Learnt from: dyc3
Repo: biomejs/biome PR: 7081
File: packages/@biomejs/biome/configuration_schema.json:7765-7781
Timestamp: 2025-08-05T14:43:29.581Z
Learning: The file `packages/biomejs/biome/configuration_schema.json` is auto-generated and should not be manually edited or reviewed for schema issues; any changes should be made at the code generation source.
Applied to files:
crates/biome_js_analyze/tests/specs/performance/noNamespaceImport/invalidWithAllowlist.options.jsoncrates/biome_js_analyze/tests/specs/performance/noNamespaceImport/validWithAllowlist.options.json
📚 Learning: 2025-09-25T12:32:59.003Z
Learnt from: arendjr
Repo: biomejs/biome PR: 7593
File: crates/biome_service/src/workspace/server.rs:1306-1306
Timestamp: 2025-09-25T12:32:59.003Z
Learning: In the biomejs/biome project, do not flag compilation errors during code review as they are handled by the existing test infrastructure and CI. Focus on other code quality aspects instead.
Applied to files:
crates/biome_js_analyze/tests/specs/performance/noNamespaceImport/invalidWithAllowlist.options.jsoncrates/biome_js_analyze/tests/specs/performance/noNamespaceImport/validWithAllowlist.options.json
📚 Learning: 2025-10-15T09:22:46.002Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:46.002Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : Import and use the `FormatNode` trait for AST nodes
Applied to files:
crates/biome_js_analyze/src/lint/performance/no_namespace_import.rs
📚 Learning: 2025-10-15T09:22:46.002Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:46.002Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : Do not attempt to fix code; if a mandatory token/node is missing, return `None` instead
Applied to files:
crates/biome_js_analyze/src/lint/performance/no_namespace_import.rs
📚 Learning: 2025-10-15T09:23:33.055Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:23:33.055Z
Learning: Applies to crates/biome_js_type_info/biome_module_graph/src/js_module_info/scoped_resolver.rs : Full inference must resolve TypeReference::Import across modules to TypeReference::Resolved when the target is available in the module graph.
Applied to files:
crates/biome_js_analyze/src/lint/performance/no_namespace_import.rs
📚 Learning: 2025-10-15T09:22:46.002Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:46.002Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : Implement the `Format` trait for your node type and use `JsFormatter` with `write!`/`format_args!` to define formatting
Applied to files:
crates/biome_js_analyze/src/lint/performance/no_namespace_import.rs
📚 Learning: 2025-10-15T09:23:33.055Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:23:33.055Z
Learning: Applies to crates/biome_js_type_info/biome_module_graph/src/js_module_info/collector.rs : Thin (module-level) inference should resolve local and global bindings to TypeReference::Resolved, mark imported bindings as TypeReference::Import, and fall back to TypeReference::Unknown if unresolved.
Applied to files:
crates/biome_js_analyze/src/lint/performance/no_namespace_import.rs
📚 Learning: 2025-10-15T09:23:33.055Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:23:33.055Z
Learning: Applies to crates/biome_js_type_info/biome_module_graph/src/**/*.rs : Do not copy or clone data between module graph entries (including behind Arc). Each module must avoid holding duplicated data from another module to enable simple invalidation.
Applied to files:
crates/biome_js_analyze/src/lint/performance/no_namespace_import.rs
📚 Learning: 2025-10-15T09:22:46.002Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:46.002Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : Use `dbg_write!` to debug and inspect the emitted IR during formatting
Applied to files:
crates/biome_js_analyze/src/lint/performance/no_namespace_import.rs
📚 Learning: 2025-10-15T09:22:46.002Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:46.002Z
Learning: Applies to crates/biome_js_formatter/**/Cargo.toml : Declare the dependency `biome_js_formatter = { version = "0.0.1", path = "../biome_js_formatter" }` for internal installation
Applied to files:
crates/biome_js_analyze/src/lint/performance/no_namespace_import.rs
📚 Learning: 2025-10-15T09:22:46.002Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:46.002Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : When a token is mandatory and present in the AST, use the AST-provided token (e.g., `node.l_paren_token().format()`) instead of emitting a static token
Applied to files:
crates/biome_js_analyze/src/lint/performance/no_namespace_import.rs
📚 Learning: 2025-10-15T09:22:15.851Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:15.851Z
Learning: Applies to crates/biome_formatter/src/**/*.rs : After generation, remove usages of `format_verbatim_node` and implement real formatting with biome_formatter utilities
Applied to files:
crates/biome_js_analyze/src/lint/performance/no_namespace_import.rs
📚 Learning: 2025-10-15T09:23:33.055Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:23:33.055Z
Learning: Applies to crates/biome_js_type_info/src/{type_info,local_inference,resolver,flattening}.rs : Avoid recursive type structures and cross-module Arcs; represent links between types using TypeReference and TypeData::Reference.
Applied to files:
crates/biome_rule_options/src/no_namespace_import.rs
🧬 Code graph analysis (2)
crates/biome_js_analyze/src/lint/performance/no_namespace_import.rs (1)
crates/biome_js_factory/src/generated/node_factory.rs (1)
js_module_source(2553-2558)
crates/biome_rule_options/src/no_namespace_import.rs (1)
packages/@biomejs/backend-jsonrpc/src/workspace.ts (1)
NoNamespaceImportOptions(8415-8415)
🔇 Additional comments (8)
crates/biome_rule_options/src/no_namespace_import.rs (2)
1-10: LGTM! Struct definition looks solid.The allowlist field and serde configuration are appropriate for this use case.
12-18: Merge implementation is correct.Standard last-write-wins semantics—when
other.allowlistisSome, it overwritesself.allowlist. This is appropriate for configuration merging.crates/biome_js_analyze/tests/specs/performance/noNamespaceImport/validWithAllowlist.options.json (1)
1-15: Test configuration looks correct.crates/biome_js_analyze/src/lint/performance/no_namespace_import.rs (3)
33-50: Documentation is clear and helpful.Good examples showing practical usage of the allowlist feature.
6-6: Import is correct.
AnyJsModuleSourceis needed to extract the module name from the import source.
75-91: Allowlist checking logic is sound.The iterator chain correctly unwraps
Option<Box<[Box<str>]>>→ slice → individual items. Error handling is conservative: if the module name can't be extracted, the diagnostic is still emitted, which is the safe default.crates/biome_js_analyze/tests/specs/performance/noNamespaceImport/validWithAllowlist.js (1)
1-3: Test case is clear and correct.The imports align with the allowlist configuration, properly testing that allowlisted modules don't trigger diagnostics.
crates/biome_js_analyze/tests/specs/performance/noNamespaceImport/invalidWithAllowlist.options.json (1)
1-15: Configuration looks good.The test configuration correctly sets up the allowlist for the
invalidWithAllowlisttest case. Modules listed in the allowlist (in this case,"zod") will be exempt from the rule, allowing the test to verify that non-allowlisted modules still trigger diagnostics as expected.
ematipico
left a comment
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.
Thank you! I believe the addition of an option is sound. I left some comments that must be addressed
CodSpeed Performance ReportMerging #8010 will not alter performanceComparing Summary
Footnotes
|
|
@ematipico i believe i've resolved everything, lmk if i missed something. |
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.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
.changeset/thirty-goats-rescue.md(1 hunks)crates/biome_js_analyze/src/lint/performance/no_namespace_import.rs(3 hunks)crates/biome_js_analyze/tests/specs/performance/noNamespaceImport/invalidWithAllowlist.options.json(1 hunks)crates/biome_js_analyze/tests/specs/performance/noNamespaceImport/validWithAllowlist.options.json(1 hunks)crates/biome_rule_options/src/no_namespace_import.rs(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
- crates/biome_js_analyze/tests/specs/performance/noNamespaceImport/validWithAllowlist.options.json
- crates/biome_js_analyze/src/lint/performance/no_namespace_import.rs
- crates/biome_js_analyze/tests/specs/performance/noNamespaceImport/invalidWithAllowlist.options.json
- .changeset/thirty-goats-rescue.md
🧰 Additional context used
🧠 Learnings (5)
📚 Learning: 2025-10-15T09:23:33.055Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:23:33.055Z
Learning: Applies to crates/biome_js_type_info/biome_module_graph/src/**/*.rs : Do not copy or clone data between module graph entries (including behind Arc). Each module must avoid holding duplicated data from another module to enable simple invalidation.
Applied to files:
crates/biome_rule_options/src/no_namespace_import.rs
📚 Learning: 2025-10-15T09:23:33.055Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:23:33.055Z
Learning: Applies to crates/biome_js_type_info/src/{type_info,local_inference,resolver,flattening}.rs : Avoid recursive type structures and cross-module Arcs; represent links between types using TypeReference and TypeData::Reference.
Applied to files:
crates/biome_rule_options/src/no_namespace_import.rs
📚 Learning: 2025-10-15T09:22:15.851Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:15.851Z
Learning: Applies to crates/biome_formatter/src/**/*.rs : After generation, remove usages of `format_verbatim_node` and implement real formatting with biome_formatter utilities
Applied to files:
crates/biome_rule_options/src/no_namespace_import.rs
📚 Learning: 2025-10-15T09:23:33.055Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:23:33.055Z
Learning: Applies to crates/biome_js_type_info/biome_module_graph/src/js_module_info/scoped_resolver.rs : Full inference must resolve TypeReference::Import across modules to TypeReference::Resolved when the target is available in the module graph.
Applied to files:
crates/biome_rule_options/src/no_namespace_import.rs
📚 Learning: 2025-10-15T09:24:31.042Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:24:31.042Z
Learning: Applies to crates/biome_parser/crates/biome_*_{syntax,factory}/** : Create per-language crates biome_<lang>_syntax and biome_<lang>_factory under crates/
Applied to files:
crates/biome_rule_options/src/no_namespace_import.rs
🧬 Code graph analysis (1)
crates/biome_rule_options/src/no_namespace_import.rs (1)
packages/@biomejs/backend-jsonrpc/src/workspace.ts (1)
NoNamespaceImportOptions(8415-8415)
🔇 Additional comments (2)
crates/biome_rule_options/src/no_namespace_import.rs (2)
1-3: ManualMergeimplementation looks correct.Removing
Mergefrom the derive list and imports is the right approach when implementing the trait manually.
6-10: Field definition and naming convention are sound.The
allowed_modulesname is semantically appropriate for an allow-list field. Other rules useignore/ignoresfor deny-lists, which is a distinct semantic pattern—this differentiation is intentional and correct.
There's one thing missing. The PR must be merged in the |
ematipico
left a comment
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.
We're almost there. We need more tests, and make sure we correctly understand the purpose of this new option. Once we understand it, more tests should be added, and docs should be aligned.
crates/biome_js_analyze/src/lint/performance/no_namespace_import.rs
Outdated
Show resolved
Hide resolved
| #[serde(skip_serializing_if = "Vec::is_empty")] | ||
| pub allowed_modules: Vec<String>, | ||
| } |
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.
I recommend overriding options upon merging:
| #[serde(skip_serializing_if = "Vec::is_empty")] | |
| pub allowed_modules: Vec<String>, | |
| } | |
| #[serde(skip_serializing_if = "Option::<_>::is_none")] | |
| pub allowed_modules: Option<Box<[Box<str>]>>, | |
| } | |
| impl biome_deserialize::Merge for NoBitwiseOperatorsOptions { | |
| fn merge_with(&mut self, other: Self) { | |
| if let Some(allowed_modules) = other.allowed_modules { | |
| self.allowed_modules = Some(allowed_modules); | |
| } | |
| } | |
| } |
This aligns with other rules' options.
At call site you can use allowed_modules.iter().flatten() instead of allowed_modules.iter()
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.
If possible, let's avoid Box. In other rules, it's been a perf bottleneck
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.
it's been a perf bottleneck
We have no evidence about that. If I remember correctly, @arendjr tried to use Vec instead and don't find evidence of perf overhead.
However, we have no evidence for the reverse either.
Thus, I accept any choice.
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.
I've seen cases where it caused overhead indeed, but then when I switched to Vec instead it turned out it wasn't the actual bottleneck. So while it does cause overhead, calling it a bottleneck is probably too strong. But yeah, by default I would suggest using Vec, except in situations where there is a very strong argument against the extra memory usage.
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.
Turning a Vec into a box should not re-allocate if the Vec length is equal to its capacity. Our JSON deserializer should more or less guarantee this (to be checked).
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.
Our JSON deserializer should more or less guarantee this (to be checked).
I am very sceptical of this claim :)
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.
|
Hey @ematipico made the requested changes. Might need a resolution on how to resolve that one conversation above though. |
|
@haydenbleasel please make sure to fix the CI before merging main again. since you're a first time contributor, we have to manually approve the CI runs. |
|
@dyc3 fixed the failing ci issues 👍 |
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.
Actionable comments posted: 0
♻️ Duplicate comments (1)
crates/biome_js_analyze/src/lint/performance/no_namespace_import.rs (1)
33-76: Verify documentation format matches contribution guide.The documentation nicely covers both external dependencies and local modules (addressing the earlier concern). However, a previous review noted that the options format may not match the analyzer contribution guide. Please double-check the guide to ensure the format is correct.
🧹 Nitpick comments (1)
crates/biome_js_analyze/src/lint/performance/no_namespace_import.rs (1)
99-114: Consider documenting exact string matching behaviour.The allowlist uses exact string comparison, so
"./utils"won't match"./utils/"(trailing slash) and path normalisation isn't performed. This is likely fine, but users might find it helpful if the documentation explicitly mentions that module specifiers must match exactly as they appear in the import statement.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
packages/@biomejs/backend-jsonrpc/src/workspace.tsis excluded by!**/backend-jsonrpc/src/workspace.tsand included by**packages/@biomejs/biome/configuration_schema.jsonis excluded by!**/configuration_schema.jsonand included by**
📒 Files selected for processing (2)
.changeset/thirty-goats-rescue.md(1 hunks)crates/biome_js_analyze/src/lint/performance/no_namespace_import.rs(3 hunks)
✅ Files skipped from review due to trivial changes (1)
- .changeset/thirty-goats-rescue.md
🧰 Additional context used
🧠 Learnings (12)
📚 Learning: 2025-10-15T09:23:33.055Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:23:33.055Z
Learning: Applies to crates/biome_js_type_info/biome_module_graph/src/js_module_info/scoped_resolver.rs : Full inference must resolve TypeReference::Import across modules to TypeReference::Resolved when the target is available in the module graph.
Applied to files:
crates/biome_js_analyze/src/lint/performance/no_namespace_import.rs
📚 Learning: 2025-10-15T09:23:33.055Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:23:33.055Z
Learning: Applies to crates/biome_js_type_info/biome_module_graph/src/**/*.rs : Do not copy or clone data between module graph entries (including behind Arc). Each module must avoid holding duplicated data from another module to enable simple invalidation.
Applied to files:
crates/biome_js_analyze/src/lint/performance/no_namespace_import.rs
📚 Learning: 2025-10-15T09:23:33.055Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:23:33.055Z
Learning: Applies to crates/biome_js_type_info/src/{type_info,local_inference,resolver,flattening}.rs : Avoid recursive type structures and cross-module Arcs; represent links between types using TypeReference and TypeData::Reference.
Applied to files:
crates/biome_js_analyze/src/lint/performance/no_namespace_import.rs
📚 Learning: 2025-10-15T09:23:33.055Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:23:33.055Z
Learning: Applies to crates/biome_js_type_info/biome_module_graph/src/js_module_info/collector.rs : Thin (module-level) inference should resolve local and global bindings to TypeReference::Resolved, mark imported bindings as TypeReference::Import, and fall back to TypeReference::Unknown if unresolved.
Applied to files:
crates/biome_js_analyze/src/lint/performance/no_namespace_import.rs
📚 Learning: 2025-10-15T09:22:46.002Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:46.002Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : Import and use the `FormatNode` trait for AST nodes
Applied to files:
crates/biome_js_analyze/src/lint/performance/no_namespace_import.rs
📚 Learning: 2025-10-15T09:23:33.055Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:23:33.055Z
Learning: Applies to crates/biome_js_type_info/biome_module_graph/src/js_module_info/scoped_resolver.rs : Do not cache results of full inference; module replacements would stale such caches.
Applied to files:
crates/biome_js_analyze/src/lint/performance/no_namespace_import.rs
📚 Learning: 2025-10-15T09:22:46.002Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:46.002Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : Do not attempt to fix code; if a mandatory token/node is missing, return `None` instead
Applied to files:
crates/biome_js_analyze/src/lint/performance/no_namespace_import.rs
📚 Learning: 2025-10-15T09:22:46.002Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:46.002Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : Implement the `Format` trait for your node type and use `JsFormatter` with `write!`/`format_args!` to define formatting
Applied to files:
crates/biome_js_analyze/src/lint/performance/no_namespace_import.rs
📚 Learning: 2025-10-15T09:22:46.002Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:46.002Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : Use `dbg_write!` to debug and inspect the emitted IR during formatting
Applied to files:
crates/biome_js_analyze/src/lint/performance/no_namespace_import.rs
📚 Learning: 2025-10-15T09:22:46.002Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:46.002Z
Learning: Applies to crates/biome_js_formatter/**/Cargo.toml : Declare the dependency `biome_js_formatter = { version = "0.0.1", path = "../biome_js_formatter" }` for internal installation
Applied to files:
crates/biome_js_analyze/src/lint/performance/no_namespace_import.rs
📚 Learning: 2025-10-15T09:22:46.002Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:46.002Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : When a token is mandatory and present in the AST, use the AST-provided token (e.g., `node.l_paren_token().format()`) instead of emitting a static token
Applied to files:
crates/biome_js_analyze/src/lint/performance/no_namespace_import.rs
📚 Learning: 2025-10-15T09:22:15.851Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:22:15.851Z
Learning: Applies to crates/biome_formatter/src/**/*.rs : After generation, remove usages of `format_verbatim_node` and implement real formatting with biome_formatter utilities
Applied to files:
crates/biome_js_analyze/src/lint/performance/no_namespace_import.rs
🧬 Code graph analysis (1)
crates/biome_js_analyze/src/lint/performance/no_namespace_import.rs (1)
crates/biome_js_factory/src/generated/node_factory.rs (1)
js_module_source(2553-2558)
🔇 Additional comments (2)
crates/biome_js_analyze/src/lint/performance/no_namespace_import.rs (2)
6-6: Import looks good.The addition of
AnyJsModuleSourceis necessary for extracting the module specifier in the new allowlist logic.
99-114: Logic looks solid.The chained
if letguards are idiomatic and handle extraction failures gracefully. The exact string matching approach is simple and predictable—"zod"matches"zod","./utils"matches"./utils".
|
I would pay for this feature 👀 I was just slapping |
|
@haydenbleasel you probably missed this from the contribution guide, but this PR must be sent to |
|
@haydenbleasel It looks like the diff of this PR went crazy when you changed it to You can fix this like so:
|
|
@haydenbleasel are you still interested in this PR? |
|
@ematipico I am, I just don't have the time to re-branch it at the moment. Will get to it as soon as I can. |
Introduces an 'allowlist' option to the noNamespaceImport lint rule, allowing specific modules to use namespace imports without triggering diagnostics. Updates rule logic, options struct, and adds tests for valid and invalid cases with allowlist configuration.
I am not a Rust developer so this is purely Claude. Reviewed it, hope it's okay.
Summary
As requested by some Ultracite users (example), some libraries heavily encourage the use of the namespace import.
Zod for example is 73% smaller when imported this way.
I'd like to enforce this rule but for a small selection, hence the allowlist.
Test Plan
Claude created test files to verify the new functionality:
diagnostics
diagnostics
Docs
N/A