Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable linting for graphql #3295

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

58 changes: 58 additions & 0 deletions crates/biome_analyze/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use biome_diagnostics::{
DiagnosticTags, Error, Location, Severity, Visit,
};
use biome_rowan::TextRange;
use std::borrow::Cow;
use std::fmt::{Debug, Display, Formatter};

use crate::rule::RuleDiagnostic;
Expand Down Expand Up @@ -171,3 +172,60 @@ impl SuppressionDiagnostic {
self
}
}

/// Series of errors encountered when running rules on a file
#[derive(Debug, PartialEq, Eq, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
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 {}
3 changes: 1 addition & 2 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 Down
59 changes: 1 addition & 58 deletions crates/biome_js_analyze/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ use biome_analyze::{
SuppressionKind,
};
use biome_aria::{AriaProperties, AriaRoles};
use biome_diagnostics::{category, Diagnostic, Error as DiagnosticError};
use biome_diagnostics::{category, Error as DiagnosticError};
use biome_js_syntax::{JsFileSource, JsLanguage};
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};

mod assists;
mod ast_utils;
Expand Down Expand Up @@ -172,61 +170,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 {
use biome_analyze::options::RuleOptions;
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 @@ -27,6 +27,7 @@ biome_diagnostics = { workspace = true }
biome_flags = { workspace = true }
biome_formatter = { workspace = true, features = ["serde"] }
biome_fs = { workspace = true, features = ["serde"] }
biome_graphql_analyze = { workspace = true }
biome_graphql_parser = { workspace = true }
biome_graphql_syntax = { workspace = true }
biome_grit_patterns = { workspace = 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
@@ -1,4 +1,5 @@
use crate::workspace::DocumentFileSource;
use biome_analyze::RuleError;
use biome_configuration::diagnostics::{ConfigurationDiagnostic, EditorConfigDiagnostic};
use biome_configuration::{BiomeDiagnostic, CantLoadExtendFile};
use biome_console::fmt::Bytes;
Expand All @@ -10,7 +11,6 @@ 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;
Expand Down
8 changes: 3 additions & 5 deletions crates/biome_service/src/file_handlers/css.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::WorkspaceError;
use biome_analyze::options::PreferredQuote;
use biome_analyze::{
AnalysisFilter, AnalyzerConfiguration, AnalyzerOptions, ControlFlow, Never,
RuleCategoriesBuilder, RuleCategory,
RuleCategoriesBuilder, RuleCategory, RuleError,
};
use biome_css_analyze::analyze;
use biome_css_formatter::context::CssFormatOptions;
Expand All @@ -31,8 +31,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 +474,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 +537,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