| 168 | } |
| 169 | |
| 170 | const log = async (report: { |
| 171 | errorCount: number; |
| 172 | warningCount: number; |
| 173 | fixableErrorCount: number; |
| 174 | fixableWarningCount: number; |
| 175 | results: ESLint.LintResult[]; |
| 176 | rulesMeta: Record<string, Rule.RuleMetaData>; |
| 177 | }, xo: Xo) => { |
| 178 | const reporterName = cliOptions.reporter; |
| 179 | const shouldUsePrettyReporter = reporterName === undefined; |
| 180 | |
| 181 | // Hide warnings when there are errors to reduce noise in the default human-readable output. |
| 182 | const results = shouldUsePrettyReporter && report.errorCount > 0 && cliOptions.maxWarnings < 0 |
| 183 | ? ESLint.getErrorResults(report.results) |
| 184 | : report.results; |
| 185 | |
| 186 | if (shouldUsePrettyReporter) { |
| 187 | const counts = { |
| 188 | errorCount: 0, |
| 189 | warningCount: 0, |
| 190 | fixableErrorCount: 0, |
| 191 | fixableWarningCount: 0, |
| 192 | }; |
| 193 | |
| 194 | for (const result of results) { |
| 195 | counts.errorCount += result.errorCount; |
| 196 | counts.warningCount += result.warningCount; |
| 197 | counts.fixableErrorCount += result.fixableErrorCount; |
| 198 | counts.fixableWarningCount += result.fixableWarningCount; |
| 199 | } |
| 200 | |
| 201 | const formatterMetadata = { |
| 202 | cwd: linterOptions.cwd, |
| 203 | ...report, |
| 204 | ...counts, |
| 205 | results, |
| 206 | }; |
| 207 | |
| 208 | console.log(formatterPretty(results, formatterMetadata)); |
| 209 | } else { |
| 210 | const reporter = await xo.getFormatter(reporterName); |
| 211 | console.log(await reporter.format(results)); |
| 212 | } |
| 213 | |
| 214 | process.exitCode = report.errorCount === 0 ? 0 : 1; |
| 215 | |
| 216 | if (cliOptions.maxWarnings >= 0 && report.warningCount > cliOptions.maxWarnings) { |
| 217 | console.error(`XO found too many warnings (maximum: ${cliOptions.maxWarnings}).`); |
| 218 | process.exitCode = 1; |
| 219 | } |
| 220 | }; |
| 221 | |
| 222 | try { |
| 223 | if (cliOptions.version) { |