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 .clang-format #163

Merged
merged 2 commits into from
Jun 4, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import {createProgram} from './lint';

const clangFormat = require('clang-format');

const baseArgs =
['-style', '{Language: JavaScript, BasedOnStyle: Google, ColumnLimit: 80}'];
const baseArgs = ['-style=file'];

/**
* Run tslint fix and clang fix with the default configuration
Expand Down
8 changes: 7 additions & 1 deletion src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ async function generateTsConfig(options: Options): Promise<void> {
return generateConfigFile(options, './tsconfig.json', config);
}

async function generateClangFormat(options: Options): Promise<void> {
const style = await read(path.join(__dirname, '../../.clang-format'), 'utf8');
return generateConfigFile(options, './.clang-format', style);
}

async function generateConfigFile(
options: Options, filename: string, contents: string) {
let existing;
Expand Down Expand Up @@ -183,7 +188,7 @@ async function generateConfigFile(
if (!options.dryRun) {
await write(filename, contents);
}
options.logger.dir(JSON.parse(contents));
options.logger.log(contents);
}
}

Expand Down Expand Up @@ -222,6 +227,7 @@ export async function init(options: Options): Promise<boolean> {
}
await generateTsConfig(options);
await generateTsLintConfig(options);
await generateClangFormat(options);

// Run `npm install` after initial setup so `npm run check` works right away.
if (!options.dryRun) {
Expand Down
5 changes: 2 additions & 3 deletions test/test-kitchen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,10 @@ test.serial('init', async t => {
execOpts);
}

// Ensure tsconfig.json got generated.
// Ensure config files got generated.
fs.accessSync(`${stagingPath}/kitchen/tsconfig.json`);

// Ensure tslint.json got generated.
fs.accessSync(`${stagingPath}/kitchen/tslint.json`);
fs.accessSync(`${stagingPath}/kitchen/.clang-format`);

// Compilation shouldn't have happened. Hence no `build` directory.
const dirContents = fs.readdirSync(`${stagingPath}/kitchen`);
Expand Down