File tree Expand file tree Collapse file tree 2 files changed +24
-13
lines changed Expand file tree Collapse file tree 2 files changed +24
-13
lines changed Original file line number Diff line number Diff line change @@ -162,14 +162,6 @@ const tests = [
162
162
} ,
163
163
output : '.stop {\n color: red;\n}' ,
164
164
} ,
165
- {
166
- title : 'JSON example' ,
167
- input : {
168
- text : '{ "foo": "bar"}' ,
169
- filePath : path . resolve ( './test.json' ) ,
170
- } ,
171
- output : '{ "foo": "bar" }' ,
172
- } ,
173
165
{
174
166
title : 'TypeScript example' ,
175
167
input : {
@@ -178,6 +170,22 @@ const tests = [
178
170
} ,
179
171
output : 'function Foo(this: void) {\n return this;\n}' ,
180
172
} ,
173
+ {
174
+ title : 'GraphQL example' ,
175
+ input : {
176
+ text : 'type Query{test: Test}' ,
177
+ filePath : path . resolve ( './test.gql' ) ,
178
+ } ,
179
+ output : 'type Query {\n test: Test\n}' ,
180
+ } ,
181
+ {
182
+ title : 'JSON example' ,
183
+ input : {
184
+ text : '{ "foo": "bar"}' ,
185
+ filePath : path . resolve ( './test.json' ) ,
186
+ } ,
187
+ output : '{ "foo": "bar" }' ,
188
+ } ,
181
189
]
182
190
183
191
beforeEach ( ( ) => {
Original file line number Diff line number Diff line change @@ -86,24 +86,27 @@ function format(options) {
86
86
)
87
87
88
88
const isCss = / \. ( c s s | l e s s | s c s s ) $ / . test ( filePath )
89
+ const isTypeScript = / \. ( t s | t s x ) $ / . test ( filePath )
90
+ const isGraphQL = / \. ( g r a p h q l | g q l ) $ / . test ( filePath )
89
91
const isJson = / \. j s o n $ / . test ( filePath )
90
- const isTypeScript = / \. t s x ? $ / . test ( filePath )
91
92
92
93
if ( isCss ) {
93
94
formattingOptions . prettier . parser = 'postcss'
94
- } else if ( isJson ) {
95
- formattingOptions . prettier . parser = 'json'
96
- formattingOptions . prettier . trailingComma = 'none'
97
95
} else if ( isTypeScript ) {
98
96
formattingOptions . prettier . parser = 'typescript'
99
97
// XXX: It seems babylon is getting a TypeScript plugin.
100
98
// Should that be used instead?
101
99
formattingOptions . eslint . parser = 'typescript-eslint-parser'
100
+ } else if ( isGraphQL ) {
101
+ formattingOptions . prettier . parser = 'graphql'
102
+ } else if ( isJson ) {
103
+ formattingOptions . prettier . parser = 'json'
104
+ formattingOptions . prettier . trailingComma = 'none'
102
105
}
103
106
104
107
const prettify = createPrettify ( formattingOptions . prettier , prettierPath )
105
108
106
- if ( isCss || isJson ) {
109
+ if ( isCss || isGraphQL || isJson ) {
107
110
return prettify ( text , filePath )
108
111
}
109
112
You can’t perform that action at this time.
0 commit comments