Skip to content

Commit

Permalink
Fix ESLint resource hogging (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
lemonmade authored Jun 15, 2016
1 parent 2ca4167 commit 878d08f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
26 changes: 13 additions & 13 deletions packages/esify/lib/eslint.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
var proc = require('child_process');
var path = require('path');
var fs = require('fs');
// This looks gross, but we don't want to fail if they don't have ESLint installed
// locally.

module.exports = function runESLint(details) {
return new Promise(function(resolve) {
var eslint = findESLintBinary();
if (eslint == null) { return; }
proc.exec(eslint + ' ' + details.file + ' --fix', resolve);
});
};
try {
// eslint-disable-next-line node/no-unpublished-require
var CLIEngine = require('eslint').CLIEngine;
var engine = new CLIEngine({fix: true});

function findESLintBinary() {
var possibleBinary = path.join(proc.execSync('npm bin').toString().trim(), 'eslint');
return fs.statSync(possibleBinary).isFile() ? possibleBinary : null;
module.exports = function runESLint(details) {
console.log(engine.executeOnText(details.source).results[0].output);
};
} catch (err) {
module.exports = function runESLint(details) {
return details.source;
};
}
9 changes: 3 additions & 6 deletions packages/esify/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,15 @@ function handleFile(filePath) {
try {
var decaffed = runDecaf({source: source, file: filePath, options: config});
var codemoded = runCodemods({source: decaffed, file: filePath, options: config});
var linted = runESLint({source: codemoded, file: filePath, options: config});

var newFile = path.join(
path.dirname(filePath),
path.basename(filePath, '.coffee').replace(/_/g, '-') + '.js'
);

fs.writeFileSync(newFile, codemoded);

runESLint({file: newFile})
.then(function() {
console.log(filePath + ' => ' + newFile);
});
fs.writeFileSync(newFile, linted);
console.log(filePath + ' => ' + newFile);
} catch (error) {
handleError(filePath, error);
}
Expand Down

0 comments on commit 878d08f

Please sign in to comment.