Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Chore: Only instantiate fileEntryCache when cache flage set (perf) (#…
  • Loading branch information
gyandeeps authored and kaicataldo committed Jun 21, 2017
1 parent 9851288 commit b58ae2e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
27 changes: 16 additions & 11 deletions lib/cli-engine.js
Expand Up @@ -398,15 +398,17 @@ class CLIEngine {
this.options = options;
this.linter = new Linter();

const cacheFile = getCacheFile(this.options.cacheLocation || this.options.cacheFile, this.options.cwd);

/**
* Cache used to avoid operating on files that haven't changed since the
* last successful execution (e.g., file passed linting with no errors and
* no warnings).
* @type {Object}
*/
this._fileCache = fileEntryCache.create(cacheFile);
if (options.cache) {
const cacheFile = getCacheFile(this.options.cacheLocation || this.options.cacheFile, this.options.cwd);

/**
* Cache used to avoid operating on files that haven't changed since the
* last successful execution (e.g., file passed linting with no errors and
* no warnings).
* @type {Object}
*/
this._fileCache = fileEntryCache.create(cacheFile);
}

// load in additional rules
if (this.options.rulePaths) {
Expand Down Expand Up @@ -495,6 +497,11 @@ class CLIEngine {
fileCache = this._fileCache,
configHelper = this.config;
let prevConfig; // the previous configuration used
const cacheFile = getCacheFile(this.options.cacheLocation || this.options.cacheFile, this.options.cwd);

if (!options.cache && fs.existsSync(cacheFile)) {
fs.unlinkSync(cacheFile);
}

/**
* Calculates the hash of the config file used to validate a given file
Expand Down Expand Up @@ -570,8 +577,6 @@ class CLIEngine {
// move to the next file
return;
}
} else {
fileCache.destroy();
}

debug(`Processing ${filename}`);
Expand Down
2 changes: 2 additions & 0 deletions tests/lib/cli-engine.js
Expand Up @@ -1324,6 +1324,8 @@ describe("CLIEngine", () => {
fakeFS.realpathSync = function() {
throw new Error("this error should not happen");
};
fakeFS.existsSync = fs.existsSync;
fakeFS.unlinkSync = fs.unlinkSync;

engine = new LocalCLIEngine({
ignorePattern: "tests"
Expand Down

0 comments on commit b58ae2e

Please sign in to comment.