Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: generate .eslintignore when running init #521

Merged
merged 2 commits into from Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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