From ffc3361f93121a5c6ba28bbdffa528ba3c1dc187 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Tue, 2 Jul 2024 12:58:00 +0100 Subject: [PATCH 1/5] feat: enable GraphQL linting --- crates/biome_cli/src/commands/format.rs | 9 +++- crates/biome_cli/src/commands/lint.rs | 13 +++++- crates/biome_cli/src/commands/mod.rs | 12 +++++- crates/biome_cli/src/lib.rs | 4 ++ .../main_commands_check/check_help.snap | 1 + .../snapshots/main_commands_ci/ci_help.snap | 1 + crates/biome_configuration/src/graphql.rs | 41 ++++++++++++++++++- crates/biome_configuration/src/lib.rs | 4 +- crates/biome_service/Cargo.toml | 2 - .../src/file_handlers/graphql.rs | 18 +++++++- crates/biome_service/src/file_handlers/mod.rs | 21 ++++------ crates/biome_service/src/settings.rs | 5 +++ crates/biome_wasm/Cargo.toml | 1 - 13 files changed, 107 insertions(+), 25 deletions(-) diff --git a/crates/biome_cli/src/commands/format.rs b/crates/biome_cli/src/commands/format.rs index c90b466f8464..187f7da90049 100644 --- a/crates/biome_cli/src/commands/format.rs +++ b/crates/biome_cli/src/commands/format.rs @@ -10,7 +10,7 @@ use crate::{ use biome_configuration::vcs::PartialVcsConfiguration; use biome_configuration::{ PartialCssFormatter, PartialFilesConfiguration, PartialFormatterConfiguration, - PartialJavascriptFormatter, PartialJsonFormatter, + PartialGraphqlFormatter, PartialJavascriptFormatter, PartialJsonFormatter, }; use biome_console::{markup, ConsoleExt}; use biome_deserialize::Merge; @@ -27,6 +27,7 @@ pub(crate) struct FormatCommandPayload { pub(crate) javascript_formatter: Option, pub(crate) json_formatter: Option, pub(crate) css_formatter: Option, + pub(crate) graphql_formatter: Option, pub(crate) formatter_configuration: Option, pub(crate) vcs_configuration: Option, pub(crate) files_configuration: Option, @@ -57,6 +58,7 @@ pub(crate) fn format( fix, mut json_formatter, css_formatter, + graphql_formatter, since, staged, changed, @@ -196,6 +198,11 @@ pub(crate) fn format( let css = configuration.css.get_or_insert_with(Default::default); css.formatter.merge_with(css_formatter); } + if graphql_formatter.is_some() { + let graphql = configuration.graphql.get_or_insert_with(Default::default); + graphql.formatter.merge_with(graphql_formatter); + } + if javascript_formatter.is_some() { let javascript = configuration .javascript diff --git a/crates/biome_cli/src/commands/lint.rs b/crates/biome_cli/src/commands/lint.rs index e00631f89e1a..b6e08746b03d 100644 --- a/crates/biome_cli/src/commands/lint.rs +++ b/crates/biome_cli/src/commands/lint.rs @@ -12,7 +12,8 @@ use biome_configuration::json::PartialJsonLinter; use biome_configuration::linter::RuleSelector; use biome_configuration::vcs::PartialVcsConfiguration; use biome_configuration::{ - PartialConfiguration, PartialFilesConfiguration, PartialLinterConfiguration, + PartialConfiguration, PartialFilesConfiguration, PartialGraphqlLinter, + PartialLinterConfiguration, }; use biome_deserialize::Merge; use biome_service::configuration::{ @@ -43,6 +44,7 @@ pub(crate) struct LintCommandPayload { pub(crate) javascript_linter: Option, pub(crate) json_linter: Option, pub(crate) css_linter: Option, + pub(crate) graphql_linter: Option, } /// Handler for the "lint" command of the Biome CLI @@ -67,6 +69,7 @@ pub(crate) fn lint(session: CliSession, payload: LintCommandPayload) -> Result<( javascript_linter, css_linter, json_linter, + graphql_linter, } = payload; setup_cli_subscriber(cli_options.log_level, cli_options.log_kind); @@ -118,6 +121,13 @@ pub(crate) fn lint(session: CliSession, payload: LintCommandPayload) -> Result<( let css = fs_configuration.css.get_or_insert_with(Default::default); css.linter.merge_with(css_linter); } + + if graphql_linter.is_some() { + let graphql = fs_configuration + .graphql + .get_or_insert_with(Default::default); + graphql.linter.merge_with(graphql_linter); + } if javascript_linter.is_some() { let javascript = fs_configuration .javascript @@ -139,6 +149,7 @@ pub(crate) fn lint(session: CliSession, payload: LintCommandPayload) -> Result<( let stdin = get_stdin(stdin_file_path, &mut *session.app.console, "lint")?; + dbg!(&fs_configuration); session .app .workspace diff --git a/crates/biome_cli/src/commands/mod.rs b/crates/biome_cli/src/commands/mod.rs index 0b49de90d539..5323782b6bbd 100644 --- a/crates/biome_cli/src/commands/mod.rs +++ b/crates/biome_cli/src/commands/mod.rs @@ -9,12 +9,14 @@ use biome_configuration::javascript::PartialJavascriptLinter; use biome_configuration::json::PartialJsonLinter; use biome_configuration::linter::RuleSelector; use biome_configuration::{ - css::partial_css_formatter, css::partial_css_linter, javascript::partial_javascript_formatter, + css::partial_css_formatter, css::partial_css_linter, graphql::partial_graphql_formatter, + graphql::partial_graphql_linter, javascript::partial_javascript_formatter, javascript::partial_javascript_linter, json::partial_json_formatter, json::partial_json_linter, partial_configuration, partial_files_configuration, partial_formatter_configuration, partial_linter_configuration, vcs::partial_vcs_configuration, vcs::PartialVcsConfiguration, PartialCssFormatter, PartialFilesConfiguration, PartialFormatterConfiguration, - PartialJavascriptFormatter, PartialJsonFormatter, PartialLinterConfiguration, + PartialGraphqlFormatter, PartialGraphqlLinter, PartialJavascriptFormatter, + PartialJsonFormatter, PartialLinterConfiguration, }; use biome_configuration::{BiomeDiagnostic, PartialConfiguration}; use biome_console::{markup, Console, ConsoleExt}; @@ -190,6 +192,9 @@ pub enum BiomeCommand { #[bpaf(external(partial_css_linter), optional, hide_usage, hide)] css_linter: Option, + #[bpaf(external(partial_graphql_linter), optional, hide_usage, hide)] + graphql_linter: Option, + #[bpaf(external, hide_usage)] cli_options: CliOptions, @@ -246,6 +251,9 @@ pub enum BiomeCommand { #[bpaf(external(partial_css_formatter), optional, hide_usage, hide)] css_formatter: Option, + #[bpaf(external(partial_graphql_formatter), optional, hide_usage, hide)] + graphql_formatter: Option, + #[bpaf(external(partial_vcs_configuration), optional, hide_usage)] vcs_configuration: Option, diff --git a/crates/biome_cli/src/lib.rs b/crates/biome_cli/src/lib.rs index 9ab166f67b38..490fd738399b 100644 --- a/crates/biome_cli/src/lib.rs +++ b/crates/biome_cli/src/lib.rs @@ -135,6 +135,7 @@ impl<'app> CliSession<'app> { css_linter, javascript_linter, json_linter, + graphql_linter, } => commands::lint::lint( self, LintCommandPayload { @@ -157,6 +158,7 @@ impl<'app> CliSession<'app> { css_linter, javascript_linter, json_linter, + graphql_linter, }, ), BiomeCommand::Ci { @@ -193,6 +195,7 @@ impl<'app> CliSession<'app> { files_configuration, json_formatter, css_formatter, + graphql_formatter, staged, changed, since, @@ -210,6 +213,7 @@ impl<'app> CliSession<'app> { files_configuration, json_formatter, css_formatter, + graphql_formatter, staged, changed, since, diff --git a/crates/biome_cli/tests/snapshots/main_commands_check/check_help.snap b/crates/biome_cli/tests/snapshots/main_commands_check/check_help.snap index ef4daa6797ff..a2d47a64606f 100644 --- a/crates/biome_cli/tests/snapshots/main_commands_check/check_help.snap +++ b/crates/biome_cli/tests/snapshots/main_commands_check/check_help.snap @@ -102,6 +102,7 @@ The configuration that is contained inside the file `biome.json` Defaults to 80. --graphql-formatter-quote-style= The type of quotes used in GraphQL code. Defaults to double. + --graphql-linter-enabled= Control the formatter for GraphQL files. Global options applied to all commands --colors= Set the formatting mode for markup: "off" prints everything as plain text, diff --git a/crates/biome_cli/tests/snapshots/main_commands_ci/ci_help.snap b/crates/biome_cli/tests/snapshots/main_commands_ci/ci_help.snap index 69177775f6b7..dc56fa601af6 100644 --- a/crates/biome_cli/tests/snapshots/main_commands_ci/ci_help.snap +++ b/crates/biome_cli/tests/snapshots/main_commands_ci/ci_help.snap @@ -104,6 +104,7 @@ The configuration that is contained inside the file `biome.json` Defaults to 80. --graphql-formatter-quote-style= The type of quotes used in GraphQL code. Defaults to double. + --graphql-linter-enabled= Control the formatter for GraphQL files. Global options applied to all commands --colors= Set the formatting mode for markup: "off" prints everything as plain text, diff --git a/crates/biome_configuration/src/graphql.rs b/crates/biome_configuration/src/graphql.rs index 2852fe6449eb..5044dd63469d 100644 --- a/crates/biome_configuration/src/graphql.rs +++ b/crates/biome_configuration/src/graphql.rs @@ -13,6 +13,10 @@ pub struct GraphqlConfiguration { /// GraphQL formatter options #[partial(type, bpaf(external(partial_graphql_formatter), optional))] pub formatter: GraphqlFormatter, + + // GraphQL linter options + #[partial(type, bpaf(external(partial_graphql_linter), optional))] + pub linter: GraphqlLinter, } /// Options that changes how the GraphQL formatter behaves @@ -63,6 +67,15 @@ pub struct GraphqlFormatter { pub bracket_spacing: Option, } +// impl Default for GraphqlFormatter { +// fn default() -> Self { +// Self { +// enabled: Some(false), +// ..Default::default() +// } +// } +// } + impl PartialGraphqlFormatter { pub fn get_formatter_configuration(&self) -> GraphqlFormatter { GraphqlFormatter { @@ -77,8 +90,27 @@ impl PartialGraphqlFormatter { } } +/// Options that changes how the GraphQL linter behaves +#[derive(Clone, Debug, Deserialize, Eq, Partial, PartialEq, Serialize)] +#[partial(derive(Bpaf, Clone, Deserializable, Eq, Merge, PartialEq))] +#[partial(cfg_attr(feature = "schema", derive(schemars::JsonSchema)))] +#[partial(serde(rename_all = "camelCase", default, deny_unknown_fields))] +pub struct GraphqlLinter { + /// Control the formatter for GraphQL files. + #[partial(bpaf(long("graphql-linter-enabled"), argument("true|false"), optional))] + pub enabled: Option, +} + +impl Default for GraphqlLinter { + fn default() -> Self { + Self { + enabled: Some(false), + } + } +} + #[test] -fn default_graphql() { +fn default_graphql_formatter() { let graphql_configuration = GraphqlFormatter::default(); assert!(!graphql_configuration.enabled); @@ -88,3 +120,10 @@ fn default_graphql() { assert_eq!(graphql_configuration.line_width, None); assert_eq!(graphql_configuration.quote_style, None); } + +#[test] +fn default_graphql_linter() { + let graphql_configuration = GraphqlLinter::default(); + + assert_eq!(graphql_configuration.enabled, Some(false)); +} diff --git a/crates/biome_configuration/src/lib.rs b/crates/biome_configuration/src/lib.rs index 3f00684014c1..50da1a79cd57 100644 --- a/crates/biome_configuration/src/lib.rs +++ b/crates/biome_configuration/src/lib.rs @@ -35,8 +35,8 @@ pub use formatter::{ PlainIndentStyle, }; pub use graphql::{ - partial_graphql_configuration, GraphqlConfiguration, GraphqlFormatter, - PartialGraphqlConfiguration, PartialGraphqlFormatter, + partial_graphql_configuration, GraphqlConfiguration, GraphqlFormatter, GraphqlLinter, + PartialGraphqlConfiguration, PartialGraphqlFormatter, PartialGraphqlLinter, }; pub use javascript::{ partial_javascript_configuration, JavascriptConfiguration, JavascriptFormatter, diff --git a/crates/biome_service/Cargo.toml b/crates/biome_service/Cargo.toml index b24016b24ac6..c85552497fe3 100644 --- a/crates/biome_service/Cargo.toml +++ b/crates/biome_service/Cargo.toml @@ -74,8 +74,6 @@ schema = [ "biome_graphql_syntax/schema", ] -graphql = [] - [dev-dependencies] insta = { workspace = true } tests_macros = { workspace = true } diff --git a/crates/biome_service/src/file_handlers/graphql.rs b/crates/biome_service/src/file_handlers/graphql.rs index c9cf262b6680..b770b453c353 100644 --- a/crates/biome_service/src/file_handlers/graphql.rs +++ b/crates/biome_service/src/file_handlers/graphql.rs @@ -60,9 +60,23 @@ impl Default for GraphqlFormatterSettings { } } +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] +pub struct GraphqlLinterSettings { + pub enabled: Option, +} + +impl Default for GraphqlLinterSettings { + fn default() -> Self { + Self { + enabled: Some(false) + } + } +} + impl ServiceLanguage for GraphqlLanguage { type FormatterSettings = GraphqlFormatterSettings; - type LinterSettings = (); + type LinterSettings = GraphqlLinterSettings; type OrganizeImportsSettings = (); type FormatOptions = GraphqlFormatOptions; type ParserSettings = (); @@ -208,7 +222,7 @@ fn debug_formatter_ir( Ok(root_element.to_string()) } -#[tracing::instrument(level = "debug", skip(parse))] +#[tracing::instrument(level = "debug", skip(parse, settings))] fn format( biome_path: &BiomePath, document_file_source: &DocumentFileSource, diff --git a/crates/biome_service/src/file_handlers/mod.rs b/crates/biome_service/src/file_handlers/mod.rs index 6452a7ca2160..96fb667905f4 100644 --- a/crates/biome_service/src/file_handlers/mod.rs +++ b/crates/biome_service/src/file_handlers/mod.rs @@ -96,11 +96,10 @@ impl DocumentFileSource { if let Ok(file_source) = CssFileSource::try_from_well_known(file_name) { return Ok(file_source.into()); } - if cfg!(feature = "graphql") || cfg!(debug_assertions) { - if let Ok(file_source) = GraphqlFileSource::try_from_well_known(file_name) { - return Ok(file_source.into()); - } + if let Ok(file_source) = GraphqlFileSource::try_from_well_known(file_name) { + return Ok(file_source.into()); } + Err(FileSourceError::UnknownFileName(file_name.into())) } @@ -120,10 +119,8 @@ impl DocumentFileSource { if let Ok(file_source) = CssFileSource::try_from_extension(extension) { return Ok(file_source.into()); } - if cfg!(feature = "graphql") || cfg!(debug_assertions) { - if let Ok(file_source) = GraphqlFileSource::try_from_extension(extension) { - return Ok(file_source.into()); - } + if let Ok(file_source) = GraphqlFileSource::try_from_extension(extension) { + return Ok(file_source.into()); } Err(FileSourceError::UnknownExtension( Default::default(), @@ -147,10 +144,8 @@ impl DocumentFileSource { if let Ok(file_source) = CssFileSource::try_from_language_id(language_id) { return Ok(file_source.into()); } - if cfg!(feature = "graphql") || cfg!(debug_assertions) { - if let Ok(file_source) = GraphqlFileSource::try_from_language_id(language_id) { - return Ok(file_source.into()); - } + if let Ok(file_source) = GraphqlFileSource::try_from_language_id(language_id) { + return Ok(file_source.into()); } Err(FileSourceError::UnknownLanguageId(language_id.into())) } @@ -297,7 +292,7 @@ impl DocumentFileSource { EmbeddingKind::None => true, }, DocumentFileSource::Json(_) | DocumentFileSource::Css(_) => true, - DocumentFileSource::Graphql(_) => cfg!(feature = "graphql") || cfg!(debug_assertions), + DocumentFileSource::Graphql(_) => true, DocumentFileSource::Unknown => false, } } diff --git a/crates/biome_service/src/settings.rs b/crates/biome_service/src/settings.rs index a57ca6a40843..28c1e4cd0ce5 100644 --- a/crates/biome_service/src/settings.rs +++ b/crates/biome_service/src/settings.rs @@ -535,6 +535,7 @@ impl From for LanguageSettings { impl From for LanguageSettings { fn from(graphql: PartialGraphqlConfiguration) -> Self { let mut language_setting: LanguageSettings = LanguageSettings::default(); + dbg!(&graphql); if let Some(formatter) = graphql.formatter { // TODO: change RHS to `formatter.enabled` when graphql formatting is enabled by default @@ -547,6 +548,10 @@ impl From for LanguageSettings { language_setting.formatter.bracket_spacing = formatter.bracket_spacing; } + if let Some(linter) = graphql.linter { + language_setting.linter.enabled = linter.enabled; + } + language_setting } } diff --git a/crates/biome_wasm/Cargo.toml b/crates/biome_wasm/Cargo.toml index 7175a576b3ef..4d6b8d30aabe 100644 --- a/crates/biome_wasm/Cargo.toml +++ b/crates/biome_wasm/Cargo.toml @@ -17,7 +17,6 @@ crate-type = ["cdylib", "rlib"] [features] default = ["console_error_panic_hook"] -graphql = ["biome_service/graphql"] [dependencies] biome_console = { workspace = true } From e7e4b3a10ef71ec9f76b7a7ab329fd0bf8cac503 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Tue, 2 Jul 2024 16:22:39 +0100 Subject: [PATCH 2/5] fmt and clippy --- crates/biome_cli/src/commands/format.rs | 2 +- crates/biome_service/src/file_handlers/graphql.rs | 2 +- crates/biome_service/src/settings.rs | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/biome_cli/src/commands/format.rs b/crates/biome_cli/src/commands/format.rs index 187f7da90049..f865f712c378 100644 --- a/crates/biome_cli/src/commands/format.rs +++ b/crates/biome_cli/src/commands/format.rs @@ -202,7 +202,7 @@ pub(crate) fn format( let graphql = configuration.graphql.get_or_insert_with(Default::default); graphql.formatter.merge_with(graphql_formatter); } - + if javascript_formatter.is_some() { let javascript = configuration .javascript diff --git a/crates/biome_service/src/file_handlers/graphql.rs b/crates/biome_service/src/file_handlers/graphql.rs index b770b453c353..fd774df29e86 100644 --- a/crates/biome_service/src/file_handlers/graphql.rs +++ b/crates/biome_service/src/file_handlers/graphql.rs @@ -69,7 +69,7 @@ pub struct GraphqlLinterSettings { impl Default for GraphqlLinterSettings { fn default() -> Self { Self { - enabled: Some(false) + enabled: Some(false), } } } diff --git a/crates/biome_service/src/settings.rs b/crates/biome_service/src/settings.rs index 28c1e4cd0ce5..adb2f93a185b 100644 --- a/crates/biome_service/src/settings.rs +++ b/crates/biome_service/src/settings.rs @@ -535,7 +535,6 @@ impl From for LanguageSettings { impl From for LanguageSettings { fn from(graphql: PartialGraphqlConfiguration) -> Self { let mut language_setting: LanguageSettings = LanguageSettings::default(); - dbg!(&graphql); if let Some(formatter) = graphql.formatter { // TODO: change RHS to `formatter.enabled` when graphql formatting is enabled by default From 6049dd4d8ef1081b99e55ae71f4f88f200415d3a Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Tue, 2 Jul 2024 16:26:39 +0100 Subject: [PATCH 3/5] codegen --- .../@biomejs/backend-jsonrpc/src/workspace.ts | 10 ++++++++++ .../@biomejs/biome/configuration_schema.json | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/packages/@biomejs/backend-jsonrpc/src/workspace.ts b/packages/@biomejs/backend-jsonrpc/src/workspace.ts index 9bcc88f7c8a5..99ddac35e63f 100644 --- a/packages/@biomejs/backend-jsonrpc/src/workspace.ts +++ b/packages/@biomejs/backend-jsonrpc/src/workspace.ts @@ -179,6 +179,7 @@ export interface PartialGraphqlConfiguration { * GraphQL formatter options */ formatter?: PartialGraphqlFormatter; + linter?: PartialGraphqlLinter; } /** * A set of options applied to the JavaScript files @@ -380,6 +381,15 @@ export interface PartialGraphqlFormatter { */ quoteStyle?: QuoteStyle; } +/** + * Options that changes how the GraphQL linter behaves + */ +export interface PartialGraphqlLinter { + /** + * Control the formatter for GraphQL files. + */ + enabled?: boolean; +} /** * Formatting options specific to the JavaScript files */ diff --git a/packages/@biomejs/biome/configuration_schema.json b/packages/@biomejs/biome/configuration_schema.json index 0de5597190bd..75214586604a 100644 --- a/packages/@biomejs/biome/configuration_schema.json +++ b/packages/@biomejs/biome/configuration_schema.json @@ -1168,6 +1168,12 @@ { "$ref": "#/definitions/GraphqlFormatter" }, { "type": "null" } ] + }, + "linter": { + "anyOf": [ + { "$ref": "#/definitions/GraphqlLinter" }, + { "type": "null" } + ] } }, "additionalProperties": false @@ -1213,6 +1219,17 @@ }, "additionalProperties": false }, + "GraphqlLinter": { + "description": "Options that changes how the GraphQL linter behaves", + "type": "object", + "properties": { + "enabled": { + "description": "Control the formatter for GraphQL files.", + "type": ["boolean", "null"] + } + }, + "additionalProperties": false + }, "Hook": { "type": "object", "required": ["name", "stableResult"], From b675b454164be5aef92c0393184a240e1263ab30 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Thu, 4 Jul 2024 09:42:27 +0100 Subject: [PATCH 4/5] feat: enable graphql linting --- CHANGELOG.md | 8 ++ crates/biome_cli/src/commands/lint.rs | 1 - crates/biome_cli/src/commands/rage.rs | 4 +- crates/biome_cli/tests/cases/graphql.rs | 115 ++++++++++++++++++ crates/biome_cli/tests/cases/mod.rs | 1 + .../format_and_write_graphql_files.snap | 23 ++++ .../format_graphql_files.snap | 53 ++++++++ .../main_cases_graphql/lint_single_rule.snap | 36 ++++++ .../with_linter_configuration.snap | 1 + crates/biome_configuration/src/graphql.rs | 37 ++++-- crates/biome_configuration/src/lib.rs | 11 ++ .../tests/spec_test.rs | 1 + 12 files changed, 277 insertions(+), 14 deletions(-) create mode 100644 crates/biome_cli/tests/cases/graphql.rs create mode 100644 crates/biome_cli/tests/snapshots/main_cases_graphql/format_and_write_graphql_files.snap create mode 100644 crates/biome_cli/tests/snapshots/main_cases_graphql/format_graphql_files.snap create mode 100644 crates/biome_cli/tests/snapshots/main_cases_graphql/lint_single_rule.snap diff --git a/CHANGELOG.md b/CHANGELOG.md index 64381784d5da..ee2337259c7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,10 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b ### CLI +#### New features + +- Add `--graphql-linter-enabled` option, to control whether the linter should enabled or not for GraphQL files. Contributed by @ematipico + ### Configuration - Add support for loading configuration from `.editorconfig` files ([#1724](https://github.com/biomejs/biome/issues/1724)). Contributed by @dyc3 @@ -69,6 +73,10 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b Contributed by @Conaclos +#### New features + +- Add support for GraphQL linting. Contributed by @ematipico + #### Bug fixes - Don't request alt text for elements hidden from assistive technologies ([#3316](https://github.com/biomejs/biome/issues/3316)). Contributed by @robintown diff --git a/crates/biome_cli/src/commands/lint.rs b/crates/biome_cli/src/commands/lint.rs index b6e08746b03d..07dfdb14283b 100644 --- a/crates/biome_cli/src/commands/lint.rs +++ b/crates/biome_cli/src/commands/lint.rs @@ -149,7 +149,6 @@ pub(crate) fn lint(session: CliSession, payload: LintCommandPayload) -> Result<( let stdin = get_stdin(stdin_file_path, &mut *session.app.console, "lint")?; - dbg!(&fs_configuration); session .app .workspace diff --git a/crates/biome_cli/src/commands/rage.rs b/crates/biome_cli/src/commands/rage.rs index 057c6ec1fec3..86a46b16b3ec 100644 --- a/crates/biome_cli/src/commands/rage.rs +++ b/crates/biome_cli/src/commands/rage.rs @@ -271,7 +271,7 @@ impl Display for RageConfiguration<'_, '_> { configuration.get_graphql_formatter_configuration(); markup! ( {Section("GraphQL Formatter")} - {KeyValuePair("Enabled", markup!({DebugDisplay(graphql_formatter_configuration.enabled)}))} + {KeyValuePair("Enabled", markup!({DebugDisplayOption(graphql_formatter_configuration.enabled)}))} {KeyValuePair("Indent style", markup!({DebugDisplayOption(graphql_formatter_configuration.indent_style)}))} {KeyValuePair("Indent width", markup!({DebugDisplayOption(graphql_formatter_configuration.indent_width)}))} {KeyValuePair("Line ending", markup!({DebugDisplayOption(graphql_formatter_configuration.line_ending)}))} @@ -288,11 +288,13 @@ impl Display for RageConfiguration<'_, '_> { let javascript_linter = configuration.get_javascript_linter_configuration(); let json_linter = configuration.get_json_linter_configuration(); let css_linter = configuration.get_css_linter_configuration(); + let graphq_linter = configuration.get_graphql_linter_configuration(); markup! ( {Section("Linter")} {KeyValuePair("JavaScript enabled", markup!({DebugDisplay(javascript_linter.enabled)}))} {KeyValuePair("JSON enabled", markup!({DebugDisplay(json_linter.enabled)}))} {KeyValuePair("CSS enabled", markup!({DebugDisplay(css_linter.enabled)}))} + {KeyValuePair("GraphQL enabled", markup!({DebugDisplayOption(graphq_linter.enabled)}))} {KeyValuePair("Recommended", markup!({DebugDisplay(linter_configuration.recommended.unwrap_or_default())}))} {KeyValuePair("All", markup!({DebugDisplay(linter_configuration.all.unwrap_or_default())}))} {RageConfigurationLintRules("Enabled rules",linter_configuration)} diff --git a/crates/biome_cli/tests/cases/graphql.rs b/crates/biome_cli/tests/cases/graphql.rs new file mode 100644 index 000000000000..7e8dee54a6c3 --- /dev/null +++ b/crates/biome_cli/tests/cases/graphql.rs @@ -0,0 +1,115 @@ +use crate::run_cli; +use crate::snap_test::{assert_cli_snapshot, assert_file_contents, SnapshotPayload}; +use biome_console::BufferConsole; +use biome_fs::MemoryFileSystem; +use biome_service::DynRef; +use bpaf::Args; +use std::path::Path; + +const UNFORMATTED: &str = r#"type Query { + me: User +} + +type User { id: ID name: String +}"#; + +const FORMATTED: &str = "type Query {\n\tme: User\n}\n\ntype User {\n\tid: ID\n\tname: String\n}\n"; + +const MISSING_REASON: &str = r#"query { + member @deprecated { + id + } +}"#; + +#[test] +fn format_graphql_files() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let file_path = Path::new("file.graphql"); + fs.insert(file_path.into(), UNFORMATTED.as_bytes()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from([("format"), file_path.as_os_str().to_str().unwrap()].as_slice()), + ); + + assert!(result.is_err(), "run_cli returned {result:?}"); + + assert_file_contents(&fs, file_path, UNFORMATTED); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "format_graphql_files", + fs, + console, + result, + )); +} + +#[test] +fn format_and_write_graphql_files() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let file_path = Path::new("file.graphql"); + fs.insert(file_path.into(), UNFORMATTED.as_bytes()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from( + [ + ("format"), + "--write", + file_path.as_os_str().to_str().unwrap(), + ] + .as_slice(), + ), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + assert_file_contents(&fs, file_path, FORMATTED); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "format_and_write_graphql_files", + fs, + console, + result, + )); +} + +#[test] +fn lint_single_rule() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let file_path = Path::new("file.graphql"); + fs.insert(file_path.into(), MISSING_REASON.as_bytes()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from( + [ + ("lint"), + "--only=nursery/useDeprecatedReason", + file_path.as_os_str().to_str().unwrap(), + ] + .as_slice(), + ), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "lint_single_rule", + fs, + console, + result, + )); +} diff --git a/crates/biome_cli/tests/cases/mod.rs b/crates/biome_cli/tests/cases/mod.rs index fc3e960808d8..8c76695ba529 100644 --- a/crates/biome_cli/tests/cases/mod.rs +++ b/crates/biome_cli/tests/cases/mod.rs @@ -7,6 +7,7 @@ mod config_path; mod cts_files; mod diagnostics; mod editorconfig; +mod graphql; mod handle_astro_files; mod handle_css_files; mod handle_svelte_files; diff --git a/crates/biome_cli/tests/snapshots/main_cases_graphql/format_and_write_graphql_files.snap b/crates/biome_cli/tests/snapshots/main_cases_graphql/format_and_write_graphql_files.snap new file mode 100644 index 000000000000..21ef37915e23 --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_cases_graphql/format_and_write_graphql_files.snap @@ -0,0 +1,23 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +## `file.graphql` + +```graphql +type Query { + me: User +} + +type User { + id: ID + name: String +} + +``` + +# Emitted Messages + +```block +Formatted 1 file in