From 6424ebae80c46afea1479fda8a51a0e5666b468e Mon Sep 17 00:00:00 2001 From: Naseem Date: Thu, 28 May 2020 11:04:15 -0400 Subject: [PATCH 1/2] skip lint on build dir by means of .eslintignore generation solves https://github.com/google/gts/issues/483 solves https://github.com/google/gts/issues/520 --- src/init.ts | 7 +++++++ test/kitchen.ts | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/src/init.ts b/src/init.ts index 14294410..1eaf5182 100644 --- a/src/init.ts +++ b/src/init.ts @@ -181,6 +181,8 @@ export const ESLINT_CONFIG = { extends: './node_modules/gts/', }; +export const ESLINT_IGNORE = 'build/\n'; + async function generateConfigFile( options: Options, filename: string, @@ -227,6 +229,10 @@ async function generateESLintConfig(options: Options): Promise { ); } +async function generateESLintIgnore(options: Options): Promise { + return generateConfigFile(options, './.eslintignore', ESLINT_IGNORE); +} + async function generateTsConfig(options: Options): Promise { const config = formatJson({ extends: './node_modules/gts/tsconfig-google.json', @@ -308,6 +314,7 @@ export async function init(options: Options): Promise { } await generateTsConfig(options); await generateESLintConfig(options); + await generateESLintIgnore(options); await generatePrettierConfig(options); await installDefaultTemplate(options); diff --git a/test/kitchen.ts b/test/kitchen.ts index 12abb492..c0bdcca9 100644 --- a/test/kitchen.ts +++ b/test/kitchen.ts @@ -60,6 +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, '.eslintignore')); fs.accessSync(path.join(kitchenPath, '.prettierrc.js')); // Compilation shouldn't have happened. Hence no `build` directory. @@ -122,6 +123,11 @@ describe('🚰 kitchen sink', () => { .readFileSync(path.join(kitchenPath, '.eslintrc.json'), 'utf8') .endsWith('\n') ); + assert.ok( + fs + .readFileSync(path.join(kitchenPath, '.eslintignore'), 'utf8') + .endsWith('\n') + ); }); it('should check before fix', async () => { From 0ed5df04ad0e62ccdad9e44654bb4059c5b37f36 Mon Sep 17 00:00:00 2001 From: Naseem Date: Tue, 2 Jun 2020 22:27:52 -0400 Subject: [PATCH 2/2] fix: add empty line at end of generated .prettierrc.js Signed-off-by: Naseem --- src/init.ts | 3 ++- test/kitchen.ts | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/init.ts b/src/init.ts index 1eaf5182..b7b5fa4f 100644 --- a/src/init.ts +++ b/src/init.ts @@ -245,7 +245,8 @@ async function generateTsConfig(options: Options): Promise { async function generatePrettierConfig(options: Options): Promise { const style = `module.exports = { ...require('gts/.prettierrc.json') -}`; +} +`; return generateConfigFile(options, './.prettierrc.js', style); } diff --git a/test/kitchen.ts b/test/kitchen.ts index c0bdcca9..c0d6dbe2 100644 --- a/test/kitchen.ts +++ b/test/kitchen.ts @@ -105,7 +105,7 @@ describe('🚰 kitchen sink', () => { } }); - it('should terminate generated json files with newline', () => { + it('should terminate generated files with newline', () => { const GTS = path.resolve(stagingPath, gtsPath); spawn.sync(GTS, ['init', '-y'], execOpts); assert.ok( @@ -128,6 +128,11 @@ describe('🚰 kitchen sink', () => { .readFileSync(path.join(kitchenPath, '.eslintignore'), 'utf8') .endsWith('\n') ); + assert.ok( + fs + .readFileSync(path.join(kitchenPath, '.prettierrc.js'), 'utf8') + .endsWith('\n') + ); }); it('should check before fix', async () => {