Created
September 29, 2017 06:36
-
-
Save iulia-codes/c97915e6292a7688e5f07c87b804b88c to your computer and use it in GitHub Desktop.
Setting up a simple linter
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
//https://github.com/natelistrom/sturdy-octo-broccoli/blob/32eddcf0b8f9e22bf7e1f98cc32ee1da75d4ac6e/scripts/parallel-lint.js | |
var Linter = require("tslint"); | |
var fs = require("fs"); | |
function getLinterOptions() { | |
return { | |
configuration: require("../tslint.json"), | |
formatter: "prose", | |
formattersDirectory: undefined, | |
rulesDirectory: "built/local/tslint" | |
}; | |
} | |
function lintFileContents(options, path, contents) { | |
var ll = new Linter(path, contents, options); | |
return ll.lint(); | |
} | |
function lintFileAsync(options, path, cb) { | |
fs.readFile(path, "utf8", function (err, contents) { | |
if (err) { | |
return cb(err); | |
} | |
var result = lintFileContents(options, path, contents); | |
cb(undefined, result); | |
}); | |
} | |
process.on("message", function (data) { | |
switch (data.kind) { | |
case "file": | |
var target = data.name; | |
var lintOptions = getLinterOptions(); | |
lintFileAsync(lintOptions, target, function (err, result) { | |
if (err) { | |
process.send({ kind: "error", error: err.toString() }); | |
return; | |
} | |
process.send({ kind: "result", failures: result.failureCount, output: result.output }); | |
}); | |
break; | |
case "close": | |
process.exit(0); | |
break; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment