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

Function printErrorWithSuggestedFixes

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

* Prints an error message with recommended fixes (in diff form) for a file with * formatting errors. * * @param {string} file * @return {Promise }

(file)

Source from the content-addressed store, hash-verified

61 * @return {Promise<void>}
62 */
63async function printErrorWithSuggestedFixes(file) {
64 logWithoutTimestamp('\n');
65 log(`Suggested fixes for ${cyan(file)}:`);
66 const options = await getOptions(file);
67 const original = fs.readFileSync(file).toString();
68 const fixed = await prettier.format(original, options);
69 const fixedFile = `${tempDir}/${file}`;
70 fs.ensureDirSync(path.dirname(fixedFile));
71 fs.writeFileSync(fixedFile, fixed);
72 const diffCmd = `git -c color.ui=always diff -U0 ${file} ${fixedFile} | tail -n +5`;
73 exec(diffCmd);
74}
75
76/**
77 * Prints instructions for how to auto-fix errors.

Callers 1

runPrettifyFunction · 0.85

Calls 6

logWithoutTimestampFunction · 0.85
cyanFunction · 0.85
execFunction · 0.85
getOptionsFunction · 0.70
logFunction · 0.50
toStringMethod · 0.45

Tested by

no test coverage detected