MCPcopy
hub / github.com/ampproject/amphtml / runPrettify

Function runPrettify

build-system/tasks/prettify.js:110–143  ·  view source on GitHub ↗

* Prettifies on the given list of files. * @param {!Array } filesToCheck * @return {Promise }

(filesToCheck)

Source from the content-addressed store, hash-verified

108 * @return {Promise<void>}
109 */
110async function runPrettify(filesToCheck) {
111 logLocalDev(green('Starting checks...'));
112 const filesWithErrors = [];
113 for (const file of filesToCheck) {
114 const options = await getOptions(file);
115 const original = fs.readFileSync(file).toString();
116 if (argv.fix) {
117 const fixed = await prettier.format(original, options);
118 if (fixed != original) {
119 fs.writeFileSync(file, fixed);
120 }
121 if (!prettier.check(fixed, options)) {
122 filesWithErrors.push(file);
123 }
124 } else {
125 if (!prettier.check(original, options)) {
126 filesWithErrors.push(file);
127 }
128 }
129 logOnSameLineLocalDev(green('Checked: ') + path.relative(rootDir, file));
130 }
131 if (filesWithErrors.length) {
132 logOnSameLine(
133 red('ERROR:'),
134 'Found formatting errors in one or more files'
135 );
136 for (const file of filesWithErrors) {
137 await printErrorWithSuggestedFixes(file);
138 }
139 printFixMessages();
140 process.exitCode = 1;
141 }
142 logOnSameLineLocalDev('Checked ' + cyan(filesToCheck.length) + ' file(s)');
143}
144
145module.exports = {
146 prettify,

Callers 1

prettifyFunction · 0.85

Calls 12

logLocalDevFunction · 0.85
greenFunction · 0.85
logOnSameLineLocalDevFunction · 0.85
logOnSameLineFunction · 0.85
redFunction · 0.85
printFixMessagesFunction · 0.85
cyanFunction · 0.85
getOptionsFunction · 0.70
toStringMethod · 0.45
checkMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected