diff --git a/packages/esify/lib/eslint.js b/packages/esify/lib/eslint.js index 4128230..f7d4e9d 100644 --- a/packages/esify/lib/eslint.js +++ b/packages/esify/lib/eslint.js @@ -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; + }; } diff --git a/packages/esify/lib/index.js b/packages/esify/lib/index.js index d062c8d..6b293ac 100644 --- a/packages/esify/lib/index.js +++ b/packages/esify/lib/index.js @@ -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); }