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 4f8f137b..94e39305 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', ); } diff --git a/src/init.ts b/src/init.ts index 98e75f78..09ebccfd 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) { @@ -344,7 +344,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 28c19287..edfe3a17 100644 --- a/src/util.ts +++ b/src/util.ts @@ -63,7 +63,7 @@ async function getBase( filePath: string, customReadFilep: ReadFileP, readFiles: Set, - currentDir: string + currentDir: string, ): Promise { customReadFilep = customReadFilep || readFilep; @@ -92,7 +92,7 @@ async function getBase( contents.extends, customReadFilep, readFiles, - path.dirname(filePath) + path.dirname(filePath), ); contents = combineTSConfig(nextFile, contents); } @@ -117,7 +117,7 @@ function combineTSConfig(base: ConfigFile, inherited: ConfigFile): ConfigFile { Object.assign( result.compilerOptions!, base.compilerOptions!, - inherited.compilerOptions! + inherited.compilerOptions!, ); delete result.extends; return result; @@ -161,7 +161,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 df1888e2..9d03320a 100644 --- a/test/kitchen.ts +++ b/test/kitchen.ts @@ -82,7 +82,7 @@ describe('🚰 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. @@ -91,12 +91,12 @@ describe('🚰 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. @@ -113,27 +113,27 @@ describe('🚰 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'), ); }); @@ -141,7 +141,7 @@ describe('🚰 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 7bc80b70..92d0a50f 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 8b735aea..20423267 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`, ); });