<commit_before>'use strict'

const path = require('path')
const {spawn} = require('child_process')

const CONFIG = require('../config')

module.exports = async function () {
  return new Promise((resolve, reject) => {
    const eslint = spawn(
      path.join('script', 'node_modules', '.bin', 'eslint'),
      ['--cache', '--format', 'json', '.'],
      { cwd: CONFIG.repositoryRootPath }
    )

    let output = ''
    let errorOutput = ''
    eslint.stdout.on('data', data => {
      output += data.toString()
    })

    eslint.stderr.on('data', data => {
      errorOutput += data.toString()
    })

    eslint.on('error', error => reject(error))
    eslint.on('close', exitCode => {
      const errors = []
      let files

      try {
        files = JSON.parse(output)
      } catch (_) {
        reject(errorOutput)
        return
      }

      for (const file of files) {
        for (const error of file.messages) {<commit_msg>Add script/lint --fix which fixes some code formatting issues via eslint<commit_after>'use strict'

const path = require('path')
const {spawn} = require('child_process')
const process = require('process')

const CONFIG = require('../config')

module.exports = async function () {
  return new Promise((resolve, reject) => {
    const eslintArgs = ['--cache', '--format', 'json']

    if (process.argv.includes('--fix')) {
      eslintArgs.push('--fix')
    }

    const eslint = spawn(
      path.join('script', 'node_modules', '.bin', 'eslint'),
      [...eslintArgs, '.'],
      { cwd: CONFIG.repositoryRootPath }
    )

    let output = ''
    let errorOutput = ''
    eslint.stdout.on('data', data => {
      output += data.toString()
    })

    eslint.stderr.on('data', data => {
      errorOutput += data.toString()
    })

    eslint.on('error', error => reject(error))
    eslint.on('close', exitCode => {
      const errors = []
      let files

      try {
        files = JSON.parse(output)
      } catch (_) {
        reject(errorOutput)
        return
      }

      for (const file of files) {
        for (const error of file.messages) {
{'fraction_non_alphanumeric': 0.1658699808795411, 'fraction_numerical': 0.0, 'mean_word_length': 2.459504132231405, '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': '6798364', 'n_tokens_mistral': 641, 'n_tokens_neox': 627, 'n_words': 153}