Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaRHristov committed Dec 18, 2024
1 parent d053b79 commit baf8249
Show file tree
Hide file tree
Showing 1,935 changed files with 298,798 additions and 333,564 deletions.
40 changes: 10 additions & 30 deletions crates/biome_analyze/Source/categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,34 +85,20 @@ impl ActionCategory {
},

ActionCategory::Refactor(RefactorKind::None) => Cow::Borrowed("refactor.biome"),
ActionCategory::Refactor(RefactorKind::Extract) => {
Cow::Borrowed("refactor.extract.biome")
},
ActionCategory::Refactor(RefactorKind::Extract) => Cow::Borrowed("refactor.extract.biome"),

ActionCategory::Refactor(RefactorKind::Inline) => {
Cow::Borrowed("refactor.inline.biome")
},
ActionCategory::Refactor(RefactorKind::Inline) => Cow::Borrowed("refactor.inline.biome"),

ActionCategory::Refactor(RefactorKind::Rewrite) => {
Cow::Borrowed("refactor.rewrite.biome")
},
ActionCategory::Refactor(RefactorKind::Rewrite) => Cow::Borrowed("refactor.rewrite.biome"),

ActionCategory::Refactor(RefactorKind::Other(tag)) => {
Cow::Owned(format!("refactor.{tag}.biome"))
},
ActionCategory::Refactor(RefactorKind::Other(tag)) => Cow::Owned(format!("refactor.{tag}.biome")),

ActionCategory::Source(SourceActionKind::None) => Cow::Borrowed("source.biome"),
ActionCategory::Source(SourceActionKind::FixAll) => {
Cow::Borrowed("source.fixAll.biome")
},
ActionCategory::Source(SourceActionKind::FixAll) => Cow::Borrowed("source.fixAll.biome"),

ActionCategory::Source(SourceActionKind::OrganizeImports) => {
Cow::Borrowed("source.organizeImports.biome")
},
ActionCategory::Source(SourceActionKind::OrganizeImports) => Cow::Borrowed("source.organizeImports.biome"),

ActionCategory::Source(SourceActionKind::Other(tag)) => {
Cow::Owned(format!("source.{tag}.biome"))
},
ActionCategory::Source(SourceActionKind::Other(tag)) => Cow::Owned(format!("source.{tag}.biome")),

ActionCategory::Other(tag) => Cow::Owned(format!("{tag}.biome")),
}
Expand Down Expand Up @@ -218,9 +204,7 @@ impl RuleCategories {

/// Checks whether the current categories contain a specific
/// [RuleCategories]
pub fn contains(&self, other:impl Into<RuleCategories>) -> bool {
self.0.contains(other.into().0)
}
pub fn contains(&self, other:impl Into<RuleCategories>) -> bool { self.0.contains(other.into().0) }
}

impl Default for RuleCategories {
Expand All @@ -237,9 +221,7 @@ impl From<RuleCategory> for RuleCategories {
RuleCategory::Syntax => RuleCategories(BitFlags::from_flag(Categories::Syntax)),
RuleCategory::Lint => RuleCategories(BitFlags::from_flag(Categories::Lint)),
RuleCategory::Action => RuleCategories(BitFlags::from_flag(Categories::Action)),
RuleCategory::Transformation => {
RuleCategories(BitFlags::from_flag(Categories::Transformation))
},
RuleCategory::Transformation => RuleCategories(BitFlags::from_flag(Categories::Transformation)),
}
}
}
Expand Down Expand Up @@ -285,9 +267,7 @@ impl<'de> serde::Deserialize<'de> for RuleCategories {
impl<'de> de::Visitor<'de> for Visitor {
type Value = RuleCategories;

fn expecting(&self, formatter:&mut Formatter) -> fmt::Result {
write!(formatter, "RuleCategories")
}
fn expecting(&self, formatter:&mut Formatter) -> fmt::Result { write!(formatter, "RuleCategories") }

fn visit_seq<A>(self, mut seq:A) -> Result<Self::Value, A::Error>
where
Expand Down
12 changes: 3 additions & 9 deletions crates/biome_analyze/Source/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ where
pub fn group(&self) -> &'static str { <R::Group as RuleGroup>::NAME }

/// Returns the category that belongs to the current rule
pub fn category(&self) -> RuleCategory {
<<R::Group as RuleGroup>::Category as GroupCategory>::CATEGORY
}
pub fn category(&self) -> RuleCategory { <<R::Group as RuleGroup>::Category as GroupCategory>::CATEGORY }

/// Returns a clone of the AST root
pub fn root(&self) -> RuleRoot<R> { self.root.clone() }
Expand Down Expand Up @@ -146,17 +144,13 @@ where
pub fn options(&self) -> &R::Options { self.options }

/// Returns the JSX runtime in use.
pub fn jsx_runtime(&self) -> JsxRuntime {
self.jsx_runtime.expect("jsx_runtime should be provided")
}
pub fn jsx_runtime(&self) -> JsxRuntime { self.jsx_runtime.expect("jsx_runtime should be provided") }

/// Checks whether the provided text belongs to globals
pub fn is_global(&self, text:&str) -> bool { self.globals.contains(&text) }

/// Returns the source type of the current file
pub fn source_type<T:'static>(&self) -> &T {
self.bag.get_service::<T>().expect("Source type is not registered")
}
pub fn source_type<T:'static>(&self) -> &T { self.bag.get_service::<T>().expect("Source type is not registered") }

/// The file path of the current file
pub fn file_path(&self) -> &Path { self.file_path }
Expand Down
26 changes: 6 additions & 20 deletions crates/biome_analyze/Source/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ impl Diagnostic for AnalyzerDiagnostic {

fn message(&self, fmt:&mut biome_console::fmt::Formatter<'_>) -> std::io::Result<()> {
match &self.kind {
DiagnosticKind::Rule(rule_diagnostic) => {
biome_console::fmt::Display::fmt(&rule_diagnostic.message, fmt)
},
DiagnosticKind::Rule(rule_diagnostic) => biome_console::fmt::Display::fmt(&rule_diagnostic.message, fmt),

DiagnosticKind::Raw(error) => error.message(fmt),
}
Expand All @@ -90,9 +88,7 @@ impl Diagnostic for AnalyzerDiagnostic {

fn location(&self) -> Location<'_> {
match &self.kind {
DiagnosticKind::Rule(rule_diagnostic) => {
Location::builder().span(&rule_diagnostic.span).build()
},
DiagnosticKind::Rule(rule_diagnostic) => Location::builder().span(&rule_diagnostic.span).build(),

DiagnosticKind::Raw(error) => error.location(),
}
Expand All @@ -115,9 +111,7 @@ impl Diagnostic for AnalyzerDiagnostic {

impl AnalyzerDiagnostic {
/// Creates a diagnostic from a generic [Error]
pub fn from_error(error:Error) -> Self {
Self { kind:DiagnosticKind::Raw(error), code_suggestion_list:vec![] }
}
pub fn from_error(error:Error) -> Self { Self { kind:DiagnosticKind::Raw(error), code_suggestion_list:vec![] } }

pub fn get_span(&self) -> Option<TextRange> {
match &self.kind {
Expand All @@ -136,9 +130,7 @@ impl AnalyzerDiagnostic {
DiagnosticKind::Rule(rule_diagnostic)
},

DiagnosticKind::Raw(error) => {
DiagnosticKind::Raw(error.with_tags(DiagnosticTags::FIXABLE))
},
DiagnosticKind::Raw(error) => DiagnosticKind::Raw(error.with_tags(DiagnosticTags::FIXABLE)),
};

self.code_suggestion_list.push(suggestion);
Expand Down Expand Up @@ -198,10 +190,7 @@ impl std::fmt::Display for RuleError {
},

RuleError::ReplacedRootWithNonRootError { rule_name: None } => {
std::write!(
fmt,
"a code action replaced the root of the file with a non-root node."
)
std::write!(fmt, "a code action replaced the root of the file with a non-root node.")
},
}
}
Expand All @@ -218,10 +207,7 @@ impl biome_console::fmt::Display for RuleError {
},

RuleError::ReplacedRootWithNonRootError { rule_name: None } => {
std::write!(
fmt,
"a code action replaced the root of the file with a non-root node."
)
std::write!(fmt, "a code action replaced the root of the file with a non-root node.")
},
}
}
Expand Down
70 changes: 17 additions & 53 deletions crates/biome_analyze/Source/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,7 @@ mod visitor;
// Re-exported for use in the `declare_group` macro
use biome_console::markup;
pub use biome_diagnostics::category_concat;
use biome_diagnostics::{
Applicability,
Diagnostic,
DiagnosticExt,
DiagnosticTags,
Severity,
category,
};
use biome_diagnostics::{Applicability, Diagnostic, DiagnosticExt, DiagnosticTags, Severity, category};
use biome_rowan::{
AstNode,
BatchMutation,
Expand Down Expand Up @@ -154,11 +147,7 @@ where

/// Registers a [Visitor] to be executed as part of a given `phase` of the
/// analyzer run
pub fn add_visitor(
&mut self,
phase:Phases,
visitor:Box<dyn Visitor<Language = L> + 'analyzer>,
) {
pub fn add_visitor(&mut self, phase:Phases, visitor:Box<dyn Visitor<Language = L> + 'analyzer>) {
self.phases.entry(phase).or_default().push(visitor);
}

Expand Down Expand Up @@ -224,8 +213,8 @@ where
SuppressionDiagnostic::new(
category!("suppressions/unused"),
suppression.comment_span,
"Suppression comment has no effect. Remove the suppression or make sure you \
are suppressing the correct rule.",
"Suppression comment has no effect. Remove the suppression or make sure you are suppressing the \
correct rule.",
)
});

Expand Down Expand Up @@ -378,9 +367,7 @@ where
for (index, piece) in token.leading_trivia().pieces().enumerate() {
if matches!(
piece.kind(),
TriviaPieceKind::Newline
| TriviaPieceKind::MultiLineComment
| TriviaPieceKind::Skipped
TriviaPieceKind::Newline | TriviaPieceKind::MultiLineComment | TriviaPieceKind::Skipped
) {
self.bump_line_index(piece.text(), piece.text_range());
}
Expand All @@ -395,9 +382,7 @@ where
for (index, piece) in token.trailing_trivia().pieces().enumerate() {
if matches!(
piece.kind(),
TriviaPieceKind::Newline
| TriviaPieceKind::MultiLineComment
| TriviaPieceKind::Skipped
TriviaPieceKind::Newline | TriviaPieceKind::MultiLineComment | TriviaPieceKind::Skipped
) {
self.bump_line_index(piece.text(), piece.text_range());
}
Expand Down Expand Up @@ -431,8 +416,7 @@ where
// search over all the previously seen suppressions to find one
// with a matching range
let suppression = self.line_suppressions.last_mut().filter(|suppression| {
suppression.line_index == *self.line_index
&& suppression.text_range.start() <= start
suppression.line_index == *self.line_index && suppression.text_range.start() <= start
});

let suppression = match suppression {
Expand Down Expand Up @@ -553,9 +537,7 @@ where

let key = match group_rule {
None => self.metadata.find_group(rule).map(RuleFilter::from),
Some((group, rule)) => {
self.metadata.find_rule(group, rule).map(RuleFilter::from)
},
Some((group, rule)) => self.metadata.find_rule(group, rule).map(RuleFilter::from),
};

match (key, instance) {
Expand All @@ -574,20 +556,15 @@ where
SuppressionDiagnostic::new(
category!("suppressions/unknownRule"),
range,
format_args!(
"Unknown lint rule {group}/{rule} in suppression \
comment"
),
format_args!("Unknown lint rule {group}/{rule} in suppression comment"),
)
},

None => {
SuppressionDiagnostic::new(
category!("suppressions/unknownGroup"),
range,
format_args!(
"Unknown lint rule group {rule} in suppression comment"
),
format_args!("Unknown lint rule group {rule} in suppression comment"),
)
},
}
Expand Down Expand Up @@ -619,8 +596,7 @@ where
.with_tags(DiagnosticTags::DEPRECATED_CODE)
});

let signal = signal
.with_action(|| update_suppression(self.root, token, is_leading, index, text));
let signal = signal.with_action(|| update_suppression(self.root, token, is_leading, index, text));

(self.emit_signal)(&signal)?;
}
Expand All @@ -635,9 +611,7 @@ where
// If the last suppression was on the same or previous line, extend its
// range and set of suppressed rules with the content for the new suppression
if let Some(last_suppression) = self.line_suppressions.last_mut() {
if last_suppression.line_index == line_index
|| last_suppression.line_index + 1 == line_index
{
if last_suppression.line_index == line_index || last_suppression.line_index + 1 == line_index {
last_suppression.line_index = line_index;

last_suppression.text_range = last_suppression.text_range.cover(range);
Expand Down Expand Up @@ -682,9 +656,8 @@ where
for (index, _) in text.match_indices('\n') {
if let Some(last_suppression) = self.line_suppressions.last_mut() {
if last_suppression.line_index == *self.line_index {
let index = TextSize::try_from(index).expect(
"integer overflow while converting a suppression line to `TextSize`",
);
let index = TextSize::try_from(index)
.expect("integer overflow while converting a suppression line to `TextSize`");

let range = TextRange::at(range.start(), index);

Expand All @@ -707,9 +680,7 @@ where
}
}

fn create_suppression_comment_action<L:Language>(
token:&SyntaxToken<L>,
) -> Option<AnalyzerAction<L>> {
fn create_suppression_comment_action<L:Language>(token:&SyntaxToken<L>) -> Option<AnalyzerAction<L>> {
let first_node = token.parent()?;

let mut new_leading_trivia = vec![];
Expand Down Expand Up @@ -744,12 +715,7 @@ fn create_suppression_comment_action<L:Language>(
token_text.push_str(piece.text());
}

let new_token = SyntaxToken::new_detached(
token.kind(),
&token_text,
new_leading_trivia,
new_trailing_trivia,
);
let new_token = SyntaxToken::new_detached(token.kind(), &token_text, new_leading_trivia, new_trailing_trivia);

mutation.replace_token_discard_trivia(token.clone(), new_token);

Expand Down Expand Up @@ -915,9 +881,7 @@ impl<'a> RuleFilter<'a> {
R: Rule, {
match self {
RuleFilter::Group(group) => group == <R::Group as RuleGroup>::NAME,
RuleFilter::Rule(group, rule) => {
group == <R::Group as RuleGroup>::NAME && rule == R::METADATA.name
},
RuleFilter::Rule(group, rule) => group == <R::Group as RuleGroup>::NAME && rule == R::METADATA.name,
}
}
}
Expand Down
Loading

0 comments on commit baf8249

Please sign in to comment.