Last active
February 24, 2019 08:34
-
-
Save jinjor/cce51986afa422a3e38befebe091ead2 to your computer and use it in GitHub Desktop.
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 childProcess = require("child_process"); | |
childProcess.exec("./node_modules/.bin/elm-analyse", (e, out) => { | |
let file; | |
let all = {}; | |
for (let line of out.split("\n")) { | |
if (line.startsWith("-")) { | |
file = line.slice(2); | |
continue; | |
} | |
const matched = line.match( | |
/.*Unused import `.*at.*\(\((\d+),(\d+)\),\((\d+),(\d+)\)\)/ | |
); | |
if (matched) { | |
if (!all[file]) { | |
all[file] = []; | |
} | |
const [start, end] = [+matched[1], +matched[3]]; | |
all[file].push({ start, end }); | |
} | |
} | |
for (let file in all) { | |
const contentArray = fs.readFileSync(file, "utf8").split("\n"); | |
const ranges = all[file]; | |
ranges.forEach(({ start, end }) => { | |
for (let i = start - 1; i < end; i++) { | |
contentArray[i] = null; | |
} | |
}); | |
const content = contentArray.filter(s => s !== null).join("\n"); | |
fs.writeFileSync(file, content); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment