Skip to content

Commit

Permalink
feat: generate .eslintignore when running init (#521)
Browse files Browse the repository at this point in the history
  • Loading branch information
naseemkullah committed Jun 9, 2020
1 parent c9c27b4 commit 8bce036
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/init.ts
Expand Up @@ -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,
Expand Down Expand Up @@ -227,6 +229,10 @@ async function generateESLintConfig(options: Options): Promise<void> {
);
}

async function generateESLintIgnore(options: Options): Promise<void> {
return generateConfigFile(options, './.eslintignore', ESLINT_IGNORE);
}

async function generateTsConfig(options: Options): Promise<void> {
const config = formatJson({
extends: './node_modules/gts/tsconfig-google.json',
Expand All @@ -239,7 +245,8 @@ async function generateTsConfig(options: Options): Promise<void> {
async function generatePrettierConfig(options: Options): Promise<void> {
const style = `module.exports = {
...require('gts/.prettierrc.json')
}`;
}
`;
return generateConfigFile(options, './.prettierrc.js', style);
}

Expand Down Expand Up @@ -308,6 +315,7 @@ export async function init(options: Options): Promise<boolean> {
}
await generateTsConfig(options);
await generateESLintConfig(options);
await generateESLintIgnore(options);
await generatePrettierConfig(options);
await installDefaultTemplate(options);

Expand Down
13 changes: 12 additions & 1 deletion test/kitchen.ts
Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand All @@ -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 () => {
Expand Down

0 comments on commit 8bce036

Please sign in to comment.