From 59b3a9bc568a90af8282cd99bf3d465b74348329 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Sat, 24 Jun 2017 11:06:56 -0700 Subject: [PATCH] Add support for --no-bracket-spacing for GraphQL (#2255) Fixes #2252 --- src/printer-graphql.js | 4 +-- .../__snapshots__/jsfmt.spec.js.snap | 29 +++++++++++++++++++ .../bracket_spacing.graphql | 6 ++++ tests/graphql_bracket_spacing/jsfmt.spec.js | 2 ++ 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 tests/graphql_bracket_spacing/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/graphql_bracket_spacing/bracket_spacing.graphql create mode 100644 tests/graphql_bracket_spacing/jsfmt.spec.js diff --git a/src/printer-graphql.js b/src/printer-graphql.js index b5c2914de..503d378a5 100644 --- a/src/printer-graphql.js +++ b/src/printer-graphql.js @@ -143,7 +143,7 @@ function genericPrint(path, options, print) { return group( concat([ "{", - n.fields.length > 0 ? " " : "", + options.bracketSpacing && n.fields.length > 0 ? " " : "", indent( concat([ softline, @@ -154,7 +154,7 @@ function genericPrint(path, options, print) { ]) ), softline, - ifBreak("", n.fields.length > 0 ? " " : ""), + ifBreak("", options.bracketSpacing && n.fields.length > 0 ? " " : ""), "}" ]) ); diff --git a/tests/graphql_bracket_spacing/__snapshots__/jsfmt.spec.js.snap b/tests/graphql_bracket_spacing/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000..143ab37d7 --- /dev/null +++ b/tests/graphql_bracket_spacing/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,29 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`bracket_spacing.graphql 1`] = ` +fragment Visit on HighlightedVisit + @argumentDefinitions( + count: {type: "Int", defaultValue: 20} + ) { + name +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +fragment Visit on HighlightedVisit + @argumentDefinitions(count: { type: "Int", defaultValue: 20 }) { + name +} +`; + +exports[`bracket_spacing.graphql 2`] = ` +fragment Visit on HighlightedVisit + @argumentDefinitions( + count: {type: "Int", defaultValue: 20} + ) { + name +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +fragment Visit on HighlightedVisit + @argumentDefinitions(count: {type: "Int", defaultValue: 20}) { + name +} +`; diff --git a/tests/graphql_bracket_spacing/bracket_spacing.graphql b/tests/graphql_bracket_spacing/bracket_spacing.graphql new file mode 100644 index 000000000..0e047c3f5 --- /dev/null +++ b/tests/graphql_bracket_spacing/bracket_spacing.graphql @@ -0,0 +1,6 @@ +fragment Visit on HighlightedVisit + @argumentDefinitions( + count: {type: "Int", defaultValue: 20} + ) { + name +} diff --git a/tests/graphql_bracket_spacing/jsfmt.spec.js b/tests/graphql_bracket_spacing/jsfmt.spec.js new file mode 100644 index 000000000..4f10d724b --- /dev/null +++ b/tests/graphql_bracket_spacing/jsfmt.spec.js @@ -0,0 +1,2 @@ +run_spec(__dirname, { parser: "graphql" }); +run_spec(__dirname, { parser: "graphql", bracketSpacing: false });