<commit_before>#!/usr/bin/env node

var fs = require('fs')
var minimist = require('minimist')
var standard = require('../')
var standardFormat = require('standard-format')
var stdin = require('get-stdin')

var argv = minimist(process.argv.slice(2), {
  alias: {
    format: 'F',
    global: 'globals',
    help: 'h',
    verbose: 'v'
  },
  boolean: [
    'format',
    'help',
    'stdin',
    'verbose',
    'version'
  ],
  string: [
    'global',
    'parser'
  ]
})

// running `standard -` is equivalent to `standard --stdin`
if (argv._[0] === '-') {
  argv.stdin = true
  argv._.shift()
}

if (argv.help) {
  console.log(function () {
  /*
standard - JavaScript Standard Style (https://github.com/feross/standard)

Usage:
    standard <flags> [FILES...]

    If FILES is omitted, then all JavaScript source files (*.js, *.jsx) in the current
    working directory are checked, recursively.

    Certain paths (node_modules/, .git/, coverage/, *.min.js, bundle.js) are
    automatically ignored.

Flags:
    -F, --format    Automatically format code (using standard-format)
    -v, --verbose   Show error codes (so you can ignore specific rules)
        --stdin     Check source text on stdin
        --global    Declare global variable
        --parser    Custom js parser (e.g. babel-eslint)
        --version   Show current version
    -h, --help      Show usage information
  */
  }.toString().split(/\n/).slice(2, -2).join('\n'))
  process.exit(0)
}

if (argv.version) {
  console.log(require('../package.json').version)
  process.exit(0)
}

if (argv.stdin) {
  stdin(function (text) {
    if (argv.format) {
      text = standardFormat.transform(text)
      process.stdout.write(text)
    }
    standard.lintText(text, { parser: argv.parser }, onResult)
  })
} else {
  var opts = { parser: argv.parser, global: argv.global }
  if (argv.format) {
    opts._onFiles = function (files) {
      files.forEach(function (file) {
        var data = fs.readFileSync(file).toString()
        fs.writeFileSync(file, standardFormat.transform(data))
      })
    }
  }
  standard.lintFiles(argv._, opts, onResult)
}

function onResult (err, result) {
  if (err) return onError(err)
  if (result.errorCount === 0) process.exit(0)

  console.error(
    'standard: Use JavaScript Standard Style ' +
    '(https://github.com/feross/standard)'
  )

  result.results.forEach(function (result) {
    result.messages.forEach(function (message) {
      log(
        '  %s:%d:%d: %s%s',
        result.filePath, message.line || 0, message.column || 0, message.message,
        argv.verbose ? ' (' + message.ruleId + ')' : ''
      )
    })
  })

  process.exit(1)
}

function onError (err) {
  console.error('standard: Unexpected linter output:\n')
  console.error(err.stack || err.message || err)
  console.error(
    '\nIf you think this is a bug in `standard`, open an issue: ' +
    'https://github.com/feross/standard'
  )
  process.exit(1)
}

/**
 * Print lint errors to stdout since this is expected output from `standard`.
 * Note: When formatting code from stdin (`standard --stdin --format`), the transformed
 * code is printed to stdout, so print lint errors to stderr in this case.
 */
function log () {
  if (argv.stdin && argv.format) {
    arguments[0] = 'standard: ' + arguments[0]
    console.error.apply(console, arguments)
  } else {
    console.log.apply(console, arguments)
  }
}<commit_msg>expected output should go to stdout<commit_after>#!/usr/bin/env node

var fs = require('fs')
var minimist = require('minimist')
var standard = require('../')
var standardFormat = require('standard-format')
var stdin = require('get-stdin')

var argv = minimist(process.argv.slice(2), {
  alias: {
    format: 'F',
    global: 'globals',
    help: 'h',
    verbose: 'v'
  },
  boolean: [
    'format',
    'help',
    'stdin',
    'verbose',
    'version'
  ],
  string: [
    'global',
    'parser'
  ]
})

// running `standard -` is equivalent to `standard --stdin`
if (argv._[0] === '-') {
  argv.stdin = true
  argv._.shift()
}

if (argv.help) {
  console.log(function () {
  /*
standard - JavaScript Standard Style (https://github.com/feross/standard)

Usage:
    standard <flags> [FILES...]

    If FILES is omitted, then all JavaScript source files (*.js, *.jsx) in the current
    working directory are checked, recursively.

    Certain paths (node_modules/, .git/, coverage/, *.min.js, bundle.js) are
    automatically ignored.

Flags:
    -F, --format    Automatically format code (using standard-format)
    -v, --verbose   Show error codes (so you can ignore specific rules)
        --stdin     Check source text on stdin
        --global    Declare global variable
        --parser    Custom js parser (e.g. babel-eslint)
        --version   Show current version
    -h, --help      Show usage information
  */
  }.toString().split(/\n/).slice(2, -2).join('\n'))
  process.exit(0)
}

if (argv.version) {
  console.log(require('../package.json').version)
  process.exit(0)
}

if (argv.stdin) {
  stdin(function (text) {
    if (argv.format) {
      text = standardFormat.transform(text)
      process.stdout.write(text)
    }
    standard.lintText(text, { parser: argv.parser }, onResult)
  })
} else {
  var opts = { parser: argv.parser, global: argv.global }
  if (argv.format) {
    opts._onFiles = function (files) {
      files.forEach(function (file) {
        var data = fs.readFileSync(file).toString()
        fs.writeFileSync(file, standardFormat.transform(data))
      })
    }
  }
  standard.lintFiles(argv._, opts, onResult)
}

function onResult (err, result) {
  if (err) return onError(err)
  if (result.errorCount === 0) process.exit(0)

  console.log(
    'standard: Use JavaScript Standard Style ' +
    '(https://github.com/feross/standard)'
  )

  result.results.forEach(function (result) {
    result.messages.forEach(function (message) {
      log(
        '  %s:%d:%d: %s%s',
        result.filePath, message.line || 0, message.column || 0, message.message,
        argv.verbose ? ' (' + message.ruleId + ')' : ''
      )
    })
  })

  process.exit(1)
}

function onError (err) {
  console.error('standard: Unexpected linter output:\n')
  console.error(err.stack || err.message || err)
  console.error(
    '\nIf you think this is a bug in `standard`, open an issue: ' +
    'https://github.com/feross/standard'
  )
  process.exit(1)
}

/**
 * Print lint errors to stdout since this is expected output from `standard`.
 * Note: When formatting code from stdin (`standard --stdin --format`), print lint errors
 * to stderr, since the transformed code is printed to stdout.
 */
function log () {
  if (argv.stdin && argv.format) {
    arguments[0] = 'standard: ' + arguments[0]
    console.error.apply(console, arguments)
  } else {
    console.log.apply(console, arguments)
  }
}
{'fraction_non_alphanumeric': 0.15434272300469484, 'fraction_numerical': 0.004107981220657277, 'mean_word_length': 2.844895657078398, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 6, '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': '6359543', 'n_tokens_mistral': 2244, 'n_tokens_neox': 2218, 'n_words': 576}