2020-04-24 19:29:53 -04:00
|
|
|
/**
|
|
|
|
* @license
|
2020-05-19 15:08:49 -04:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2020-04-24 19:29:53 -04:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
|
|
|
import {join} from 'path';
|
|
|
|
|
2020-05-20 17:19:17 -04:00
|
|
|
import {error} from '../../utils/console';
|
2020-04-24 19:29:53 -04:00
|
|
|
|
|
|
|
import {Formatter} from './base-formatter';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Formatter for running clang-format against Typescript and Javascript files
|
|
|
|
*/
|
|
|
|
export class ClangFormat extends Formatter {
|
2021-07-07 13:58:22 -04:00
|
|
|
override name = 'clang-format';
|
2020-04-24 19:29:53 -04:00
|
|
|
|
2021-07-07 13:58:22 -04:00
|
|
|
override binaryFilePath = join(this.git.baseDir, 'node_modules/.bin/clang-format');
|
2020-04-24 19:29:53 -04:00
|
|
|
|
2021-07-07 13:58:22 -04:00
|
|
|
override defaultFileMatcher = ['**/*.{t,j}s'];
|
2020-04-24 19:29:53 -04:00
|
|
|
|
2021-07-07 13:58:22 -04:00
|
|
|
override actions = {
|
2020-04-24 19:29:53 -04:00
|
|
|
check: {
|
|
|
|
commandFlags: `--Werror -n -style=file`,
|
|
|
|
callback:
|
2021-05-27 15:04:39 -04:00
|
|
|
(_: string, code: number|NodeJS.Signals) => {
|
2020-04-24 19:29:53 -04:00
|
|
|
return code !== 0;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
format: {
|
|
|
|
commandFlags: `-i -style=file`,
|
|
|
|
callback:
|
2021-05-27 15:04:39 -04:00
|
|
|
(file: string, code: number|NodeJS.Signals, _: string, stderr: string) => {
|
2020-04-24 19:29:53 -04:00
|
|
|
if (code !== 0) {
|
2020-05-20 17:19:17 -04:00
|
|
|
error(`Error running clang-format on: ${file}`);
|
|
|
|
error(stderr);
|
|
|
|
error();
|
2020-04-24 19:29:53 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|