Created
February 20, 2019 09:01
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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