Skip to content

Commit

Permalink
Update prettier (#2499)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov authored Apr 2, 2020
1 parent c155ae0 commit a8f73db
Show file tree
Hide file tree
Showing 90 changed files with 11,147 additions and 3,929 deletions.
3 changes: 1 addition & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all",
"endOfLine": "lf"
"trailingComma": "all"
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Then, serve the result of a query against that type schema.
```js
var query = '{ hello }';

graphql(schema, query).then(result => {
graphql(schema, query).then((result) => {
// Prints
// {
// data: { hello: "world" }
Expand All @@ -90,7 +90,7 @@ it, reporting errors otherwise.
```js
var query = '{ BoyHowdy }';

graphql(schema, query).then(result => {
graphql(schema, query).then((result) => {
// Prints
// {
// errors: [
Expand Down
4 changes: 2 additions & 2 deletions docs/Guides-ConstructingTypes.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var fakeDatabase = {
};

var root = {
user: function({ id }) {
user: function ({ id }) {
return fakeDatabase[id];
},
};
Expand Down Expand Up @@ -98,7 +98,7 @@ var queryType = new graphql.GraphQLObjectType({
args: {
id: { type: graphql.GraphQLString },
},
resolve: function(_, { id }) {
resolve: function (_, { id }) {
return fakeDatabase[id];
},
},
Expand Down
2 changes: 1 addition & 1 deletion docs/Tutorial-Authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function loggingMiddleware(req, res, next) {
}

var root = {
ip: function(args, request) {
ip: function (args, request) {
return request.ip;
},
};
Expand Down
2 changes: 1 addition & 1 deletion docs/Tutorial-BasicTypes.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var root = {
return Math.random();
},
rollThreeDice: () => {
return [1, 2, 3].map(_ => 1 + Math.floor(Math.random() * 6));
return [1, 2, 3].map((_) => 1 + Math.floor(Math.random() * 6));
},
};

Expand Down
2 changes: 1 addition & 1 deletion docs/Tutorial-GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var root = {
};

// Run the GraphQL query '{ hello }' and print out the response
graphql(schema, '{ hello }', root).then(response => {
graphql(schema, '{ hello }', root).then((response) => {
console.log(response);
});
```
Expand Down
8 changes: 4 additions & 4 deletions docs/Tutorial-GraphQLClients.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ fetch('/graphql', {
},
body: JSON.stringify({ query: '{ hello }' }),
})
.then(r => r.json())
.then(data => console.log('data returned:', data));
.then((r) => r.json())
.then((data) => console.log('data returned:', data));
```

You should see the data returned, logged in the console:
Expand Down Expand Up @@ -76,8 +76,8 @@ fetch('/graphql', {
variables: { dice, sides },
}),
})
.then(r => r.json())
.then(data => console.log('data returned:', data));
.then((r) => r.json())
.then((data) => console.log('data returned:', data));
```

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.
Expand Down
18 changes: 8 additions & 10 deletions docs/Tutorial-Mutations.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ Both mutations and queries can be handled by root resolvers, so the root that im
```js
var fakeDatabase = {};
var root = {
setMessage: function({ message }) {
setMessage: function ({ message }) {
fakeDatabase.message = message;
return message;
},
getMessage: function() {
getMessage: function () {
return fakeDatabase.message;
},
};
Expand Down Expand Up @@ -112,22 +112,20 @@ class Message {
var fakeDatabase = {};

var root = {
getMessage: function({ id }) {
getMessage: function ({ id }) {
if (!fakeDatabase[id]) {
throw new Error('no message exists with id ' + id);
}
return new Message(id, fakeDatabase[id]);
},
createMessage: function({ input }) {
createMessage: function ({ input }) {
// Create a random id for our "database".
var id = require('crypto')
.randomBytes(10)
.toString('hex');
var id = require('crypto').randomBytes(10).toString('hex');

fakeDatabase[id] = input;
return new Message(id, input);
},
updateMessage: function({ id, input }) {
updateMessage: function ({ id, input }) {
if (!fakeDatabase[id]) {
throw new Error('no message exists with id ' + id);
}
Expand Down Expand Up @@ -188,8 +186,8 @@ fetch('/graphql', {
},
}),
})
.then(r => r.json())
.then(data => console.log('data returned:', data));
.then((r) => r.json())
.then((data) => console.log('data returned:', data));
```

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/).
4 changes: 2 additions & 2 deletions docs/Tutorial-ObjectTypes.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class RandomDie {
}

var root = {
getDie: function({ numSides }) {
getDie: function ({ numSides }) {
return new RandomDie(numSides || 6);
},
};
Expand Down Expand Up @@ -111,7 +111,7 @@ class RandomDie {

// The root provides the top-level API endpoints
var root = {
getDie: function({ numSides }) {
getDie: function ({ numSides }) {
return new RandomDie(numSides || 6);
},
};
Expand Down
10 changes: 5 additions & 5 deletions docs/Tutorial-PassingArguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ So far, our resolver functions took no arguments. When a resolver takes argument

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

```js
var root = {
rollDice: function({ numDice, numSides }) {
rollDice: function ({ numDice, numSides }) {
var output = [];
for (var i = 0; i < numDice; i++) {
output.push(1 + Math.floor(Math.random() * (numSides || 6)));
Expand Down Expand Up @@ -70,7 +70,7 @@ var schema = buildSchema(`

// The root provides a resolver function for each API endpoint
var root = {
rollDice: function({ numDice, numSides }) {
rollDice: function ({ numDice, numSides }) {
var output = [];
for (var i = 0; i < numDice; i++) {
output.push(1 + Math.floor(Math.random() * (numSides || 6)));
Expand Down Expand Up @@ -125,8 +125,8 @@ fetch('/graphql', {
variables: { dice, sides },
}),
})
.then(r => r.json())
.then(data => console.log('data returned:', data));
.then((r) => r.json())
.then((data) => console.log('data returned:', data));
```

Using `$dice` and `$sides` as variables in GraphQL means we don't have to worry about escaping on the client side.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"flow-bin": "0.120.1",
"mocha": "7.1.0",
"nyc": "15.0.0",
"prettier": "1.19.1",
"prettier": "2.0.2",
"typescript": "^3.8.3"
}
}
6 changes: 3 additions & 3 deletions resources/benchmark-fork.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ function sampleModule(modulePath) {
let message;
let error;

child.on('message', msg => (message = msg));
child.on('error', e => (error = e));
child.on('message', (msg) => (message = msg));
child.on('error', (e) => (error = e));
child.on('close', () => {
if (message) {
return resolve(message);
}
reject(error || new Error('Forked process closed without error'));
});
}).then(result => {
}).then((result) => {
global.gc();
return result;
});
Expand Down
6 changes: 3 additions & 3 deletions resources/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ function maxBy(array, fn) {

// Prepare all revisions and run benchmarks matching a pattern against them.
async function prepareAndRunBenchmarks(benchmarkPatterns, revisions) {
const environments = revisions.map(revision => ({
const environments = revisions.map((revision) => ({
revision,
distPath: prepareRevision(revision),
}));
Expand Down Expand Up @@ -269,8 +269,8 @@ async function prepareAndRunBenchmarks(benchmarkPatterns, revisions) {
function matchBenchmarks(patterns) {
let benchmarks = findFiles(LOCAL_DIR('src'), '*/__tests__/*-benchmark.js');
if (patterns.length > 0) {
benchmarks = benchmarks.filter(benchmark =>
patterns.some(pattern => path.join('src', benchmark).includes(pattern)),
benchmarks = benchmarks.filter((benchmark) =>
patterns.some((pattern) => path.join('src', benchmark).includes(pattern)),
);
}

Expand Down
4 changes: 2 additions & 2 deletions resources/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ function showStats() {
stats.sort((a, b) => b[1] - a[1]);
stats = stats.map(([type, size]) => [type, (size / 1024).toFixed(2) + ' KB']);

const typeMaxLength = Math.max(...stats.map(x => x[0].length));
const sizeMaxLength = Math.max(...stats.map(x => x[1].length));
const typeMaxLength = Math.max(...stats.map((x) => x[0].length));
const sizeMaxLength = Math.max(...stats.map((x) => x[1].length));
for (const [type, size] of stats) {
console.log(
type.padStart(typeMaxLength) + ' | ' + size.padStart(sizeMaxLength),
Expand Down
10 changes: 5 additions & 5 deletions resources/check-cover.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ const {

rmdirRecursive('./coverage/flow');
getFullCoverage()
.then(fullCoverage =>
.then((fullCoverage) =>
writeFile(
'./coverage/flow/full-coverage.json',
JSON.stringify(fullCoverage),
),
)
.catch(error => {
.catch((error) => {
console.error(error.stack);
process.exit(1);
});
Expand All @@ -34,10 +34,10 @@ async function getFullCoverage() {

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

await Promise.all(files.map(getCoverage)).then(coverages => {
await Promise.all(files.map(getCoverage)).then((coverages) => {
for (const coverage of coverages) {
fullCoverage[coverage.path] = coverage;
}
Expand Down
2 changes: 1 addition & 1 deletion resources/eslint-rules/no-dir-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
const fs = require('fs');
const path = require('path');

module.exports = function(context) {
module.exports = function (context) {
return {
ImportDeclaration: checkImporPath,
ExportNamedDeclaration: checkImporPath,
Expand Down
22 changes: 11 additions & 11 deletions resources/gen-changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ if (repoURLMatch == null) {
const [, githubOrg, githubRepo] = repoURLMatch;

getChangeLog()
.then(changelog => process.stdout.write(changelog))
.catch(error => console.error(error));
.then((changelog) => process.stdout.write(changelog))
.catch((error) => console.error(error));

function getChangeLog() {
const { version } = packageJSON;
Expand All @@ -76,8 +76,8 @@ function getChangeLog() {

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

function genChangeLog(tag, date, allPRs) {
Expand All @@ -86,8 +86,8 @@ function genChangeLog(tag, date, allPRs) {

for (const pr of allPRs) {
const labels = pr.labels.nodes
.map(label => label.name)
.filter(label => label.startsWith('PR: '));
.map((label) => label.name)
.filter((label) => label.startsWith('PR: '));

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

req.on('response', res => {
req.on('response', (res) => {
let responseBody = '';

res.setEncoding('utf8');
res.on('data', d => (responseBody += d));
res.on('error', error => resultCB(error));
res.on('data', (d) => (responseBody += d));
res.on('error', (error) => resultCB(error));

res.on('end', () => {
if (res.statusCode !== 200) {
Expand Down Expand Up @@ -187,7 +187,7 @@ function graphqlRequestImpl(query, variables, cb) {
});
});

req.on('error', error => resultCB(error));
req.on('error', (error) => resultCB(error));
req.write(JSON.stringify({ query, variables }));
req.end();
}
Expand Down Expand Up @@ -271,7 +271,7 @@ function commitsInfoToPRs(commits) {
const prs = {};
for (const commit of commits) {
const associatedPRs = commit.associatedPullRequests.nodes.filter(
pr => pr.repository.nameWithOwner === `${githubOrg}/${githubRepo}`,
(pr) => pr.repository.nameWithOwner === `${githubOrg}/${githubRepo}`,
);
if (associatedPRs.length === 0) {
const match = / \(#([0-9]+)\)$/m.exec(commit.message);
Expand Down
7 changes: 2 additions & 5 deletions resources/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ function removeTrailingNewLine(str) {
return str;
}

return str
.split('\n')
.slice(0, -1)
.join('\n');
return str.split('\n').slice(0, -1).join('\n');
}

function mkdirRecursive(dirPath) {
Expand Down Expand Up @@ -68,7 +65,7 @@ function readdirRecursive(dirPath, opts = {}) {
if (ignoreDir && ignoreDir.test(name)) {
continue;
}
const list = readdirRecursive(path.join(dirPath, name), opts).map(f =>
const list = readdirRecursive(path.join(dirPath, name), opts).map((f) =>
path.join(name, f),
);
result.push(...list);
Expand Down
Loading

0 comments on commit a8f73db

Please sign in to comment.