all files / src/ LintIssue.js

100% Statements 10/10
100% Branches 2/2
100% Functions 2/2
100% Lines 10/10
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 36                          53× 53× 53× 53×                          
"use strict";
 
const chalk = require("chalk");
 
class LintIssue {
 
  /**
   * constructor
   * @param  {String} lintId      Unique, lowercase, hyphen-separate name for the lint
   * @param  {String} lintType    error or warning
   * @param  {String} node        Name of the node in the JSON the lint audits
   * @param  {String} lintMessage Human-friendly message to users
   */
  constructor(lintId, lintType, node, lintMessage) {
    this.lintId = lintId;
    this.lintType = lintType;
    this.node = node;
    this.lintMessage = lintMessage;
  }
 
  /**
   * Helper to convert the LintIssue to a printable string
   * @return {String} Human-friendly message about the lint issue
   */
  toString() {
    const formattedLintId = chalk.cyan.bold(this.lintId);
    const formattedNode = chalk.blue.bold(this.node);
    const formattedMessage = this.lintType === "error" ? chalk.bold.red(this.lintMessage) : chalk.yellow(this.lintMessage);
 
    return `${formattedLintId} - node: ${formattedNode} - ${formattedMessage}`;
  }
 
}
 
module.exports = LintIssue;