{"size": 1584, "ext": "js", "max_stars_repo_path": "src/utils/logger.js", "max_stars_repo_name": "freearhey/m3u-linter", "max_stars_repo_stars_event_min_datetime": "2021-07-16T15:22:09.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-16T19:14:59.000Z", "max_issues_repo_path": "src/utils/logger.js", "max_issues_repo_name": "freearhey/m3u-linter", "max_issues_repo_issues_event_min_datetime": "2021-06-21T10:42:46.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-21T12:41:07.000Z", "max_forks_repo_path": "src/utils/logger.js", "max_forks_repo_name": "freearhey/m3u-linter", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 3, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 25.1428571429, "max_line_length": 99, "alphanum_fraction": 0.5688131313}
const chalk = require('chalk')
const path = require('path')

module.exports = {
  results(filePath, errors) {
    this.log(`\n${chalk.underline.white(path.resolve(filePath))}`)

    const findLargestReducer = (prev, curr) => {
      return curr > prev ? curr : prev
    }
    const longestLineChars = errors
      .map(error => `${error.line}:${error.column}`.length)
      .reduce(findLargestReducer, 0)
    const longestMsgChars = errors.map(error => error.message.length).reduce(findLargestReducer, 0)

    errors
      .sort((a, b) => {
        if (a.line < b.line) return -1
        if (a.line > b.line) return 1
        if (a.column < b.column) return -1
        if (a.column > b.column) return 1
        return 0
      })
      .forEach(error => {
        const lineText = padString(`${error.line}:${error.column}`, longestLineChars)
        const line = chalk.gray(lineText)
        const msg = chalk.white(padString(error.message, longestMsgChars))
        const rule = chalk.gray(error.rule)

        this.log(`  ${line}  ${msg}  ${rule}`)
      })
  },
  info(message) {
    if (message) {
      this.log(`\n${message}\n`)
    }
  },
  success(message) {
    if (message) {
      this.log(`\n${chalk.green(message)}\n`)
    }
  },
  error(message) {
    if (message) {
      this.log(`\n${chalk.red(message)}\n`)
    }
  },
  log(message) {
    console.log(message)
  }
}

function padString(string, longest) {
  if (string.length < longest) {
    Array(longest - string.length)
      .fill(null)
      .forEach(() => {
        string += ' '
      })
  }
  return string
}
