Skip to content

Commit

Permalink
Merge 309078d into aeb2042
Browse files Browse the repository at this point in the history
  • Loading branch information
KamiKillertO committed May 21, 2020
2 parents aeb2042 + 309078d commit cbbc47f
Show file tree
Hide file tree
Showing 11 changed files with 570 additions and 308 deletions.
15 changes: 8 additions & 7 deletions lib/cli/index.js
Expand Up @@ -124,12 +124,11 @@ function exitProcess(is_errored = false) {
return process.exit(exit_code);
}

async function getLinter(config) {
async function checkLinterConfig(config) {
const configSpinner = ora("Checking rules config").start();
try {
const linter = await linthtml.fromConfig(config);
await linthtml.fromConfig(config);
configSpinner.succeed();
return linter;
} catch (error) {
configSpinner.fail();
console.log();
Expand All @@ -139,15 +138,15 @@ async function getLinter(config) {
}

async function lint(input, config) {
const linter = await getLinter(config);
await checkLinterConfig(config);

const searchSpinner = ora("Searching for files").start();
const lintSpinner = ora("Analysing files").start();
let files = await getFilesToLint(input, config);
searchSpinner.succeed(`Found ${files.length} files`);
files = files.map(getFileContent);
try {
let reports = await Promise.all(files.map(file => lintFile(file, linter, config)));
let reports = await Promise.all(files.map(file => lintFile(file, config)));
reports = reports.filter(report => report.issues.length > 0);
lintSpinner.succeed();
printReports(reports);
Expand Down Expand Up @@ -228,9 +227,11 @@ function getFileContent(name) {
};
}

async function lintFile(file, linter, config) {
async function lintFile(file, config) {
try {
const issues = await linter.lint(file.content, config);
const linter = await linthtml.fromConfig(config); // await needed by legacy linter

const issues = await linter.lint(file.content, config); // config needed by legacy linter
return { fileName: file.name, issues };
} catch (error) {
error.fileName = file.name;
Expand Down
1 change: 0 additions & 1 deletion lib/cli/read-config.js
Expand Up @@ -23,7 +23,6 @@ module.exports.config_from_path = function(file_path) {
} catch (error) {
if (isConfigDirectory) {
throw new CustomError("CLI-01", { config_path });
// console.log(`{red Error:} Cannot read config file in directory: {underline ${config_path}}`);
}
throw new CustomError("CLI-02", { config_path });
}
Expand Down
13 changes: 6 additions & 7 deletions lib/config.js
@@ -1,7 +1,8 @@
class NonExistingRule extends Error {
constructor(message) {
super(message);
constructor(rule_name) {
super(`Rule "${rule_name}" does not exist.`);
this.name = "NonExistingRule";
this.rule_name = rule_name;
}
}
class InvalidRuleConfig extends Error {
Expand Down Expand Up @@ -93,6 +94,7 @@ function extractAllRules(rules) {
}

/**
* @class Config
* @constructor
* @param {} rules -
* @param {} config -
Expand Down Expand Up @@ -139,7 +141,7 @@ class Config {
getRule(ruleName) {
const rule = this.rules[ruleName];
if (rule === undefined) {
throw new NonExistingRule(`Rule "${ruleName}" does not exist.`);
throw new NonExistingRule(ruleName);
}
return rule;
}
Expand All @@ -161,12 +163,9 @@ class Config {
rule.validateConfig(ruleConfig);
}
}
// this.activateRules[ruleName] = Object.create(rule);
this.activatedRules[rule.name].severity = getSeverity(config[rule.name]);
this.activatedRules[rule.name].config = ruleConfig;
}/* else {
delete this.activateRules[rule.name];
} */ // ?
}
}

generateLegacyConfig(config) {
Expand Down

0 comments on commit cbbc47f

Please sign in to comment.