Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ESLint resource hogging #177

Merged
merged 1 commit into from
Jun 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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