Skip to content

Commit

Permalink
chore(lint): add semicolons (via prettier) (#807)
Browse files Browse the repository at this point in the history
This diff only contains semicolon changes (except for a few places where adding a semicolon caused the line to wrap, and thus whitespace trailing commas were added also).

You can confirm this with `git diff -w --word-diff-regex='[^[:space:]]'` and `git diff -w --word-diff-regex='[^;]'` across the relevant git range
  • Loading branch information
benjie committed Jul 21, 2018
1 parent 2e16cf0 commit 473840a
Show file tree
Hide file tree
Showing 30 changed files with 1,502 additions and 1,485 deletions.
2 changes: 1 addition & 1 deletion prettier.config.js
@@ -1,6 +1,6 @@
module.exports = {
printWidth: 100,
semi: false,
semi: true,
singleQuote: true,
trailingComma: "all",
}
16 changes: 8 additions & 8 deletions src/__tests__/utils/createTestInParallel.ts
Expand Up @@ -11,24 +11,24 @@ export default function createTestInParallel(): (
) => void {
// All of the test functions. We collect them in a single array so that we can
// call them all at once.
const testFns: Array<() => void | Promise<void>> = []
const testFns: Array<() => void | Promise<void>> = [];

// The promised results of calling all of our test functions. The single serial
// tests will await these values.
let testResults: Array<Promise<void>> | undefined
let testResults: Array<Promise<void>> | undefined;

return (name: string, fn: () => void | Promise<void>): void => {
// Add the test function and record its position.
const index = testFns.length
testFns.push(fn)
const index = testFns.length;
testFns.push(fn);

test(name, async () => {
// If the tests have not yet been run then run all of our tests.
if (!testResults) {
testResults = testFns.map(testFn => Promise.resolve(testFn()))
testResults = testFns.map(testFn => Promise.resolve(testFn()));
}
// Await the result.
await testResults[index]
})
}
await testResults[index];
});
};
}
14 changes: 7 additions & 7 deletions src/__tests__/utils/kitchenSinkSchemaSql.ts
@@ -1,11 +1,11 @@
import { readFile } from 'fs'
import * as minify from 'pg-minify'
import { readFile } from 'fs';
import * as minify from 'pg-minify';

const kitchenSinkSchemaSql = new Promise<string>((resolve, reject) => {
readFile('examples/kitchen-sink/schema.sql', (error, data) => {
if (error) reject(error)
else resolve(minify(data.toString().replace(/begin;|commit;/g, '')))
})
})
if (error) reject(error);
else resolve(minify(data.toString().replace(/begin;|commit;/g, '')));
});
});

export default kitchenSinkSchemaSql
export default kitchenSinkSchemaSql;
10 changes: 5 additions & 5 deletions src/__tests__/utils/pgPool.ts
@@ -1,12 +1,12 @@
import { Pool } from 'pg'
import { parse as parsePgConnectionString } from 'pg-connection-string'
import { Pool } from 'pg';
import { parse as parsePgConnectionString } from 'pg-connection-string';

const pgUrl = process.env.TEST_PG_URL || 'postgres://localhost:5432/postgraphile_test'
const pgUrl = process.env.TEST_PG_URL || 'postgres://localhost:5432/postgraphile_test';

const pgPool = new Pool({
...parsePgConnectionString(pgUrl),
max: 15,
idleTimeoutMillis: 500,
})
});

export default pgPool
export default pgPool;
30 changes: 15 additions & 15 deletions src/__tests__/utils/printSchemaOrdered.js
@@ -1,37 +1,37 @@
import { parse, buildASTSchema } from 'graphql'
import { printSchema } from 'graphql/utilities'
import { parse, buildASTSchema } from 'graphql';
import { printSchema } from 'graphql/utilities';

export default function printSchemaOrdered(originalSchema) {
// Clone schema so we don't damage anything
const schema = buildASTSchema(parse(printSchema(originalSchema)))
const schema = buildASTSchema(parse(printSchema(originalSchema)));

const typeMap = schema.getTypeMap()
const typeMap = schema.getTypeMap();
Object.keys(typeMap).forEach(name => {
const gqlType = typeMap[name]
const gqlType = typeMap[name];

// Object?
if (gqlType.getFields) {
const fields = gqlType.getFields()
const keys = Object.keys(fields).sort()
const fields = gqlType.getFields();
const keys = Object.keys(fields).sort();
keys.forEach(key => {
const value = fields[key]
const value = fields[key];

// Move the key to the end of the object
delete fields[key]
fields[key] = value
delete fields[key];
fields[key] = value;

// Sort args
if (value.args) {
value.args.sort((a, b) => a.name.localeCompare(b.name))
value.args.sort((a, b) => a.name.localeCompare(b.name));
}
})
});
}

// Enum?
if (gqlType.getValues) {
gqlType.getValues().sort((a, b) => a.name.localeCompare(b.name))
gqlType.getValues().sort((a, b) => a.name.localeCompare(b.name));
}
})
});

return printSchema(schema)
return printSchema(schema);
}
38 changes: 19 additions & 19 deletions src/__tests__/utils/withPgClient.ts
@@ -1,6 +1,6 @@
import { PoolClient } from 'pg'
import pgPool from './pgPool'
import kitchenSinkSchemaSql from './kitchenSinkSchemaSql'
import { PoolClient } from 'pg';
import pgPool from './pgPool';
import kitchenSinkSchemaSql from './kitchenSinkSchemaSql';

/**
* Takes a function implementation of a test, and provides it a Postgres
Expand All @@ -11,47 +11,47 @@ export default function withPgClient<T>(
fn: (client: PoolClient) => T | Promise<T>,
): () => Promise<T> {
return async (): Promise<T> => {
let result: T | undefined
let result: T | undefined;

// Connect a client from our pool and begin a transaction.
const client = await pgPool.connect()
const client = await pgPool.connect();

// There鈥檚 some wierd behavior with the `pg` module here where an error
// is resolved correctly.
//
// @see https://github.com/brianc/node-postgres/issues/1142
if ((client as object)['errno']) throw client
if ((client as object)['errno']) throw client;

await client.query('begin')
await client.query("set local timezone to '+04:00'")
await client.query('begin');
await client.query("set local timezone to '+04:00'");

// Run our kichen sink schema Sql, if there is an error we should report it
try {
await client.query(await kitchenSinkSchemaSql)
await client.query(await kitchenSinkSchemaSql);
} catch (error) {
// Release the client if an error was thrown.
await client.query('rollback')
client.release()
await client.query('rollback');
client.release();
// Log the error for debugging purposes.
console.error(error.stack || error) // tslint:disable-line no-console
throw error
console.error(error.stack || error); // tslint:disable-line no-console
throw error;
}

// Mock the query function.
client.query = jest.fn(client.query)
client.query = jest.fn(client.query);

// Try to run our test, if it fails we still want to cleanup the client.
try {
result = await fn(client)
result = await fn(client);
} finally {
// Always rollback our changes and release the client, even if the test
// fails.
await client.query('rollback')
client.release()
await client.query('rollback');
client.release();
}

// We will always define our result in the above block. It appears that
// TypeScript cannot detect that so we need to tell it with the bang.
return result!
}
return result!;
};
}
8 changes: 4 additions & 4 deletions src/index.ts
Expand Up @@ -3,10 +3,10 @@ import {
createPostGraphileSchema,
watchPostGraphileSchema,
withPostGraphileContext,
} from './postgraphile'
import { makePluginHook, PostGraphilePlugin } from './postgraphile/pluginHook'
} from './postgraphile';
import { makePluginHook, PostGraphilePlugin } from './postgraphile/pluginHook';

export default postgraphile
export default postgraphile;

export {
postgraphile,
Expand All @@ -20,4 +20,4 @@ export {
createPostGraphileSchema as createPostGraphQLSchema,
watchPostGraphileSchema as watchPostGraphQLSchema,
withPostGraphileContext as withPostGraphQLContext,
}
};

0 comments on commit 473840a

Please sign in to comment.