MCPcopy Create free account
hub / github.com/angular/dev-infra / checkFiles

Function checkFiles

ng-dev/format/format.ts:46–83  ·  view source on GitHub ↗
(files: string[])

Source from the content-addressed store, hash-verified

44 * @returns a status code indicating whether the format check run was successful.
45 */
46export async function checkFiles(files: string[]) {
47 // Files which are currently not formatted correctly.
48 const failures = await runFormatterInParallel(files, 'check');
49
50 if (failures === false) {
51 Log.info('No files matched for formatting check.');
52 return 0;
53 }
54
55 if (failures.length) {
56 // Provide output expressing which files are failing formatting.
57 Log.warn('\nThe following files are out of format:');
58 for (const {filePath} of failures) {
59 Log.warn(` • ${filePath}`);
60 }
61 Log.warn();
62
63 // If the command is run in a non-CI environment, prompt to format the files immediately.
64 let runFormatter = false;
65 if (!process.env['CI']) {
66 runFormatter = await Prompt.confirm({message: 'Format the files now?', default: true});
67 }
68
69 if (runFormatter) {
70 // Format the failing files as requested.
71 return (await formatFiles(failures.map((f) => f.filePath))) || 0;
72 } else {
73 // Inform user how to format files in the future.
74 Log.info();
75 Log.info(`To format the failing file run the following command:`);
76 Log.info(` pnpm ng-dev format files ${failures.map((f) => f.filePath).join(' ')}`);
77 return 1;
78 }
79 } else {
80 Log.info(green('✔ All files correctly formatted.'));
81 return 0;
82 }
83}

Callers

nothing calls this directly

Calls 2

runFormatterInParallelFunction · 0.85
formatFilesFunction · 0.85

Tested by

no test coverage detected