Skip to content

Commit

Permalink
refactor: add modern/legacy variants
Browse files Browse the repository at this point in the history
  • Loading branch information
Conaclos committed Oct 21, 2024
1 parent a64cfc9 commit f8946c0
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions crates/biome_js_analyze/src/assists/source/organize_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,23 @@ declare_source_rule! {

impl Rule for OrganizeImports {
type Query = Ast<JsModule>;
type State = legacy::ImportGroups;
type State = State;
type Signals = Option<Self::State>;
type Options = ();

fn run(ctx: &RuleContext<Self>) -> Option<Self::State> {
let root = ctx.query();
legacy::run(root)
legacy::run(root).map(State::Legacy)
}

fn action(ctx: &RuleContext<Self>, groups: &Self::State) -> Option<JsRuleAction> {
fn action(ctx: &RuleContext<Self>, state: &Self::State) -> Option<JsRuleAction> {
let mut mutation = ctx.root().begin();
legacy::action(ctx.query(), groups, &mut mutation)?;
match state {
State::Legacy(groups) => {
legacy::action(ctx.query(), groups, &mut mutation)?;
}
State::Modern => {}
}
Some(JsRuleAction::new(
ActionCategory::Source(SourceActionKind::OrganizeImports),
ctx.metadata().applicability(),
Expand All @@ -65,3 +70,9 @@ impl Rule for OrganizeImports {
))
}
}

#[derive(Debug)]
pub enum State {
Legacy(legacy::ImportGroups),
Modern,
}

0 comments on commit f8946c0

Please sign in to comment.