diff --git a/.prettierrc.json b/.prettierrc.json index 993c3270..2399e7ec 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1,6 +1,6 @@ { "bracketSpacing": false, "singleQuote": true, - "trailingComma": "es5", + "trailingComma": "all", "arrowParens": "avoid" } diff --git a/src/clean.ts b/src/clean.ts index b71be1ea..8dd3eebd 100644 --- a/src/clean.ts +++ b/src/clean.ts @@ -33,7 +33,7 @@ export async function clean(options: Options): Promise { if (outDir === '.') { options.logger.error( `${chalk.red('ERROR:')} ${chalk.gray('compilerOptions.outDir')} ` + - 'cannot use the value ".". That would delete all of our sources.' + 'cannot use the value ".". That would delete all of our sources.', ); return false; } @@ -45,7 +45,7 @@ export async function clean(options: Options): Promise { options.logger.error( `${chalk.red('ERROR:')} The ${chalk.gray('clean')} command` + ` requires ${chalk.gray('compilerOptions.outDir')} to be defined in ` + - 'tsconfig.json.' + 'tsconfig.json.', ); return false; } diff --git a/src/cli.ts b/src/cli.ts index c8676530..507f0e7c 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -42,7 +42,7 @@ export interface Options { export type VerbFilesFunction = ( options: Options, files: string[], - fix?: boolean + fix?: boolean, ) => Promise; const logger: Logger = console; @@ -105,7 +105,7 @@ export async function run(verb: string, files: string[]): Promise { throw new Error( `gts requires node.js 10.x or up. You are currently running ${process.version}, which is not supported. Please upgrade to - a safe, secure version of nodejs!` + a safe, secure version of nodejs!`, ); } @@ -133,7 +133,7 @@ export async function run(verb: string, files: string[]): Promise { '**/*.js', '**/*.tsx', '**/*.jsx', - '--no-error-on-unmatched-pattern' + '--no-error-on-unmatched-pattern', ); } @@ -169,16 +169,15 @@ if (cli.input.length < 1) { usage(); } -run(cli.input[0], cli.input.slice(1)).then( - success => { +run(cli.input[0], cli.input.slice(1)) + .then(success => { if (!success) { // eslint-disable-next-line n/no-process-exit process.exit(1); } - }, - e => { + }) + .catch(e => { console.error(e); // eslint-disable-next-line n/no-process-exit process.exit(1); - } -); + }); diff --git a/src/init.ts b/src/init.ts index 03fe41f5..0f161d3e 100644 --- a/src/init.ts +++ b/src/init.ts @@ -54,7 +54,7 @@ async function query( message: string, question: string, defaultVal: boolean, - options: Options + options: Options, ): Promise { if (options.yes) { return true; @@ -77,7 +77,7 @@ async function query( export async function addScripts( packageJson: PackageJSON, - options: Options + options: Options, ): Promise { let edits = false; const pkgManager = getPkgManagerCommand(options.yarn); @@ -120,7 +120,7 @@ export async function addScripts( export async function addDependencies( packageJson: PackageJSON, - options: Options + options: Options, ): Promise { let edits = false; const deps: DefaultPackage = { @@ -164,7 +164,7 @@ function formatJson(object: {}) { async function writePackageJson( packageJson: PackageJSON, - options: Options + options: Options, ): Promise { options.logger.log('Writing package.json...'); if (!options.dryRun) { @@ -186,7 +186,7 @@ export const ESLINT_IGNORE = 'build/\n'; async function generateConfigFile( options: Options, filename: string, - contents: string + contents: string, ) { let existing; try { @@ -209,7 +209,7 @@ async function generateConfigFile( `${chalk.bold(filename)} already exists`, 'Overwrite', false, - options + options, ); } @@ -226,7 +226,7 @@ async function generateESLintConfig(options: Options): Promise { return generateConfigFile( options, './.eslintrc.json', - formatJson(ESLINT_CONFIG) + formatJson(ESLINT_CONFIG), ); } @@ -265,7 +265,7 @@ insert_final_newline = true } export async function installDefaultTemplate( - options: Options + options: Options, ): Promise { const cwd = process.cwd(); const sourceDirName = path.join(__dirname, '../template'); @@ -287,7 +287,7 @@ export async function installDefaultTemplate( if (tsFiles.length !== 0) { options.logger.log( 'Target src directory already has ts files. ' + - 'Template files not installed.' + 'Template files not installed.', ); return false; } @@ -310,7 +310,7 @@ export async function init(options: Options): Promise { `${chalk.bold('package.json')} does not exist.`, 'Generate', true, - options + options, ); if (!generate) { @@ -348,7 +348,7 @@ export async function init(options: Options): Promise { cp.spawnSync( getPkgManagerCommand(options.yarn), ['install', '--ignore-scripts'], - {stdio: 'inherit'} + {stdio: 'inherit'}, ); } diff --git a/src/util.ts b/src/util.ts index dc44df18..829d68bd 100644 --- a/src/util.ts +++ b/src/util.ts @@ -61,7 +61,7 @@ async function getBase( filePath: string, customReadFilep: ReadFileP, readFiles: Set, - currentDir: string + currentDir: string, ): Promise { customReadFilep = customReadFilep || readFilep; @@ -90,7 +90,7 @@ async function getBase( contents.extends, customReadFilep, readFiles, - path.dirname(filePath) + path.dirname(filePath), ); contents = combineTSConfig(nextFile, contents); } @@ -115,7 +115,7 @@ function combineTSConfig(base: ConfigFile, inherited: ConfigFile): ConfigFile { Object.assign( result.compilerOptions!, base.compilerOptions!, - inherited.compilerOptions! + inherited.compilerOptions!, ); delete result.extends; return result; @@ -159,7 +159,7 @@ export function getPkgManagerCommand(isYarnUsed?: boolean): string { */ export async function getTSConfig( rootDir: string, - customReadFilep?: ReadFileP + customReadFilep?: ReadFileP, ): Promise { customReadFilep = (customReadFilep || readFilep) as ReadFileP; const readArr = new Set(); diff --git a/test/kitchen.ts b/test/kitchen.ts index c39e4848..75266e74 100644 --- a/test/kitchen.ts +++ b/test/kitchen.ts @@ -84,7 +84,7 @@ action('🚰 kitchen sink', () => { // Test package.json expects a gts tarball from ../gts.tgz. fs.copySync( path.join(stagingPath, 'gts.tgz'), - path.join(tmpDir.name, 'gts.tgz') + path.join(tmpDir.name, 'gts.tgz'), ); // It's important to use `-n` here because we don't want to overwrite // the version of gts installed, as it will trigger the npm install. @@ -93,12 +93,12 @@ action('🚰 kitchen sink', () => { // The `extends` field must use the local gts path. const tsconfigJson = fs.readFileSync( path.join(tmpDir.name, 'kitchen', 'tsconfig.json'), - 'utf8' + 'utf8', ); const tsconfig = JSON.parse(tsconfigJson); assert.deepStrictEqual( tsconfig.extends, - './node_modules/gts/tsconfig-google.json' + './node_modules/gts/tsconfig-google.json', ); // server.ts has a lint error. Should error. @@ -115,27 +115,27 @@ action('🚰 kitchen sink', () => { assert.ok( fs .readFileSync(path.join(kitchenPath, 'package.json'), 'utf8') - .endsWith('\n') + .endsWith('\n'), ); assert.ok( fs .readFileSync(path.join(kitchenPath, 'tsconfig.json'), 'utf8') - .endsWith('\n') + .endsWith('\n'), ); assert.ok( fs .readFileSync(path.join(kitchenPath, '.eslintrc.json'), 'utf8') - .endsWith('\n') + .endsWith('\n'), ); assert.ok( fs .readFileSync(path.join(kitchenPath, '.eslintignore'), 'utf8') - .endsWith('\n') + .endsWith('\n'), ); assert.ok( fs .readFileSync(path.join(kitchenPath, '.prettierrc.js'), 'utf8') - .endsWith('\n') + .endsWith('\n'), ); }); @@ -143,7 +143,7 @@ action('🚰 kitchen sink', () => { const res = await execa( 'npm', ['run', 'lint'], - Object.assign({}, {reject: false}, execOpts) + Object.assign({}, {reject: false}, execOpts), ); assert.strictEqual(res.exitCode, 1); assert.ok(res.stdout.includes('assigned a value but')); diff --git a/test/test-clean.ts b/test/test-clean.ts index 0f039cbe..4c603da7 100644 --- a/test/test-clean.ts +++ b/test/test-clean.ts @@ -38,7 +38,7 @@ describe('clean', () => { return assert.rejects(() => withFixtures({}, async () => { await clean(OPTIONS); - }) + }), ); }); @@ -73,7 +73,7 @@ describe('clean', () => { async () => { const deleted = await clean(OPTIONS); assert.strictEqual(deleted, false); - } + }, ); }); @@ -88,8 +88,8 @@ describe('clean', () => { async () => { const deleted = await clean(OPTIONS); assert.strictEqual(deleted, false); - } - ) + }, + ), ); }); @@ -110,7 +110,7 @@ describe('clean', () => { assert.throws(() => { fs.accessSync(outputPath); }); - } + }, ); }); }); diff --git a/test/test-init.ts b/test/test-init.ts index 94c61c04..f5b05d04 100644 --- a/test/test-init.ts +++ b/test/test-init.ts @@ -45,7 +45,7 @@ function hasExpectedScripts(packageJson: PackageJSON): boolean { return ( !!packageJson.scripts && ['lint', 'clean', 'compile', 'fix', 'prepare', 'pretest', 'posttest'].every( - s => !!packageJson.scripts![s] + s => !!packageJson.scripts![s], ) ); } @@ -161,14 +161,14 @@ describe('init', () => { assert.notStrictEqual( contents, originalContents, - 'the file should have been modified' + 'the file should have been modified', ); assert.strictEqual( contents.some, originalContents.some, - 'unrelated property should have preserved' + 'unrelated property should have preserved', ); - } + }, ); }); @@ -195,7 +195,7 @@ describe('init', () => { const contents = await readJson('./package.json'); const cmd = process.platform === 'win32' ? 'yarn.cmd' : 'yarn'; assert.strictEqual(contents.scripts.prepare, cmd + ' run compile'); - } + }, ); }); diff --git a/test/test-util.ts b/test/test-util.ts index 8c45037d..def36a9d 100644 --- a/test/test-util.ts +++ b/test/test-util.ts @@ -42,7 +42,7 @@ function createFakeReadFilep(myMap: Map) { } function makeFakeFsExistsSync( - expected: PathLike[] + expected: PathLike[], ): (path: PathLike) => boolean { return (path: PathLike) => expected.some(item => item === path); } @@ -58,7 +58,7 @@ describe('util', () => { function fakeReadFilep( configPath: string, - encoding: string + encoding: string, ): Promise { assert.strictEqual(configPath, PATH_TO_TSCONFIG); assert.strictEqual(encoding, 'utf8'); @@ -82,7 +82,7 @@ describe('util', () => { return assert.rejects( () => getTSConfig(FAKE_DIRECTORY, createFakeReadFilep(myMap)), Error, - 'Circular Reference Detected' + 'Circular Reference Detected', ); }); @@ -108,7 +108,7 @@ describe('util', () => { const contents = await getTSConfig( FAKE_DIRECTORY, - createFakeReadFilep(myMap) + createFakeReadFilep(myMap), ); assert.deepStrictEqual(contents, combinedConfig); }); @@ -125,7 +125,7 @@ describe('util', () => { const contents = await getTSConfig( FAKE_DIRECTORY, - createFakeReadFilep(myMap) + createFakeReadFilep(myMap), ); assert.deepStrictEqual(contents, combinedConfig); }); @@ -145,12 +145,12 @@ describe('util', () => { myMap.set(path.resolve(FAKE_DIRECTORY, './foo/FAKE_CONFIG2'), FAKE_CONFIG2); myMap.set( path.resolve(FAKE_DIRECTORY, './foo/bar/FAKE_CONFIG3'), - FAKE_CONFIG3 + FAKE_CONFIG3, ); const contents = await getTSConfig( FAKE_DIRECTORY, - createFakeReadFilep(myMap) + createFakeReadFilep(myMap), ); assert.deepStrictEqual(contents, combinedConfig); }); @@ -162,7 +162,7 @@ describe('util', () => { return assert.rejects( () => getTSConfig(FAKE_DIRECTORY, createFakeReadFilep(myMap)), Error, - `${FAKE_DIRECTORY}/tsconfig.json Not Found` + `${FAKE_DIRECTORY}/tsconfig.json Not Found`, ); });