Skip to content

Commit

Permalink
feat: enable linting for graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Jun 26, 2024
1 parent 91522a5 commit 50be4e2
Show file tree
Hide file tree
Showing 9 changed files with 392 additions and 84 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions crates/biome_analyze/src/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::borrow::Cow;
use biome_console::MarkupBuf;
use biome_diagnostics::{
advice::CodeSuggestionAdvice, category, Advices, Category, Diagnostic, DiagnosticExt,
DiagnosticTags, Error, Location, Severity, Visit,
};
use biome_rowan::TextRange;
use std::fmt::{Debug, Display, Formatter};
use serde::{Deserialize, Serialize};

use crate::rule::RuleDiagnostic;

Expand Down Expand Up @@ -171,3 +173,60 @@ impl SuppressionDiagnostic {
self
}
}



/// Series of errors encountered when running rules on a file
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
pub enum RuleError {
/// The rule with the specified name replaced the root of the file with a node that is not a valid root for that language.
ReplacedRootWithNonRootError {
rule_name: Option<(Cow<'static, str>, Cow<'static, str>)>,
},
}

impl Diagnostic for RuleError {}

impl std::fmt::Display for RuleError {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
RuleError::ReplacedRootWithNonRootError {
rule_name: Some((group, rule)),
} => {
std::write!(
fmt,
"the rule '{group}/{rule}' replaced the root of the file with a non-root node."
)
}
RuleError::ReplacedRootWithNonRootError { rule_name: None } => {
std::write!(
fmt,
"a code action replaced the root of the file with a non-root node."
)
}
}
}
}

impl biome_console::fmt::Display for RuleError {
fn fmt(&self, fmt: &mut biome_console::fmt::Formatter) -> std::io::Result<()> {
match self {
RuleError::ReplacedRootWithNonRootError {
rule_name: Some((group, rule)),
} => {
std::write!(
fmt,
"the rule '{group}/{rule}' replaced the root of the file with a non-root node."
)
}
RuleError::ReplacedRootWithNonRootError { rule_name: None } => {
std::write!(
fmt,
"a code action replaced the root of the file with a non-root node."
)
}
}
}
}

impl std::error::Error for RuleError {}
5 changes: 2 additions & 3 deletions crates/biome_analyze/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ pub use crate::categories::{
ActionCategory, RefactorKind, RuleCategories, RuleCategoriesBuilder, RuleCategory,
SourceActionKind,
};
pub use crate::diagnostics::AnalyzerDiagnostic;
pub use crate::diagnostics::SuppressionDiagnostic;
pub use crate::diagnostics::{AnalyzerDiagnostic, RuleError, SuppressionDiagnostic};
pub use crate::matcher::{InspectMatcher, MatchQueryParams, QueryMatcher, RuleKey, SignalEntry};
pub use crate::options::{AnalyzerConfiguration, AnalyzerOptions, AnalyzerRules};
pub use crate::query::{AddVisitor, QueryKey, QueryMatch, Queryable};
Expand All @@ -38,7 +37,7 @@ pub use crate::registry::{
};
pub use crate::rule::{
CategoryLanguage, FixKind, GroupCategory, GroupLanguage, Rule, RuleAction, RuleDiagnostic,
RuleGroup, RuleMeta, RuleMetadata, RuleSource, RuleSourceKind, SuppressAction,
RuleGroup, RuleMeta, RuleMetadata, RuleSource, RuleSourceKind, SuppressAction
};
pub use crate::services::{FromServices, MissingServicesDiagnostic, ServiceBag};
pub use crate::signals::{
Expand Down
56 changes: 1 addition & 55 deletions crates/biome_js_analyze/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use biome_project::PackageJson;
use biome_suppression::{parse_suppression_comment, SuppressionDiagnostic};
use serde::{Deserialize, Serialize};
use std::sync::Arc;
use std::{borrow::Cow, error::Error};
use std::{error::Error};

mod assists;
mod ast_utils;
Expand Down Expand Up @@ -172,60 +172,6 @@ where
)
}

/// Series of errors encountered when running rules on a file
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
pub enum RuleError {
/// The rule with the specified name replaced the root of the file with a node that is not a valid root for that language.
ReplacedRootWithNonRootError {
rule_name: Option<(Cow<'static, str>, Cow<'static, str>)>,
},
}

impl Diagnostic for RuleError {}

impl std::fmt::Display for RuleError {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
RuleError::ReplacedRootWithNonRootError {
rule_name: Some((group, rule)),
} => {
std::write!(
fmt,
"the rule '{group}/{rule}' replaced the root of the file with a non-root node."
)
}
RuleError::ReplacedRootWithNonRootError { rule_name: None } => {
std::write!(
fmt,
"a code action replaced the root of the file with a non-root node."
)
}
}
}
}

impl biome_console::fmt::Display for RuleError {
fn fmt(&self, fmt: &mut biome_console::fmt::Formatter) -> std::io::Result<()> {
match self {
RuleError::ReplacedRootWithNonRootError {
rule_name: Some((group, rule)),
} => {
std::write!(
fmt,
"the rule '{group}/{rule}' replaced the root of the file with a non-root node."
)
}
RuleError::ReplacedRootWithNonRootError { rule_name: None } => {
std::write!(
fmt,
"a code action replaced the root of the file with a non-root node."
)
}
}
}
}

impl Error for RuleError {}

#[cfg(test)]
mod tests {
Expand Down
1 change: 1 addition & 0 deletions crates/biome_service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ biome_formatter = { workspace = true, features = ["serde"] }
biome_fs = { workspace = true, features = ["serde"] }
biome_graphql_parser = { workspace = true }
biome_graphql_syntax = { workspace = true }
biome_graphql_analyze = { workspace = true }
biome_grit_patterns = { workspace = true }
biome_js_analyze = { workspace = true }
biome_js_factory = { workspace = true, optional = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_service/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ use biome_formatter::{FormatError, PrintError};
use biome_fs::{BiomePath, FileSystemDiagnostic};
use biome_grit_patterns::CompileError;
use biome_js_analyze::utils::rename::RenameError;
use biome_js_analyze::RuleError;
use serde::{Deserialize, Serialize};
use std::error::Error;
use std::ffi::OsStr;
use std::fmt;
use std::fmt::{Debug, Display, Formatter};
use std::process::{ExitCode, Termination};
use biome_analyze::RuleError;

/// Generic errors thrown during biome operations
#[derive(Deserialize, Diagnostic, Serialize)]
Expand Down
11 changes: 3 additions & 8 deletions crates/biome_service/src/file_handlers/css.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ use crate::workspace::{
};
use crate::WorkspaceError;
use biome_analyze::options::PreferredQuote;
use biome_analyze::{
AnalysisFilter, AnalyzerConfiguration, AnalyzerOptions, ControlFlow, Never,
RuleCategoriesBuilder, RuleCategory,
};
use biome_analyze::{AnalysisFilter, AnalyzerConfiguration, AnalyzerOptions, ControlFlow, Never, RuleCategoriesBuilder, RuleCategory, RuleError};
use biome_css_analyze::analyze;
use biome_css_formatter::context::CssFormatOptions;
use biome_css_formatter::format_node;
Expand All @@ -31,8 +28,6 @@ use biome_formatter::{
FormatError, IndentStyle, IndentWidth, LineEnding, LineWidth, Printed, QuoteStyle,
};
use biome_fs::BiomePath;
use biome_js_analyze::RuleError;
use biome_js_syntax::AnyJsRoot;
use biome_parser::AnyParse;
use biome_rowan::{AstNode, NodeCache};
use biome_rowan::{TextRange, TextSize, TokenAtOffset};
Expand Down Expand Up @@ -476,7 +471,7 @@ pub(crate) fn code_actions(params: CodeActionsParams) -> PullActionsResult {
language,
settings,
} = params;
debug_span!("Code actions JavaScript", range =? range, path =? path).in_scope(move || {
debug_span!("Code actions CSS", range =? range, path =? path).in_scope(move || {
let tree = parse.tree();
trace_span!("Parsed file", tree =? tree).in_scope(move || {
let rules = settings.as_rules(params.path.as_path());
Expand Down Expand Up @@ -539,7 +534,7 @@ pub(crate) fn fix_all(params: FixAllParams) -> Result<FixFileResult, WorkspaceEr

let settings = workspace.settings();
let Some(settings) = settings else {
let tree: AnyJsRoot = parse.tree();
let tree: CssRoot = parse.tree();

return Ok(FixFileResult {
actions: vec![],
Expand Down
Loading

0 comments on commit 50be4e2

Please sign in to comment.