Skip to content

Commit

Permalink
Refactor CLIEngine piece based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nzakas committed Nov 6, 2018
1 parent 7e80da5 commit 5e1c448
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/cli-engine.js
Expand Up @@ -475,14 +475,17 @@ class CLIEngine {
// setup special filter for fixes
if (this.options.fix && this.options.fixTypes && this.options.fixTypes.length > 0) {

debug(`Using fix types ${this.options.fixTypes}`);

// throw an error if any invalid fix types are found
validateFixTypes(this.options.fixTypes);

// convert to Set for faster lookup
const fixTypes = new Set(this.options.fixTypes);

// save original value of options.fix in case it's a function
const originalFix = this.options.fix;
const originalFix = (typeof this.options.fix === "function")
? this.options.fix : () => this.options.fix;

// create a cache of rules (but don't populate until needed)
this._rulesCache = null;
Expand All @@ -491,7 +494,7 @@ class CLIEngine {
const rule = this._rulesCache.get(lintResult.ruleId);
const matches = rule.meta && fixTypes.has(rule.meta.type);

return matches && (typeof originalFix === "function" ? originalFix(lintResult) : true);
return matches && originalFix(lintResult);
};
}

Expand Down

0 comments on commit 5e1c448

Please sign in to comment.