From 1ac42a4a72ee505546625e5c5f985534942f8256 Mon Sep 17 00:00:00 2001 From: Tushar Mathur Date: Thu, 2 May 2024 22:40:33 +0530 Subject: [PATCH] refactor: remove overrides from `.prettierrc` (#1841) --- .prettierrc | 24 ----------------------- tailcall-prettier/src/lib.rs | 4 ++-- tailcall-prettier/src/parser.rs | 2 +- tailcall-prettier/src/prettier.rs | 8 ++++++-- tests/core/spec.rs | 27 ++++++++++++-------------- tests/execution/add-field-many-list.md | 5 ++++- tests/execution/add-field-many.md | 5 ++++- tests/execution/auth.md | 6 +++++- tests/execution/inline-many-list.md | 5 ++++- tests/execution/inline-many.md | 5 ++++- tests/execution/omit-many.md | 4 +++- tests/execution/test-grpc.md | 8 ++++++-- 12 files changed, 51 insertions(+), 52 deletions(-) diff --git a/.prettierrc b/.prettierrc index b38a6da2a4..75740ae27a 100644 --- a/.prettierrc +++ b/.prettierrc @@ -5,30 +5,6 @@ "tabWidth": 2, "bracketSpacing": false, "overrides": [ - { - "files": [ - "add-field-many-list.graphql", - "add-field-many-list.md", - "add-field-many.graphql", - "add-field-many.md", - "inline-many.graphql", - "inline-many.md", - "inline-many-list.graphql", - "inline-many-list.md", - "test-grpc.graphql", - "test-add-link-to-empty-config.graphql", - "test-add-link-to-empty-config.md", - "test-grpc.md", - "test-expr-success.graphql", - "test-expr-success.md", - "omit-many.graphql", - "omit-many.md", - "auth.md" - ], - "options": { - "printWidth": 210 - } - }, { "files": ["devcontainer.json"], "options": { diff --git a/tailcall-prettier/src/lib.rs b/tailcall-prettier/src/lib.rs index 13b706a359..74f2f25b54 100644 --- a/tailcall-prettier/src/lib.rs +++ b/tailcall-prettier/src/lib.rs @@ -9,7 +9,7 @@ lazy_static::lazy_static! { static ref PRETTIER: Arc = Arc::new(Prettier::new()); } -pub async fn format>(source: T, parser: Parser) -> Result { +pub async fn format>(source: T, parser: &Parser) -> Result { PRETTIER.format(source.as_ref().to_string(), parser).await } @@ -19,7 +19,7 @@ mod tests { #[tokio::test] async fn test_js() -> anyhow::Result<()> { - let prettier = format("const x={a:3};", Parser::Js).await?; + let prettier = format("const x={a:3};", &Parser::Js).await?; assert_eq!("const x = {a: 3}\n", prettier); Ok(()) } diff --git a/tailcall-prettier/src/parser.rs b/tailcall-prettier/src/parser.rs index 1a0484983f..26a31bc9e8 100644 --- a/tailcall-prettier/src/parser.rs +++ b/tailcall-prettier/src/parser.rs @@ -1,6 +1,6 @@ use anyhow::{anyhow, Result}; -#[derive(strum_macros::Display)] +#[derive(strum_macros::Display, Clone)] pub enum Parser { Gql, Yml, diff --git a/tailcall-prettier/src/prettier.rs b/tailcall-prettier/src/prettier.rs index 0693ae6b67..b196d667ce 100644 --- a/tailcall-prettier/src/prettier.rs +++ b/tailcall-prettier/src/prettier.rs @@ -19,7 +19,8 @@ impl Prettier { Self { runtime } } - pub async fn format(&self, source: String, parser: Parser) -> Result { + pub async fn format<'a>(&'a self, source: String, parser: &'a Parser) -> Result { + let parser = parser.clone(); self.runtime .spawn_blocking(move || { let mut command = command(); @@ -38,7 +39,10 @@ impl Prettier { if output.status.success() { Ok(String::from_utf8(output.stdout)?) } else { - Err(anyhow!("Prettier formatting failed")) + Err(anyhow!( + "Prettier formatting failed: {}", + String::from_utf8(output.stderr).unwrap() + )) } }) .await? diff --git a/tests/core/spec.rs b/tests/core/spec.rs index 6b3e5b72af..e93aeb28dd 100644 --- a/tests/core/spec.rs +++ b/tests/core/spec.rs @@ -122,30 +122,27 @@ async fn check_server_config(spec: ExecutionSpec) -> Vec { // tests that were explicitly written with it in mind if spec.check_identity { if matches!(source, Source::GraphQL) { - let identity = config.to_sdl(); + let actual = config.to_sdl(); // \r is added automatically in windows, it's safe to replace it with \n let content = content.replace("\r\n", "\n"); let path_str = spec.path.display().to_string(); + let context = format!("path: {}", path_str); - let identity = tailcall_prettier::format( - identity, - tailcall_prettier::Parser::detect(path_str.as_str()).unwrap(), - ) - .await - .unwrap(); + let actual = tailcall_prettier::format(actual, &tailcall_prettier::Parser::Gql) + .await + .context(context.clone()) + .unwrap(); - let content = tailcall_prettier::format( - content, - tailcall_prettier::Parser::detect(path_str.as_str()).unwrap(), - ) - .await - .unwrap(); + let expected = tailcall_prettier::format(content, &tailcall_prettier::Parser::Gql) + .await + .context(context) + .unwrap(); pretty_assertions::assert_eq!( - identity, - content, + actual, + expected, "Identity check failed for {:#?}", spec.path, ); diff --git a/tests/execution/add-field-many-list.md b/tests/execution/add-field-many-list.md index c4dd3ba8f1..2efbae182d 100644 --- a/tests/execution/add-field-many-list.md +++ b/tests/execution/add-field-many-list.md @@ -19,7 +19,10 @@ type Query { u: U @http(baseURL: "http://jsonplaceholder.typicode.com", path: "/us/1") } -type U @addField(name: "b", path: ["a", "b"]) @addField(name: "c", path: ["a", "c"]) @addField(name: "d", path: ["a", "d"]) { +type U + @addField(name: "b", path: ["a", "b"]) + @addField(name: "c", path: ["a", "c"]) + @addField(name: "d", path: ["a", "d"]) { a: A e: String } diff --git a/tests/execution/add-field-many.md b/tests/execution/add-field-many.md index 146e7b17bd..74bd20d41d 100644 --- a/tests/execution/add-field-many.md +++ b/tests/execution/add-field-many.md @@ -9,7 +9,10 @@ schema @server @upstream { query: Query } -type Foo @addField(name: "a", path: ["x", "a"]) @addField(name: "b", path: ["x", "b"]) @addField(name: "c", path: ["x", "c"]) { +type Foo + @addField(name: "a", path: ["x", "a"]) + @addField(name: "b", path: ["x", "b"]) + @addField(name: "c", path: ["x", "c"]) { name: String x: X } diff --git a/tests/execution/auth.md b/tests/execution/auth.md index 78cb3057e7..62c9664897 100644 --- a/tests/execution/auth.md +++ b/tests/execution/auth.md @@ -5,7 +5,11 @@ check_identity: true # auth ```graphql @server -schema @server @upstream @link(id: "htpasswd", src: ".htpasswd", type: Htpasswd) @link(id: "jwks", src: "jwks.json", type: Jwks) { +schema + @server + @upstream + @link(id: "htpasswd", src: ".htpasswd", type: Htpasswd) + @link(id: "jwks", src: "jwks.json", type: Jwks) { query: Query } diff --git a/tests/execution/inline-many-list.md b/tests/execution/inline-many-list.md index 719cb48d56..67a140876a 100644 --- a/tests/execution/inline-many-list.md +++ b/tests/execution/inline-many-list.md @@ -19,7 +19,10 @@ type Query { u: U @http(baseURL: "http://jsonplaceholder.typicode.com", path: "/us/1") } -type U @addField(name: "b", path: ["a", "b"]) @addField(name: "c", path: ["a", "c"]) @addField(name: "d", path: ["a", "d"]) { +type U + @addField(name: "b", path: ["a", "b"]) + @addField(name: "c", path: ["a", "c"]) + @addField(name: "d", path: ["a", "d"]) { a: A @modify(omit: true) e: String } diff --git a/tests/execution/inline-many.md b/tests/execution/inline-many.md index 054187d179..b3d2a7d92e 100644 --- a/tests/execution/inline-many.md +++ b/tests/execution/inline-many.md @@ -19,7 +19,10 @@ type Query { user: User @http(baseURL: "http://jsonplaceholder.typicode.com", path: "/users/1") } -type User @addField(name: "city", path: ["address", "city"]) @addField(name: "street", path: ["address", "street"]) @addField(name: "zipcode", path: ["address", "zipcode"]) { +type User + @addField(name: "city", path: ["address", "city"]) + @addField(name: "street", path: ["address", "street"]) + @addField(name: "zipcode", path: ["address", "zipcode"]) { address: Address @modify(omit: true) name: String } diff --git a/tests/execution/omit-many.md b/tests/execution/omit-many.md index b39fc236d7..0a76858fec 100644 --- a/tests/execution/omit-many.md +++ b/tests/execution/omit-many.md @@ -20,7 +20,9 @@ type Query { user: User @http(baseURL: "http://jsonplaceholder.typicode.com", path: "/users/1") } -type User @addField(name: "zipcode", path: ["address", "zipcode"]) @addField(name: "complements", path: ["address", "complements"]) { +type User + @addField(name: "zipcode", path: ["address", "zipcode"]) + @addField(name: "complements", path: ["address", "complements"]) { address: Address @omit name: String } diff --git a/tests/execution/test-grpc.md b/tests/execution/test-grpc.md index 9394cae654..e456b7d424 100644 --- a/tests/execution/test-grpc.md +++ b/tests/execution/test-grpc.md @@ -41,7 +41,10 @@ message NewsList { ``` ```graphql @server -schema @server(port: 8000) @upstream(baseURL: "http://localhost:50051", batch: {delay: 10, headers: [], maxSize: 1000}) @link(id: "news", src: "news.proto", type: Protobuf) { +schema + @server(port: 8000) + @upstream(baseURL: "http://localhost:50051", batch: {delay: 10, headers: [], maxSize: 1000}) + @link(id: "news", src: "news.proto", type: Protobuf) { query: Query } @@ -66,6 +69,7 @@ type NewsData { type Query { news: NewsData! @grpc(method: "news.NewsService.GetAllNews") newsById(news: NewsInput!): News! @grpc(body: "{{.args.news}}", method: "news.NewsService.GetNews") - newsByIdBatch(news: NewsInput!): News! @grpc(body: "{{.args.news}}", batchKey: ["news", "id"], method: "news.NewsService.GetMultipleNews") + newsByIdBatch(news: NewsInput!): News! + @grpc(body: "{{.args.news}}", batchKey: ["news", "id"], method: "news.NewsService.GetMultipleNews") } ```