refactor(organizeImports): require sortBareImports for bare matchers#10517
Conversation
|
✅ Organic activityNo automation signals detected in the analyzed events. This is an automated analysis by AgentScan |
sortBareImports when using bare ki…sortBareImports for bare matchers
b0744a3 to
f5788a3
Compare
WalkthroughAdds detection for bare import matchers (value-based ImportKindMatcher and NegatableImportKindMatcher, and has_bare_matchers on GroupMatcher/ImportGroup/ImportGroups) and a DeserializableValidator on OrganizeImportsOptions that errors if bare matchers appear while sort_bare_imports is not explicitly true. Includes a test options JSON exercising a bare-kind group. Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
ematipico
left a comment
There was a problem hiding this comment.
The intention of the PR is good, but the new functions take self which is not necessarary
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/biome_rule_options/src/organize_imports/import_groups.rs (1)
31-33: ⚡ Quick winTighten these helper visibilities.
These look like internal plumbing for the validator/matcher path, so
pubfeels a bit generous. Exposing them widens the public API for free, which is rarely a bargain.pub(crate)forImportGroups::has_bare_matchersand private methods for the other two should be enough here.♻️ Proposed tweak
impl ImportGroups { @@ - pub fn has_bare_matchers(&self) -> bool { + pub(crate) fn has_bare_matchers(&self) -> bool { self.0.iter().any(|group| group.has_bare_matchers()) } @@ impl GroupMatcher { @@ - pub fn has_bare_matchers(&self) -> bool { + fn has_bare_matchers(&self) -> bool { match self { Self::Import(import_matcher) => import_matcher .kind .is_some_and(|kind_matcher| kind_matcher.kind.is_bare()), Self::Source(_source_matcher) => false, } } @@ impl ImportKindMatcher { @@ - pub const fn is_bare(&self) -> bool { + const fn is_bare(&self) -> bool { matches!(self, Self::Bare) } }Also applies to: 149-156, 328-329
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/biome_rule_options/src/organize_imports/import_groups.rs` around lines 31 - 33, The helper visibility is too broad: change the public signature of ImportGroups::has_bare_matchers from pub fn to pub(crate) fn and make the other two helper methods mentioned in the review (the internal matcher/validator helpers referenced at lines 149-156 and 328-329) private (remove pub) so they are not exposed in the public API; update their declarations (method names matching those ranges) accordingly and run tests to ensure no external call sites rely on them.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@crates/biome_rule_options/src/organize_imports/import_groups.rs`:
- Around line 31-33: The helper visibility is too broad: change the public
signature of ImportGroups::has_bare_matchers from pub fn to pub(crate) fn and
make the other two helper methods mentioned in the review (the internal
matcher/validator helpers referenced at lines 149-156 and 328-329) private
(remove pub) so they are not exposed in the public API; update their
declarations (method names matching those ranges) accordingly and run tests to
ensure no external call sites rely on them.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 7b8c7178-7916-4402-9a97-3396a5595356
📒 Files selected for processing (1)
crates/biome_rule_options/src/organize_imports/import_groups.rs
Summary
I think that #10190 is not ready for v2.5
To avoid any blocking, I submitted this PR.
This PR errors on configurations that use bare kind matchers without settings
sortBareImportstotrue.The diagnostic points to #10190.
Test Plan
I added a test.
Docs
No change. The docs and changesets already speak about that.