all files / src/ Reporter.js

100% Statements 11/11
100% Branches 2/2
100% Functions 1/1
100% Lines 11/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35                                               
'use strict';
 
const chalk = require('chalk');
const LintIssue = require('./LintIssue');
 
class Reporter {
 
  /**
   * Print issues
   * @param  {Array}      issues    An array of LintIssues
   * @param  {string}     issueType Error or warning
   * @return {undefined}            No return
   */
  write(issues, issueType) {
    const issueCount = issues.length;
 
    if (issueCount) {
      console.log(`\n----${issueType}-----`);
 
      for (const issue of issues) {
        console.log(issue.toString());
      }
 
      const formattedIssueCount = chalk.red.bold(issueCount);
 
      console.log(`\n${formattedIssueCount} ${issueType} found.`);
    } else {
      console.log(chalk.green.bold(`\nNo ${issueType} found!`));
    }
  }
 
}
 
module.exports = Reporter;