From 8bce0368767f0c2ad7d0700deb839962bc928d16 Mon Sep 17 00:00:00 2001 From: Naseem Date: Mon, 8 Jun 2020 21:46:11 -0400 Subject: [PATCH] feat: generate .eslintignore when running init (#521) --- src/init.ts | 10 +++++++++- test/kitchen.ts | 13 ++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/init.ts b/src/init.ts index 14294410..b7b5fa4f 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', @@ -239,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); } @@ -308,6 +315,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..c0d6dbe2 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. @@ -104,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( @@ -122,6 +123,16 @@ describe('🚰 kitchen sink', () => { .readFileSync(path.join(kitchenPath, '.eslintrc.json'), 'utf8') .endsWith('\n') ); + assert.ok( + fs + .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 () => {