Skip to content

Commit cfde0cc

Browse files
committed
review changes
1 parent 69edf3b commit cfde0cc

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

src/language/__tests__/printer-test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,19 @@ describe('Printer: Query document', () => {
121121
{
122122
trip(
123123
obj: {
124-
wheelchair: false,
125-
smallObj: { a: 1 },
124+
wheelchair: false
125+
smallObj: { a: 1 }
126126
largeObj: {
127-
wheelchair: false,
128-
smallObj: { a: 1 },
129-
arriveBy: false,
130-
includePlannedCancellations: true,
131-
transitDistanceReluctance: 2000,
127+
wheelchair: false
128+
smallObj: { a: 1 }
129+
arriveBy: false
130+
includePlannedCancellations: true
131+
transitDistanceReluctance: 2000
132132
anotherLongFieldName: "Lots and lots and lots and lots of text"
133-
},
134-
arriveBy: false,
135-
includePlannedCancellations: true,
136-
transitDistanceReluctance: 2000,
133+
}
134+
arriveBy: false
135+
includePlannedCancellations: true
136+
transitDistanceReluctance: 2000
137137
anotherLongFieldName: "Lots and lots and lots and lots of text"
138138
}
139139
) {
@@ -154,10 +154,10 @@ describe('Printer: Query document', () => {
154154
{
155155
trip(
156156
list: [
157-
["small array", "small", "small"],
157+
["small array", "small", "small"]
158158
[
159-
"Lots and lots and lots and lots of text",
160-
"Lots and lots and lots and lots of text",
159+
"Lots and lots and lots and lots of text"
160+
"Lots and lots and lots and lots of text"
161161
"Lots and lots and lots and lots of text"
162162
]
163163
]

src/language/printer.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,18 @@ const printDocASTReducer: ASTReducer<string> = {
150150
EnumValue: { leave: ({ value }) => value },
151151
ListValue: {
152152
leave: ({ values }) => {
153-
if (values.reduce((t, v) => t + v.length + 2, 0) > MAX_LINE_LENGTH) {
154-
return '[\n' + indent(join(values, ',\n')) + '\n]';
153+
const valuesLine = '[' + join(values, ', ') + ']';
154+
155+
if (valuesLine.length > MAX_LINE_LENGTH) {
156+
return '[\n' + indent(join(values, '\n')) + '\n]';
155157
}
156-
return '[' + join(values, ', ') + ']';
158+
return valuesLine;
157159
},
158160
},
159161
ObjectValue: {
160162
leave: ({ fields }) => {
161-
if (fields.reduce((t, f) => t + f.length + 2, 0) > MAX_LINE_LENGTH) {
162-
return '{\n' + indent(join(fields, ',\n')) + '\n}';
163-
}
164-
return '{ ' + join(fields, ', ') + ' }';
163+
const fieldsLine = '{ ' + join(fields, ', ') + ' }';
164+
return fieldsLine.length > MAX_LINE_LENGTH ? block(fields) : fieldsLine;
165165
},
166166
},
167167
ObjectField: { leave: ({ name, value }) => name + ': ' + value },

0 commit comments

Comments
 (0)