* Prettifies on the given list of files. * @param {!Array } filesToCheck * @return {Promise }
(filesToCheck)
| 108 | * @return {Promise<void>} |
| 109 | */ |
| 110 | async 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 | |
| 145 | module.exports = { |
| 146 | prettify, |
no test coverage detected