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

Callers

nothing calls this directly

Calls 2

runFormatterInParallelFunction · 0.85
formatFilesFunction · 0.85

Tested by

no test coverage detected