<commit_before>import {repeat} from 'lodash'


export default class PrintErrorsAndWarningsPlugin {
  apply(program) {
    let errorCount = 0
    let warningCount = 0
    program.plugin('parser', parser => {
      let currentTrip
      function formatError(error) {
        const {file, severity, line, text, startColumn, endColumn, message} = error
        let surveyScan = currentTrip && currentTrip.surveyScan
        return [
          `${severity}: ${message} (${file}, ${line}:${startColumn}-${endColumn}) ${surveyScan || ''}`,
          text,
          repeat(' ', startColumn) + repeat('^', endColumn - startColumn),
        ].join('\n')
      }

      parser.plugin('trip', trip => currentTrip = trip)
      parser.plugin('error', error => {
        if (error.severity === 'error') {
          errorCount++
          console.error(formatError(error))
        } else {
          warningCount++
          console.warn(formatError(error))
        }
        return error
      })
    })
    program.plugin('beforeExit', () => {
      if (errorCount + warningCount > 0) {
        console[errorCount ? 'error' : 'warning'](
          `${errorCount} error${errorCount !== 1 ? 's' : ''}, ${warningCount} warning${warningCount !== 1 ? 's' : ''}`
        )
      }
    })
  }
}
<commit_msg>output more trip information with errors/warnings<commit_after>import {repeat} from 'lodash'

export default class ErrorOutputPlugin {
  apply(program) {
    let errorCount = 0
    let warningCount = 0
    program.plugin('parser', parser => {
      let currentTrip
      function formatError(error) {
        const {file, severity, line, text, startColumn, endColumn, message} = error
        const {surveyScan, tripNum, name} = currentTrip || {}
        return [
          `${severity}: ${message} (${file}, ${line}:${startColumn}-${endColumn}) ${surveyScan || `Trip #${tripNum || '?'}: ${name}`}`,
          text,
          repeat(' ', startColumn) + repeat('^', endColumn - startColumn),
        ].join('\n')
      }

      parser.plugin('trip', trip => currentTrip = trip)
      parser.plugin('error', error => {
        if (error.severity === 'error') {
          errorCount++
          console.error(formatError(error))
        } else {
          warningCount++
          console.warn(formatError(error))
        }
        return error
      })
    })
    program.plugin('beforeExit', () => {
      if (errorCount + warningCount > 0) {
        console[errorCount ? 'error' : 'warning'](
          `${errorCount} error${errorCount !== 1 ? 's' : ''}, ${warningCount} warning${warningCount !== 1 ? 's' : ''}`
        )
      }
    })
  }
}

{'fraction_non_alphanumeric': 0.1630558722919042, 'fraction_numerical': 0.003800836183960471, 'mean_word_length': 2.422626788036411, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4519944', 'n_tokens_mistral': 774, 'n_tokens_neox': 759, 'n_words': 167}