Skip to content

Commit a8f73db

Browse files
Update prettier (#2499)
1 parent c155ae0 commit a8f73db

File tree

90 files changed

+11147
-3929
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+11147
-3929
lines changed

.prettierrc

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
22
"singleQuote": true,
3-
"trailingComma": "all",
4-
"endOfLine": "lf"
3+
"trailingComma": "all"
54
}

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Then, serve the result of a query against that type schema.
7474
```js
7575
var query = '{ hello }';
7676

77-
graphql(schema, query).then(result => {
77+
graphql(schema, query).then((result) => {
7878
// Prints
7979
// {
8080
// data: { hello: "world" }
@@ -90,7 +90,7 @@ it, reporting errors otherwise.
9090
```js
9191
var query = '{ BoyHowdy }';
9292

93-
graphql(schema, query).then(result => {
93+
graphql(schema, query).then((result) => {
9494
// Prints
9595
// {
9696
// errors: [

docs/Guides-ConstructingTypes.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ var fakeDatabase = {
4141
};
4242

4343
var root = {
44-
user: function({ id }) {
44+
user: function ({ id }) {
4545
return fakeDatabase[id];
4646
},
4747
};
@@ -98,7 +98,7 @@ var queryType = new graphql.GraphQLObjectType({
9898
args: {
9999
id: { type: graphql.GraphQLString },
100100
},
101-
resolve: function(_, { id }) {
101+
resolve: function (_, { id }) {
102102
return fakeDatabase[id];
103103
},
104104
},

docs/Tutorial-Authentication.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function loggingMiddleware(req, res, next) {
3030
}
3131

3232
var root = {
33-
ip: function(args, request) {
33+
ip: function (args, request) {
3434
return request.ip;
3535
},
3636
};

docs/Tutorial-BasicTypes.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var root = {
3939
return Math.random();
4040
},
4141
rollThreeDice: () => {
42-
return [1, 2, 3].map(_ => 1 + Math.floor(Math.random() * 6));
42+
return [1, 2, 3].map((_) => 1 + Math.floor(Math.random() * 6));
4343
},
4444
};
4545

docs/Tutorial-GettingStarted.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var root = {
4040
};
4141

4242
// Run the GraphQL query '{ hello }' and print out the response
43-
graphql(schema, '{ hello }', root).then(response => {
43+
graphql(schema, '{ hello }', root).then((response) => {
4444
console.log(response);
4545
});
4646
```

docs/Tutorial-GraphQLClients.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ fetch('/graphql', {
3636
},
3737
body: JSON.stringify({ query: '{ hello }' }),
3838
})
39-
.then(r => r.json())
40-
.then(data => console.log('data returned:', data));
39+
.then((r) => r.json())
40+
.then((data) => console.log('data returned:', data));
4141
```
4242

4343
You should see the data returned, logged in the console:
@@ -76,8 +76,8 @@ fetch('/graphql', {
7676
variables: { dice, sides },
7777
}),
7878
})
79-
.then(r => r.json())
80-
.then(data => console.log('data returned:', data));
79+
.then((r) => r.json())
80+
.then((data) => console.log('data returned:', data));
8181
```
8282

8383
Using this syntax for variables is a good idea because it automatically prevents bugs due to escaping, and it makes it easier to monitor your server.

docs/Tutorial-Mutations.md

+8-10
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ Both mutations and queries can be handled by root resolvers, so the root that im
2727
```js
2828
var fakeDatabase = {};
2929
var root = {
30-
setMessage: function({ message }) {
30+
setMessage: function ({ message }) {
3131
fakeDatabase.message = message;
3232
return message;
3333
},
34-
getMessage: function() {
34+
getMessage: function () {
3535
return fakeDatabase.message;
3636
},
3737
};
@@ -112,22 +112,20 @@ class Message {
112112
var fakeDatabase = {};
113113

114114
var root = {
115-
getMessage: function({ id }) {
115+
getMessage: function ({ id }) {
116116
if (!fakeDatabase[id]) {
117117
throw new Error('no message exists with id ' + id);
118118
}
119119
return new Message(id, fakeDatabase[id]);
120120
},
121-
createMessage: function({ input }) {
121+
createMessage: function ({ input }) {
122122
// Create a random id for our "database".
123-
var id = require('crypto')
124-
.randomBytes(10)
125-
.toString('hex');
123+
var id = require('crypto').randomBytes(10).toString('hex');
126124

127125
fakeDatabase[id] = input;
128126
return new Message(id, input);
129127
},
130-
updateMessage: function({ id, input }) {
128+
updateMessage: function ({ id, input }) {
131129
if (!fakeDatabase[id]) {
132130
throw new Error('no message exists with id ' + id);
133131
}
@@ -188,8 +186,8 @@ fetch('/graphql', {
188186
},
189187
}),
190188
})
191-
.then(r => r.json())
192-
.then(data => console.log('data returned:', data));
189+
.then((r) => r.json())
190+
.then((data) => console.log('data returned:', data));
193191
```
194192

195193
One particular type of mutation is operations that change users, like signing up a new user. While you can implement this using GraphQL mutations, you can reuse many existing libraries if you learn about [GraphQL with authentication and Express middleware](/graphql-js/authentication-and-express-middleware/).

docs/Tutorial-ObjectTypes.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class RandomDie {
5050
}
5151

5252
var root = {
53-
getDie: function({ numSides }) {
53+
getDie: function ({ numSides }) {
5454
return new RandomDie(numSides || 6);
5555
},
5656
};
@@ -111,7 +111,7 @@ class RandomDie {
111111

112112
// The root provides the top-level API endpoints
113113
var root = {
114-
getDie: function({ numSides }) {
114+
getDie: function ({ numSides }) {
115115
return new RandomDie(numSides || 6);
116116
},
117117
};

docs/Tutorial-PassingArguments.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ So far, our resolver functions took no arguments. When a resolver takes argument
2828

2929
```js
3030
var root = {
31-
rollDice: function(args) {
31+
rollDice: function (args) {
3232
var output = [];
3333
for (var i = 0; i < args.numDice; i++) {
3434
output.push(1 + Math.floor(Math.random() * (args.numSides || 6)));
@@ -42,7 +42,7 @@ It's convenient to use [ES6 destructuring assignment](https://developer.mozilla.
4242

4343
```js
4444
var root = {
45-
rollDice: function({ numDice, numSides }) {
45+
rollDice: function ({ numDice, numSides }) {
4646
var output = [];
4747
for (var i = 0; i < numDice; i++) {
4848
output.push(1 + Math.floor(Math.random() * (numSides || 6)));
@@ -70,7 +70,7 @@ var schema = buildSchema(`
7070

7171
// The root provides a resolver function for each API endpoint
7272
var root = {
73-
rollDice: function({ numDice, numSides }) {
73+
rollDice: function ({ numDice, numSides }) {
7474
var output = [];
7575
for (var i = 0; i < numDice; i++) {
7676
output.push(1 + Math.floor(Math.random() * (numSides || 6)));
@@ -125,8 +125,8 @@ fetch('/graphql', {
125125
variables: { dice, sides },
126126
}),
127127
})
128-
.then(r => r.json())
129-
.then(data => console.log('data returned:', data));
128+
.then((r) => r.json())
129+
.then((data) => console.log('data returned:', data));
130130
```
131131

132132
Using `$dice` and `$sides` as variables in GraphQL means we don't have to worry about escaping on the client side.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"flow-bin": "0.120.1",
6262
"mocha": "7.1.0",
6363
"nyc": "15.0.0",
64-
"prettier": "1.19.1",
64+
"prettier": "2.0.2",
6565
"typescript": "^3.8.3"
6666
}
6767
}

resources/benchmark-fork.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ function sampleModule(modulePath) {
4343
let message;
4444
let error;
4545

46-
child.on('message', msg => (message = msg));
47-
child.on('error', e => (error = e));
46+
child.on('message', (msg) => (message = msg));
47+
child.on('error', (e) => (error = e));
4848
child.on('close', () => {
4949
if (message) {
5050
return resolve(message);
5151
}
5252
reject(error || new Error('Forked process closed without error'));
5353
});
54-
}).then(result => {
54+
}).then((result) => {
5555
global.gc();
5656
return result;
5757
});

resources/benchmark.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ function maxBy(array, fn) {
229229

230230
// Prepare all revisions and run benchmarks matching a pattern against them.
231231
async function prepareAndRunBenchmarks(benchmarkPatterns, revisions) {
232-
const environments = revisions.map(revision => ({
232+
const environments = revisions.map((revision) => ({
233233
revision,
234234
distPath: prepareRevision(revision),
235235
}));
@@ -269,8 +269,8 @@ async function prepareAndRunBenchmarks(benchmarkPatterns, revisions) {
269269
function matchBenchmarks(patterns) {
270270
let benchmarks = findFiles(LOCAL_DIR('src'), '*/__tests__/*-benchmark.js');
271271
if (patterns.length > 0) {
272-
benchmarks = benchmarks.filter(benchmark =>
273-
patterns.some(pattern => path.join('src', benchmark).includes(pattern)),
272+
benchmarks = benchmarks.filter((benchmark) =>
273+
patterns.some((pattern) => path.join('src', benchmark).includes(pattern)),
274274
);
275275
}
276276

resources/build.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ function showStats() {
7777
stats.sort((a, b) => b[1] - a[1]);
7878
stats = stats.map(([type, size]) => [type, (size / 1024).toFixed(2) + ' KB']);
7979

80-
const typeMaxLength = Math.max(...stats.map(x => x[0].length));
81-
const sizeMaxLength = Math.max(...stats.map(x => x[1].length));
80+
const typeMaxLength = Math.max(...stats.map((x) => x[0].length));
81+
const sizeMaxLength = Math.max(...stats.map((x) => x[1].length));
8282
for (const [type, size] of stats) {
8383
console.log(
8484
type.padStart(typeMaxLength) + ' | ' + size.padStart(sizeMaxLength),

resources/check-cover.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ const {
1414

1515
rmdirRecursive('./coverage/flow');
1616
getFullCoverage()
17-
.then(fullCoverage =>
17+
.then((fullCoverage) =>
1818
writeFile(
1919
'./coverage/flow/full-coverage.json',
2020
JSON.stringify(fullCoverage),
2121
),
2222
)
23-
.catch(error => {
23+
.catch((error) => {
2424
console.error(error.stack);
2525
process.exit(1);
2626
});
@@ -34,10 +34,10 @@ async function getFullCoverage() {
3434

3535
// TODO: measure coverage for all files. ATM missing types for chai & mocha
3636
const files = readdirRecursive('./src', { ignoreDir: /^__.*__$/ })
37-
.filter(filepath => filepath.endsWith('.js'))
38-
.map(filepath => path.join('src/', filepath));
37+
.filter((filepath) => filepath.endsWith('.js'))
38+
.map((filepath) => path.join('src/', filepath));
3939

40-
await Promise.all(files.map(getCoverage)).then(coverages => {
40+
await Promise.all(files.map(getCoverage)).then((coverages) => {
4141
for (const coverage of coverages) {
4242
fullCoverage[coverage.path] = coverage;
4343
}

resources/eslint-rules/no-dir-import.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
const fs = require('fs');
66
const path = require('path');
77

8-
module.exports = function(context) {
8+
module.exports = function (context) {
99
return {
1010
ImportDeclaration: checkImporPath,
1111
ExportNamedDeclaration: checkImporPath,

resources/gen-changelog.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ if (repoURLMatch == null) {
5959
const [, githubOrg, githubRepo] = repoURLMatch;
6060

6161
getChangeLog()
62-
.then(changelog => process.stdout.write(changelog))
63-
.catch(error => console.error(error));
62+
.then((changelog) => process.stdout.write(changelog))
63+
.catch((error) => console.error(error));
6464

6565
function getChangeLog() {
6666
const { version } = packageJSON;
@@ -76,8 +76,8 @@ function getChangeLog() {
7676

7777
const date = exec('git log -1 --format=%cd --date=short');
7878
return getCommitsInfo(commitsList.split('\n'))
79-
.then(commitsInfo => getPRsInfo(commitsInfoToPRs(commitsInfo)))
80-
.then(prsInfo => genChangeLog(tag, date, prsInfo));
79+
.then((commitsInfo) => getPRsInfo(commitsInfoToPRs(commitsInfo)))
80+
.then((prsInfo) => genChangeLog(tag, date, prsInfo));
8181
}
8282

8383
function genChangeLog(tag, date, allPRs) {
@@ -86,8 +86,8 @@ function genChangeLog(tag, date, allPRs) {
8686

8787
for (const pr of allPRs) {
8888
const labels = pr.labels.nodes
89-
.map(label => label.name)
90-
.filter(label => label.startsWith('PR: '));
89+
.map((label) => label.name)
90+
.filter((label) => label.startsWith('PR: '));
9191

9292
if (labels.length === 0) {
9393
throw new Error(`PR is missing label. See ${pr.url}`);
@@ -153,12 +153,12 @@ function graphqlRequestImpl(query, variables, cb) {
153153
},
154154
});
155155

156-
req.on('response', res => {
156+
req.on('response', (res) => {
157157
let responseBody = '';
158158

159159
res.setEncoding('utf8');
160-
res.on('data', d => (responseBody += d));
161-
res.on('error', error => resultCB(error));
160+
res.on('data', (d) => (responseBody += d));
161+
res.on('error', (error) => resultCB(error));
162162

163163
res.on('end', () => {
164164
if (res.statusCode !== 200) {
@@ -187,7 +187,7 @@ function graphqlRequestImpl(query, variables, cb) {
187187
});
188188
});
189189

190-
req.on('error', error => resultCB(error));
190+
req.on('error', (error) => resultCB(error));
191191
req.write(JSON.stringify({ query, variables }));
192192
req.end();
193193
}
@@ -271,7 +271,7 @@ function commitsInfoToPRs(commits) {
271271
const prs = {};
272272
for (const commit of commits) {
273273
const associatedPRs = commit.associatedPullRequests.nodes.filter(
274-
pr => pr.repository.nameWithOwner === `${githubOrg}/${githubRepo}`,
274+
(pr) => pr.repository.nameWithOwner === `${githubOrg}/${githubRepo}`,
275275
);
276276
if (associatedPRs.length === 0) {
277277
const match = / \(#([0-9]+)\)$/m.exec(commit.message);

resources/utils.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ function removeTrailingNewLine(str) {
3131
return str;
3232
}
3333

34-
return str
35-
.split('\n')
36-
.slice(0, -1)
37-
.join('\n');
34+
return str.split('\n').slice(0, -1).join('\n');
3835
}
3936

4037
function mkdirRecursive(dirPath) {
@@ -68,7 +65,7 @@ function readdirRecursive(dirPath, opts = {}) {
6865
if (ignoreDir && ignoreDir.test(name)) {
6966
continue;
7067
}
71-
const list = readdirRecursive(path.join(dirPath, name), opts).map(f =>
68+
const list = readdirRecursive(path.join(dirPath, name), opts).map((f) =>
7269
path.join(name, f),
7370
);
7471
result.push(...list);

0 commit comments

Comments
 (0)