From 22a1e2056bcbce795775abebe39fba647adc53b1 Mon Sep 17 00:00:00 2001 From: Steven Hobson-Campbell Date: Mon, 15 May 2017 19:23:07 -0700 Subject: [PATCH] Fixing error handling from worker. Also accounting for errors finding config. file --- lib/worker.js | 59 ++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/lib/worker.js b/lib/worker.js index f59bc869..19b93459 100644 --- a/lib/worker.js +++ b/lib/worker.js @@ -135,43 +135,44 @@ async function lint(content, filePath, options) { return null; } - const Linter = await getLinter(filePath); - const configurationPath = Linter.findConfigurationPath(null, filePath); - const configuration = Linter.loadConfigurationFromPath(configurationPath); - - let { rulesDirectory } = configuration; - if (rulesDirectory && configurationPath) { - const configurationDir = path.dirname(configurationPath); - if (!Array.isArray(rulesDirectory)) { - rulesDirectory = [rulesDirectory]; - } - rulesDirectory = rulesDirectory.map((dir) => { - if (path.isAbsolute(dir)) { - return dir; + let lintResult; + try { + const Linter = await getLinter(filePath); + const configurationPath = Linter.findConfigurationPath(null, filePath); + const configuration = Linter.loadConfigurationFromPath(configurationPath); + + let { rulesDirectory } = configuration; + if (rulesDirectory && configurationPath) { + const configurationDir = path.dirname(configurationPath); + if (!Array.isArray(rulesDirectory)) { + rulesDirectory = [rulesDirectory]; } - return path.join(configurationDir, dir); - }); + rulesDirectory = rulesDirectory.map((dir) => { + if (path.isAbsolute(dir)) { + return dir; + } + return path.join(configurationDir, dir); + }); - if (config.rulesDirectory) { - rulesDirectory.push(config.rulesDirectory); + if (config.rulesDirectory) { + rulesDirectory.push(config.rulesDirectory); + } } - } - let program; - if (config.enableSemanticRules && configurationPath) { - program = await getProgram(Linter, configurationPath); - } - const linter = new Linter(Object.assign({ - formatter: 'json', - rulesDirectory, - }, options), program); + let program; + if (config.enableSemanticRules && configurationPath) { + program = await getProgram(Linter, configurationPath); + } + + const linter = new Linter(Object.assign({ + formatter: 'json', + rulesDirectory, + }, options), program); - let lintResult; - try { linter.lint(filePath, content, configuration); lintResult = linter.getResult(); } catch (err) { - console.error(err); // eslint-disable-line no-console + console.error(err.message, err.stack); // eslint-disable-line no-console lintResult = {}; }