Skip to content

Instantly share code, notes, and snippets.

@zhirzh
Created February 20, 2019 09:01
Show Gist options
  • Save zhirzh/28eeec102098f97708ee5598bdb5d8e7 to your computer and use it in GitHub Desktop.
Save zhirzh/28eeec102098f97708ee5598bdb5d8e7 to your computer and use it in GitHub Desktop.
flip eslint logs from rules-per-file pattern to files-per-rule pattern
const fs = require('fs')
const path = require('path')
const ESLING_LOG = path.join(__dirname, 'eslint.log')
const STATE = {
EMPTY: 'EMPTY',
FILE: 'FILE',
}
const BUGS = {}
const LOG_PATTERN = /^\s+([\S]*)\s+([\S]*).*\s+([\S]*)$/
let file = ''
let state = STATE.EMPTY
fs.readFileSync(ESLING_LOG, 'utf8')
.split('\n')
.forEach(line => {
if (state === STATE.EMPTY) {
if (line.startsWith('/')) {
file = line
state = STATE.FILE
return
}
}
if (state === STATE.FILE) {
if (line === '') {
file = ''
state = STATE.EMPTY
return
}
const match = line.match(LOG_PATTERN)
if (match === null) {
return
}
const [, position, level, type] = match
const source = `${file}:${position}`
const status = `${level}:${type}`
if (status in BUGS) {
BUGS[status].push(source)
} else {
BUGS[status] = [source]
}
}
})
const logLines = []
Object.keys(BUGS)
.sort()
.forEach(status => {
logLines.push(status)
BUGS[status].sort().forEach(src => {
logLines.push(` ${src}`)
})
logLines.push('')
})
fs.writeFileSync(ESLING_LOG, logLines.join('\n'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment