All files / lib/report summary.js

97.14% Statements 68/70
90.9% Branches 20/22
100% Functions 1/1
97.14% Lines 68/70

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 7127x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 579x 579x 579x 9874x 9874x 9874x 48x 48x 48x 5838x 9874x 9874x 579x 579x 579x 579x 17x 17x 17x 17x 17x 17x 17x 17x 16x 16x 7x 7x 17x 1x 1x 17x 17x 17x 17x 14x 14x 17x     17x 17x 17x  
'use strict'
 
module.exports = summary
 
const {
  COLORS,
  tooltip
} = require('../ncm-style')
const {
  SEVERITY_RMAP
} = require('./util')
const L = console.log
const chalk = require('chalk')
 
function summary (report, dir, filterOptions) {
  filterOptions = filterOptions || {}
 
  L()
  L(chalk`${report.length} {${COLORS.light1} packages checked}`)
  L()
 
  const riskCount = [0, 0, 0, 0, 0]
  let insecureModules = 0
  let complianceCount = 0
  let securityCount = 0
 
  for (const pkg of report) {
    let insecure = false
    let pkgMaxSeverity = 0
    for (const score of pkg.scores) {
      if (score.group === 'quality') continue
      if (score.group === 'compliance' && !score.pass) complianceCount++
      if (score.group === 'security' && !score.pass) {
        securityCount++
        insecure = true
      }
      const scoreIndex = SEVERITY_RMAP.indexOf(score.severity)
      pkgMaxSeverity = scoreIndex > pkgMaxSeverity ? scoreIndex : pkgMaxSeverity
    }
    if (pkg.auditScore != null) pkgMaxSeverity = pkg.auditScore
    riskCount[pkgMaxSeverity]++
    if (insecure) insecureModules++
  }
 
  L(chalk`  {${COLORS.red} ! ${riskCount[4]}} critical risk`)
  L(chalk`    {${COLORS.orange} ${riskCount[3]}} high risk`)
  L(chalk`    {${COLORS.yellow} ${riskCount[2]}} medium risk`)
  L(chalk`    {${COLORS.light1} ${riskCount[1]}} low risk`)
 
  L()
  if (securityCount) {
    L(chalk`  {${COLORS.red} !} ${securityCount} security vulnerabilities found across ${insecureModules} modules`)
    if (!filterOptions.filterSecurity) {
      L('    ' + tooltip('Run `ncm report --filter=security` for a list'))
    }
  } else {
    L(chalk`  {${COLORS.green} ✓} No security vulnerabilities found`)
  }
  L()
  if (complianceCount) {
    L(chalk`  {${COLORS.red} !} ${complianceCount} noncompliant modules found`)
    if (!filterOptions.filterCompliance) {
      L('    ' + tooltip('Run `ncm report --filter=compliance` for a list'))
    }
  } else {
    L(chalk`  {${COLORS.green} ✓} All modules compliant`)
  }
  L()
  return riskCount
}