Skip to content

Commit

Permalink
feat(formatter): add info about files fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
emjimadhu committed Apr 15, 2020
1 parent f86f91a commit 2f4b22c
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CLIEngine } from 'eslint';
import chalk from 'chalk';
import { relative } from 'path';

const formatter = ((results: CLIEngine.LintResult[]): string => {
let totalErrorCount = 0;
Expand All @@ -19,9 +20,29 @@ const formatter = ((results: CLIEngine.LintResult[]): string => {
totalWarningCount = totalWarningCount + warningCount;
});

const hasFixed = results.some((result: CLIEngine.LintResult) => {
return result.output;
});
let fixedFilesMessage = '\n';
if (hasFixed) {
let fixedFiles = '';
results.forEach((result: CLIEngine.LintResult) => {
if (result.output) {
const outputFileName = relative(process.cwd(), result.filePath);
if (fixedFiles.length > 0) {
fixedFiles = `${fixedFiles} ${chalk.blue(outputFileName)}\n`;
} else {
fixedFiles = ` ${chalk.blue(outputFileName)}\n`;
}
}
});

fixedFilesMessage = `\nThe following files have been auto-fixed:\n\n${fixedFiles}\n`;
}

if (totalErrorCount + totalWarningCount === 0) {
return (
`\n${chalk.bgHex('#2e7d32').white.bold(' DONE ')}: ${chalk.hex('#43a047')('No lint errors found!')}\n`
`${fixedFilesMessage}${chalk.bgHex('#2e7d32').white.bold(' DONE ')}: ${chalk.hex('#43a047')(hasFixed ? 'All lint errors auto-fixed.' : 'No lint errors found!')}\n`
);
} else {
return (
Expand Down

0 comments on commit 2f4b22c

Please sign in to comment.