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

Fixing error handling from worker. Also accounting for errors finding config. file #169

Merged
merged 1 commit into from
May 17, 2017
Merged
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
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