Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Commit

Permalink
Fixing error handling from worker. Also accounting for errors finding…
Browse files Browse the repository at this point in the history
… config. file (#169)
  • Loading branch information
Xapphire13 authored May 17, 2017
1 parent 2100cb4 commit 7bf059f
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions lib/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
}

Expand Down

0 comments on commit 7bf059f

Please sign in to comment.