Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Only instantiate fileEntryCache when cache flage set (perf) #8763

Merged
merged 1 commit into from Jun 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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