-
-
Notifications
You must be signed in to change notification settings - Fork 791
feat(biome_graphql_analyze): implement useConsistentGraphqlDescriptions
#7672
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
9147ffa
feat(biome_graphql_analyze): implement `useDescriptionStyle`
Netail 49fad78
[autofix.ci] apply automated fixes
autofix-ci[bot] 9107c7b
fix: apply coderabbitai suggestions
Netail 8cb0b33
[autofix.ci] apply automated fixes
autofix-ci[bot] c19a003
fix: feedback
Netail 7fcd33d
Merge branch 'main' into feat/use-description-style
Netail c3672ee
fix: feedback
Netail 3cc9177
fix: feedback v2
Netail 07d6c22
Merge branch 'main' into feat/use-description-style
Netail 42e5a2a
fix: options example
Netail 6cfba4a
Merge branch 'main' into feat/use-description-style
Netail 3fa40a8
Merge branch 'main' into feat/use-description-style
Netail d258e08
Merge branch 'main' into feat/use-description-style
Netail adebefe
split tests
Netail e0d7ef2
[autofix.ci] apply automated fixes
autofix-ci[bot] bdd2b90
Merge branch 'main' into feat/use-description-style
Netail aa7abe9
.
Netail 7929050
Merge branch 'main' into feat/use-description-style
Netail c2f75e2
Merge branch 'main' into feat/use-description-style
Netail c14d38f
fix: coderabbit feedback
Netail File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| --- | ||
| "@biomejs/biome": patch | ||
| --- | ||
|
|
||
| Added the nursery rule [`useConsistentGraphqlDescriptions`](https://biomejs.dev/linter/rules/use-consistent-graphql-descriptions/), requiring all descriptions to follow the same style (either block or inline) inside GraphQL files. | ||
|
|
||
| **Invalid:** | ||
|
|
||
| ```graphql | ||
| enum EnumValue { | ||
| "this is a description" | ||
| DEFAULT | ||
| } | ||
| ``` | ||
|
|
||
| **Valid:** | ||
|
|
||
| ```graphql | ||
| enum EnumValue { | ||
| """ | ||
| this is a description | ||
| """ | ||
| DEFAULT | ||
| } | ||
| ``` |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
crates/biome_graphql_analyze/src/lint/nursery/use_consistent_graphql_descriptions.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| use biome_analyze::{ | ||
| Ast, Rule, RuleDiagnostic, RuleSource, context::RuleContext, declare_lint_rule, | ||
| }; | ||
| use biome_console::markup; | ||
| use biome_graphql_syntax::GraphqlDescription; | ||
| use biome_rowan::AstNode; | ||
| use biome_rule_options::use_consistent_graphql_descriptions::{ | ||
| Style, UseConsistentGraphqlDescriptionsOptions, | ||
| }; | ||
|
|
||
| declare_lint_rule! { | ||
| /// Require all descriptions to follow the same style (either block or inline) to maintain consistency and improve readability across the schema. | ||
| /// | ||
| /// ## Examples | ||
| /// | ||
| /// ### style: `block` | ||
| /// | ||
| /// #### Invalid | ||
| /// | ||
| /// ```graphql,expect_diagnostic | ||
| /// enum EnumValue { | ||
| /// "this is a description" | ||
| /// DEFAULT | ||
| /// } | ||
| /// ``` | ||
| /// | ||
| /// #### Valid | ||
| /// | ||
| /// ```graphql | ||
| /// enum EnumValue { | ||
| /// """ | ||
| /// this is a description | ||
| /// """ | ||
| /// DEFAULT | ||
| /// } | ||
| /// ``` | ||
| /// | ||
| /// ## Options | ||
| /// | ||
| /// ### `style` | ||
| /// | ||
| /// This option will specify the description style. | ||
| /// - `"block"`: Requires triple-quoted block descriptions (`"""..."""`) | ||
| /// - `"inline"`: Requires single-quoted inline descriptions (`"..."`) | ||
| /// | ||
| /// Default `"block"` | ||
| /// | ||
| /// ```json,options | ||
| /// { | ||
| /// "options": { | ||
| /// "style": "inline" | ||
| /// } | ||
| /// } | ||
| /// ``` | ||
| /// | ||
| /// ```graphql,expect_diagnostic,use_options | ||
| /// enum EnumValue { | ||
| /// """ | ||
| /// this is a description | ||
| /// """ | ||
| /// DEFAULT | ||
| /// } | ||
| /// ``` | ||
| /// | ||
| pub UseConsistentGraphqlDescriptions { | ||
| version: "next", | ||
| name: "useConsistentGraphqlDescriptions", | ||
| language: "graphql", | ||
| sources: &[RuleSource::EslintGraphql("description-style").same()], | ||
| recommended: false, | ||
| } | ||
| } | ||
|
|
||
| impl Rule for UseConsistentGraphqlDescriptions { | ||
| type Query = Ast<GraphqlDescription>; | ||
| type State = (); | ||
| type Signals = Option<Self::State>; | ||
| type Options = UseConsistentGraphqlDescriptionsOptions; | ||
|
|
||
| fn run(ctx: &RuleContext<Self>) -> Option<Self::State> { | ||
| let node = ctx.query(); | ||
| let style = ctx.options().style.unwrap_or_default(); | ||
|
|
||
| let value = node.graphql_string_value().ok()?; | ||
|
|
||
| if style == Style::Block && !value.is_block() { | ||
| return Some(()); | ||
| } | ||
|
|
||
| if style == Style::Inline && value.is_block() { | ||
| return Some(()); | ||
| } | ||
|
|
||
| None | ||
| } | ||
|
|
||
| fn diagnostic(ctx: &RuleContext<Self>, _state: &Self::State) -> Option<RuleDiagnostic> { | ||
| let span = ctx.query().range(); | ||
| let style = ctx.options().style.unwrap_or_default(); | ||
|
|
||
| Some( | ||
| RuleDiagnostic::new( | ||
| rule_category!(), | ||
| span, | ||
| markup! { | ||
| "Unexpected "{if style == Style::Block { Style::Inline } else { Style::Block }}" description style." | ||
| }, | ||
| ) | ||
| .note(markup! { | ||
| "To stay consistent within the project, write the description "{style}" style." | ||
| }), | ||
| ) | ||
| } | ||
| } | ||
8 changes: 8 additions & 0 deletions
8
...raphql_analyze/tests/specs/nursery/useConsistentGraphqlDescriptions/block/invalid.graphql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| enum EnumValue { | ||
| "basic" | ||
| BASIC | ||
| "fluent" | ||
| FLUENT | ||
| "native" | ||
| NATIVE | ||
| } |
67 changes: 67 additions & 0 deletions
67
...l_analyze/tests/specs/nursery/useConsistentGraphqlDescriptions/block/invalid.graphql.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| --- | ||
| source: crates/biome_graphql_analyze/tests/spec_tests.rs | ||
| expression: invalid.graphql | ||
| --- | ||
| # Input | ||
| ```graphql | ||
| enum EnumValue { | ||
| "basic" | ||
| BASIC | ||
| "fluent" | ||
| FLUENT | ||
| "native" | ||
| NATIVE | ||
| } | ||
| ``` | ||
|
|
||
| # Diagnostics | ||
| ``` | ||
| invalid.graphql:2:2 lint/nursery/useConsistentGraphqlDescriptions ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
| i Unexpected inline description style. | ||
| 1 │ enum EnumValue { | ||
| > 2 │ "basic" | ||
| │ ^^^^^^^ | ||
| 3 │ BASIC | ||
| 4 │ "fluent" | ||
| i To stay consistent within the project, write the description block style. | ||
| ``` | ||
| ``` | ||
| invalid.graphql:4:2 lint/nursery/useConsistentGraphqlDescriptions ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
| i Unexpected inline description style. | ||
| 2 │ "basic" | ||
| 3 │ BASIC | ||
| > 4 │ "fluent" | ||
| │ ^^^^^^^^ | ||
| 5 │ FLUENT | ||
| 6 │ "native" | ||
| i To stay consistent within the project, write the description block style. | ||
| ``` | ||
| ``` | ||
| invalid.graphql:6:2 lint/nursery/useConsistentGraphqlDescriptions ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
| i Unexpected inline description style. | ||
| 4 │ "fluent" | ||
| 5 │ FLUENT | ||
| > 6 │ "native" | ||
| │ ^^^^^^^^ | ||
| 7 │ NATIVE | ||
| 8 │ } | ||
| i To stay consistent within the project, write the description block style. | ||
| ``` |
15 changes: 15 additions & 0 deletions
15
..._graphql_analyze/tests/specs/nursery/useConsistentGraphqlDescriptions/block/valid.graphql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # should not generate diagnostics | ||
| enum EnumValue { | ||
| """ | ||
| basic | ||
| """ | ||
| BASIC | ||
| """ | ||
| fluent | ||
| """ | ||
| FLUENT | ||
| """ | ||
| native | ||
| """ | ||
| NATIVE | ||
| } |
23 changes: 23 additions & 0 deletions
23
...hql_analyze/tests/specs/nursery/useConsistentGraphqlDescriptions/block/valid.graphql.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| --- | ||
| source: crates/biome_graphql_analyze/tests/spec_tests.rs | ||
| expression: valid.graphql | ||
| --- | ||
| # Input | ||
| ```graphql | ||
| # should not generate diagnostics | ||
| enum EnumValue { | ||
| """ | ||
| basic | ||
| """ | ||
| BASIC | ||
| """ | ||
| fluent | ||
| """ | ||
| FLUENT | ||
| """ | ||
| native | ||
| """ | ||
| NATIVE | ||
| } | ||
|
|
||
| ``` |
14 changes: 14 additions & 0 deletions
14
...aphql_analyze/tests/specs/nursery/useConsistentGraphqlDescriptions/inline/invalid.graphql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| enum EnumValue { | ||
| """ | ||
| basic | ||
| """ | ||
| BASIC | ||
| """ | ||
| fluent | ||
| """ | ||
| FLUENT | ||
| """ | ||
| native | ||
| """ | ||
| NATIVE | ||
| } |
82 changes: 82 additions & 0 deletions
82
..._analyze/tests/specs/nursery/useConsistentGraphqlDescriptions/inline/invalid.graphql.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| --- | ||
| source: crates/biome_graphql_analyze/tests/spec_tests.rs | ||
| expression: invalid.graphql | ||
| --- | ||
| # Input | ||
| ```graphql | ||
| enum EnumValue { | ||
| """ | ||
| basic | ||
| """ | ||
| BASIC | ||
| """ | ||
| fluent | ||
| """ | ||
| FLUENT | ||
| """ | ||
| native | ||
| """ | ||
| NATIVE | ||
| } | ||
|
|
||
| ``` | ||
|
|
||
| # Diagnostics | ||
| ``` | ||
| invalid.graphql:2:2 lint/nursery/useConsistentGraphqlDescriptions ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
|
|
||
| i Unexpected block description style. | ||
|
|
||
| 1 │ enum EnumValue { | ||
| > 2 │ """ | ||
| │ ^^^ | ||
| > 3 │ basic | ||
| > 4 │ """ | ||
| │ ^^^ | ||
| 5 │ BASIC | ||
| 6 │ """ | ||
|
|
||
| i To stay consistent within the project, write the description inline style. | ||
|
|
||
|
|
||
| ``` | ||
|
|
||
| ``` | ||
| invalid.graphql:6:2 lint/nursery/useConsistentGraphqlDescriptions ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
|
|
||
| i Unexpected block description style. | ||
|
|
||
| 4 │ """ | ||
| 5 │ BASIC | ||
| > 6 │ """ | ||
| │ ^^^ | ||
| > 7 │ fluent | ||
| > 8 │ """ | ||
| │ ^^^ | ||
| 9 │ FLUENT | ||
| 10 │ """ | ||
|
|
||
| i To stay consistent within the project, write the description inline style. | ||
|
|
||
|
|
||
| ``` | ||
|
|
||
| ``` | ||
| invalid.graphql:10:2 lint/nursery/useConsistentGraphqlDescriptions ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
|
|
||
| i Unexpected block description style. | ||
|
|
||
| 8 │ """ | ||
| 9 │ FLUENT | ||
| > 10 │ """ | ||
| │ ^^^ | ||
| > 11 │ native | ||
| > 12 │ """ | ||
| │ ^^^ | ||
| 13 │ NATIVE | ||
| 14 │ } | ||
|
|
||
| i To stay consistent within the project, write the description inline style. | ||
|
|
||
|
|
||
| ``` |
15 changes: 15 additions & 0 deletions
15
..._analyze/tests/specs/nursery/useConsistentGraphqlDescriptions/inline/invalid.options.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| "$schema": "../../../../../../../packages/@biomejs/biome/configuration_schema.json", | ||
| "linter": { | ||
| "rules": { | ||
| "nursery": { | ||
| "useConsistentGraphqlDescriptions": { | ||
| "level": "error", | ||
| "options": { | ||
| "style": "inline" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
...graphql_analyze/tests/specs/nursery/useConsistentGraphqlDescriptions/inline/valid.graphql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # should not generate diagnostics | ||
| enum EnumValue { | ||
| "basic" | ||
| BASIC | ||
| "fluent" | ||
| FLUENT | ||
| "native" | ||
| NATIVE | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.