Skip to content

Commit

Permalink
refactor(biome_analyze): add RuleAction::new
Browse files Browse the repository at this point in the history
  • Loading branch information
dyc3 committed May 13, 2024
1 parent 7095ed0 commit 679fea3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
16 changes: 16 additions & 0 deletions crates/biome_analyze/src/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,22 @@ pub struct RuleAction<L: Language> {
pub mutation: BatchMutation<L>,
}

impl<L: Language> RuleAction<L> {
pub fn new(
category: ActionCategory,
applicability: impl Into<Applicability>,
message: impl ToOwned<Owned = MarkupBuf>,
mutation: BatchMutation<L>,
) -> Self {
Self {
category,
applicability: applicability.into(),
message: message.to_owned(),
mutation,
}
}
}

/// An action meant to suppress a lint rule
#[derive(Clone)]
pub struct SuppressAction<L: Language> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,12 @@ impl Rule for OrganizeImports {
let mut mutation = ctx.root().begin();
mutation.replace_node_discard_trivia(old_list, new_list);

Some(JsRuleAction {
category: ActionCategory::Source(SourceActionKind::OrganizeImports),
applicability: Applicability::MaybeIncorrect,
message: markup! { "Organize Imports (Biome)" }.to_owned(),
Some(JsRuleAction::new(
ActionCategory::Source(SourceActionKind::OrganizeImports),
Applicability::MaybeIncorrect,
markup! { "Organize Imports (Biome)" }.to_owned(),
mutation,
})
))
}
}

Expand Down

0 comments on commit 679fea3

Please sign in to comment.