forked from biomejs/biome
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(graphql_formatter): bootstrap GraphQL formatter (biomejs#3255)
- Loading branch information
1 parent
1eec3ce
commit fbe402c
Showing
287 changed files
with
13,432 additions
and
120 deletions.
There are no files selected for viewing
This file contains 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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 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 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,84 @@ | ||
use crate::PlainIndentStyle; | ||
use biome_deserialize_macros::{Deserializable, Merge, Partial}; | ||
use biome_formatter::{IndentWidth, LineEnding, LineWidth, QuoteStyle}; | ||
use bpaf::Bpaf; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// Options applied to GraphQL files | ||
#[derive(Clone, Default, 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 GraphqlConfiguration { | ||
/// GraphQL formatter options | ||
#[partial(type, bpaf(external(partial_graphql_formatter), optional))] | ||
pub formatter: GraphqlFormatter, | ||
} | ||
|
||
/// Options that changes how the GraphQL formatter behaves | ||
#[derive(Clone, Debug, Default, 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 GraphqlFormatter { | ||
/// Control the formatter for GraphQL files. | ||
#[partial(bpaf(long("graphql-formatter-enabled"), argument("true|false"), optional))] | ||
pub enabled: bool, | ||
|
||
/// The indent style applied to GraphQL files. | ||
#[partial(bpaf( | ||
long("graphql-formatter-indent-style"), | ||
argument("tab|space"), | ||
optional | ||
))] | ||
pub indent_style: Option<PlainIndentStyle>, | ||
|
||
/// The size of the indentation applied to GraphQL files. Default to 2. | ||
#[partial(bpaf(long("graphql-formatter-indent-width"), argument("NUMBER"), optional))] | ||
pub indent_width: Option<IndentWidth>, | ||
|
||
/// The type of line ending applied to GraphQL files. | ||
#[partial(bpaf( | ||
long("graphql-formatter-line-ending"), | ||
argument("lf|crlf|cr"), | ||
optional | ||
))] | ||
pub line_ending: Option<LineEnding>, | ||
|
||
/// What's the max width of a line applied to GraphQL files. Defaults to 80. | ||
#[partial(bpaf(long("graphql-formatter-line-width"), argument("NUMBER"), optional))] | ||
pub line_width: Option<LineWidth>, | ||
|
||
/// The type of quotes used in GraphQL code. Defaults to double. | ||
#[partial(bpaf( | ||
long("graphql-formatter-quote-style"), | ||
argument("double|single"), | ||
optional | ||
))] | ||
pub quote_style: QuoteStyle, | ||
} | ||
|
||
impl PartialGraphqlFormatter { | ||
pub fn get_formatter_configuration(&self) -> GraphqlFormatter { | ||
GraphqlFormatter { | ||
enabled: self.enabled.unwrap_or_default(), | ||
indent_style: self.indent_style, | ||
indent_width: self.indent_width, | ||
line_ending: self.line_ending, | ||
line_width: self.line_width, | ||
quote_style: self.quote_style.unwrap_or_default(), | ||
} | ||
} | ||
} | ||
|
||
#[test] | ||
fn default_graphql() { | ||
let graphql_configuration = GraphqlFormatter::default(); | ||
|
||
assert!(!graphql_configuration.enabled); | ||
assert_eq!(graphql_configuration.indent_style, None); | ||
assert_eq!(graphql_configuration.indent_width, None); | ||
assert_eq!(graphql_configuration.line_ending, None); | ||
assert_eq!(graphql_configuration.line_width, None); | ||
assert_eq!(graphql_configuration.quote_style, QuoteStyle::Double); | ||
} |
This file contains 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 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 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 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 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,38 @@ | ||
[package] | ||
authors.workspace = true | ||
categories.workspace = true | ||
description = "Biome's GraphQL formatter" | ||
edition.workspace = true | ||
homepage.workspace = true | ||
keywords.workspace = true | ||
license.workspace = true | ||
name = "biome_graphql_formatter" | ||
repository.workspace = true | ||
version = "0.1.0" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
biome_diagnostics = { workspace = true } | ||
biome_formatter = { workspace = true } | ||
biome_graphql_syntax = { workspace = true } | ||
biome_rowan = { workspace = true } | ||
biome_suppression = { workspace = true } | ||
|
||
[dev-dependencies] | ||
biome_configuration = { path = "../biome_configuration" } | ||
biome_formatter_test = { path = "../biome_formatter_test" } | ||
biome_graphql_parser = { path = "../biome_graphql_parser" } | ||
biome_parser = { path = "../biome_parser" } | ||
biome_service = { path = "../biome_service" } | ||
countme = { workspace = true, features = ["enable"] } | ||
serde = { workspace = true, features = ["derive"] } | ||
serde_json = { workspace = true } | ||
tests_macros = { path = "../tests_macros" } | ||
|
||
# cargo-workspaces metadata | ||
[package.metadata.workspaces] | ||
independent = true | ||
|
||
[lints] | ||
workspace = true |
This file contains 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,19 @@ | ||
<p align="center"> | ||
<img alt="Biome - Toolchain of the web" width="400" src="https://raw.githubusercontent.com/biomejs/resources/main/svg/slogan-light-transparent.svg"/> | ||
</p> | ||
|
||
<div align="center"> | ||
|
||
[![Discord chat][discord-badge]][discord-url] | ||
[![cargo version][cargo-badge]][cargo-url] | ||
|
||
[discord-badge]: https://badgen.net/discord/online-members/BypW39g6Yc?icon=discord&label=discord&color=green | ||
[discord-url]: https://discord.gg/BypW39g6Yc | ||
[cargo-badge]: https://badgen.net/crates/v/biome_graphql_formatter?&color=green | ||
[cargo-url]: https://crates.io/crates/biome_graphql_formatter/ | ||
|
||
</div> | ||
|
||
# `biome_graphql_formatter` | ||
|
||
Biome's GraphQL formatter implementation. Follow the [documentation](https://docs.rs/biome_graphql_formatter/). |
Oops, something went wrong.