Skip to content

Commit

Permalink
fix: align back to the google style guide (#440)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith committed Feb 4, 2020
1 parent 06efa84 commit 8bd78c4
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 102 deletions.
1 change: 1 addition & 0 deletions .eslintignore
@@ -1,2 +1,3 @@
build/
test/fixtures/
template/
4 changes: 0 additions & 4 deletions .prettierrc.js

This file was deleted.

5 changes: 5 additions & 0 deletions .prettierrc.json
@@ -0,0 +1,5 @@
{
"bracketSpacing": false,
"singleQuote": true,
"trailingComma": "es5"
}
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -11,7 +11,7 @@
"CHANGELOG.md",
"build/src",
"build/template",
".prettierrc.js",
".prettierrc.json",
"tsconfig-google.json",
"tsconfig.json",
".eslintrc.json"
Expand Down
4 changes: 2 additions & 2 deletions src/clean.ts
Expand Up @@ -16,8 +16,8 @@
import chalk = require('chalk');
import * as ts from 'typescript';

import { Options } from './cli';
import { getTSConfig, rimrafp } from './util';
import {Options} from './cli';
import {getTSConfig, rimrafp} from './util';

interface TSConfig {
compilerOptions: ts.CompilerOptions;
Expand Down
18 changes: 9 additions & 9 deletions src/cli.ts
Expand Up @@ -19,9 +19,9 @@
import * as path from 'path';
import * as meow from 'meow';
import * as updateNotifier from 'update-notifier';
import { init } from './init';
import { clean } from './clean';
import { isYarnUsed } from './util';
import {init} from './init';
import {clean} from './clean';
import {isYarnUsed} from './util';
import * as execa from 'execa';

// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand Down Expand Up @@ -76,11 +76,11 @@ const cli = meow({
$ gts fix src/file1.ts src/file2.ts
$ gts clean`,
flags: {
help: { type: 'boolean' },
yes: { type: 'boolean', alias: 'y' },
no: { type: 'boolean', alias: 'n' },
'dry-run': { type: 'boolean' },
yarn: { type: 'boolean' },
help: {type: 'boolean'},
yes: {type: 'boolean', alias: 'y'},
no: {type: 'boolean', alias: 'n'},
'dry-run': {type: 'boolean'},
yarn: {type: 'boolean'},
},
});

Expand Down Expand Up @@ -149,7 +149,7 @@ async function run(verb: string, files: string[]): Promise<boolean> {
}
}

updateNotifier({ pkg: packageJson }).notify();
updateNotifier({pkg: packageJson}).notify();

if (cli.input.length < 1) {
usage();
Expand Down
17 changes: 8 additions & 9 deletions src/init.ts
Expand Up @@ -17,7 +17,7 @@ import * as cp from 'child_process';
import * as fs from 'fs';
import * as inquirer from 'inquirer';
import * as path from 'path';
import { ncp } from 'ncp';
import {ncp} from 'ncp';
import * as util from 'util';

import {
Expand All @@ -29,8 +29,8 @@ import {
DefaultPackage,
} from './util';

import { Options } from './cli';
import { PackageJson } from '@npm/types';
import {Options} from './cli';
import {PackageJson} from '@npm/types';
import chalk = require('chalk');

// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand All @@ -47,7 +47,7 @@ const DEFAULT_PACKAGE_JSON: PackageJson = {
files: ['build/src'],
license: 'Apache-2.0',
keywords: [],
scripts: { test: 'echo "Error: no test specified" && exit 1' },
scripts: {test: 'echo "Error: no test specified" && exit 1'},
};

async function query(
Expand Down Expand Up @@ -158,7 +158,6 @@ export async function addDependencies(
}

function formatJson(object: {}) {
// TODO: preserve the indent from the input file.
const json = JSON.stringify(object, null, ' ');
return `${json}\n`;
}
Expand Down Expand Up @@ -231,18 +230,18 @@ async function generateESLintConfig(options: Options): Promise<void> {
async function generateTsConfig(options: Options): Promise<void> {
const config = formatJson({
extends: './node_modules/gts/tsconfig-google.json',
compilerOptions: { rootDir: '.', outDir: 'build' },
compilerOptions: {rootDir: '.', outDir: 'build'},
include: ['src/**/*.ts', 'test/**/*.ts'],
});
return generateConfigFile(options, './tsconfig.json', config);
}

async function generatePrettierConfig(options: Options): Promise<void> {
const style = await read(
path.join(__dirname, '../../.prettierrc.js'),
path.join(__dirname, '../../.prettierrc.json'),
'utf8'
);
return generateConfigFile(options, './.prettierrc.js', style);
return generateConfigFile(options, './.prettierrc.json', style);
}

export async function installDefaultTemplate(
Expand Down Expand Up @@ -321,7 +320,7 @@ export async function init(options: Options): Promise<boolean> {
cp.spawnSync(
getPkgManagerCommand(options.yarn),
['install', '--ignore-scripts'],
{ stdio: 'inherit' }
{stdio: 'inherit'}
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/util.ts
Expand Up @@ -17,7 +17,7 @@
import * as fs from 'fs';
import * as path from 'path';
import * as rimraf from 'rimraf';
import { promisify } from 'util';
import {promisify} from 'util';
import * as ncp from 'ncp';
import * as writeFileAtomic from 'write-file-atomic';

Expand All @@ -37,7 +37,7 @@ export interface DefaultPackage extends Bag<string> {
}

export async function readJsonp(jsonPath: string) {
const contents = await readFilep(jsonPath, { encoding: 'utf8' });
const contents = await readFilep(jsonPath, {encoding: 'utf8'});
return JSON.parse(contents);
}

Expand Down Expand Up @@ -101,7 +101,7 @@ async function getBase(
* @param inherited is then loaded and overwrites base
*/
function combineTSConfig(base: ConfigFile, inherited: ConfigFile): ConfigFile {
const result: ConfigFile = { compilerOptions: {} };
const result: ConfigFile = {compilerOptions: {}};

Object.assign(result, base, inherited);
Object.assign(
Expand Down
14 changes: 7 additions & 7 deletions test/kitchen.ts
Expand Up @@ -2,16 +2,16 @@ import chalk = require('chalk');
import * as cp from 'child_process';
import * as fs from 'fs-extra';
import * as tmp from 'tmp';
import { assert } from 'chai';
import {assert} from 'chai';
import * as path from 'path';
import { describe, it, before, after } from 'mocha';
import {describe, it, before, after} from 'mocha';

import spawn = require('cross-spawn');
import execa = require('execa');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const pkg = require('../../package.json');
const keep = !!process.env.GTS_KEEP_TEMPDIRS;
const stagingDir = tmp.dirSync({ keep, unsafeCleanup: true });
const stagingDir = tmp.dirSync({keep, unsafeCleanup: true});
const stagingPath = stagingDir.name;
const execOpts = {
cwd: `${stagingPath}${path.sep}kitchen`,
Expand Down Expand Up @@ -60,7 +60,7 @@ describe('🚰 kitchen sink', () => {
// Ensure config files got generated.
fs.accessSync(path.join(kitchenPath, 'tsconfig.json'));
fs.accessSync(path.join(kitchenPath, '.eslintrc.json'));
fs.accessSync(path.join(kitchenPath, '.prettierrc.js'));
fs.accessSync(path.join(kitchenPath, '.prettierrc.json'));

// Compilation shouldn't have happened. Hence no `build` directory.
const dirContents = fs.readdirSync(kitchenPath);
Expand All @@ -71,8 +71,8 @@ describe('🚰 kitchen sink', () => {
// Use from a directory different from where we have locally installed. This
// simulates use as a globally installed module.
const GTS = path.resolve(stagingPath, 'kitchen/node_modules/.bin/gts');
const tmpDir = tmp.dirSync({ keep, unsafeCleanup: true });
const opts = { cwd: path.join(tmpDir.name, 'kitchen') };
const tmpDir = tmp.dirSync({keep, unsafeCleanup: true});
const opts = {cwd: path.join(tmpDir.name, 'kitchen')};

// Copy test files.
fs.copySync(fixturesPath, tmpDir.name);
Expand Down Expand Up @@ -128,7 +128,7 @@ describe('🚰 kitchen sink', () => {
const res = await execa(
'npm',
['run', 'check'],
Object.assign({}, { reject: false }, execOpts)
Object.assign({}, {reject: false}, execOpts)
);
assert.strictEqual(res.exitCode, 1);
assert.include(res.stdout, 'assigned a value but');
Expand Down
18 changes: 9 additions & 9 deletions test/test-clean.ts
Expand Up @@ -18,11 +18,11 @@ import * as assert from 'assert';
import * as fs from 'fs';
import * as path from 'path';

import { clean } from '../src/clean';
import { nop } from '../src/util';
import {clean} from '../src/clean';
import {nop} from '../src/util';

import { withFixtures } from 'inline-fixtures';
import { describe, it } from 'mocha';
import {withFixtures} from 'inline-fixtures';
import {describe, it} from 'mocha';

describe('clean', () => {
const OPTIONS = {
Expand All @@ -31,7 +31,7 @@ describe('clean', () => {
dryRun: false,
yes: false,
no: false,
logger: { log: nop, error: nop, dir: nop },
logger: {log: nop, error: nop, dir: nop},
};

it('should gracefully error if tsconfig is missing', () => {
Expand All @@ -44,15 +44,15 @@ describe('clean', () => {
});

it('should gracefully error if tsconfig does not have valid outDir', () => {
return withFixtures({ 'tsconfig.json': JSON.stringify({}) }, async () => {
return withFixtures({'tsconfig.json': JSON.stringify({})}, async () => {
const deleted = await clean(OPTIONS);
assert.strictEqual(deleted, false);
});
});

it('should avoid deleting .', () => {
return withFixtures(
{ 'tsconfig.json': JSON.stringify({ compilerOptions: { outDir: '.' } }) },
{'tsconfig.json': JSON.stringify({compilerOptions: {outDir: '.'}})},
async () => {
const deleted = await clean(OPTIONS);
assert.strictEqual(deleted, false);
Expand All @@ -66,7 +66,7 @@ describe('clean', () => {
withFixtures(
{
'tsconfig.json': JSON.stringify({
compilerOptions: { outDir: '../out' },
compilerOptions: {outDir: '../out'},
}),
},
async () => {
Expand All @@ -81,7 +81,7 @@ describe('clean', () => {
const OUT = 'outputDirectory';
return withFixtures(
{
'tsconfig.json': JSON.stringify({ compilerOptions: { outDir: OUT } }),
'tsconfig.json': JSON.stringify({compilerOptions: {outDir: OUT}}),
[OUT]: {},
},
async dir => {
Expand Down

0 comments on commit 8bd78c4

Please sign in to comment.