summaryrefslogtreecommitdiff
path: root/tools/node_modules/eslint/lib/cli-engine.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/node_modules/eslint/lib/cli-engine.js')
-rw-r--r--tools/node_modules/eslint/lib/cli-engine.js95
1 files changed, 28 insertions, 67 deletions
diff --git a/tools/node_modules/eslint/lib/cli-engine.js b/tools/node_modules/eslint/lib/cli-engine.js
index 9cab3b47b2..8442de2def 100644
--- a/tools/node_modules/eslint/lib/cli-engine.js
+++ b/tools/node_modules/eslint/lib/cli-engine.js
@@ -21,10 +21,9 @@ const fs = require("fs"),
Linter = require("./linter"),
IgnoredPaths = require("./ignored-paths"),
Config = require("./config"),
- fileEntryCache = require("file-entry-cache"),
+ LintResultCache = require("./util/lint-result-cache"),
globUtil = require("./util/glob-util"),
validator = require("./config/config-validator"),
- stringify = require("json-stable-stringify-without-jsonify"),
hash = require("./util/hash"),
ModuleResolver = require("./util/module-resolver"),
naming = require("./util/naming"),
@@ -359,8 +358,6 @@ function getCacheFile(cacheFile, cwd) {
return resolvedCacheFile;
}
-const configHashCache = new WeakMap();
-
//------------------------------------------------------------------------------
// Public Interface
//------------------------------------------------------------------------------
@@ -403,18 +400,6 @@ class CLIEngine {
this.options = options;
this.linter = new Linter();
- 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) {
const cwd = this.options.cwd;
@@ -434,6 +419,17 @@ class CLIEngine {
}
this.config = new Config(this.options, this.linter);
+
+ if (this.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.
+ * @type {Object}
+ */
+ this._lintResultCache = new LintResultCache(cacheFile, this.config);
+ }
}
getRules() {
@@ -506,7 +502,7 @@ class CLIEngine {
*/
executeOnFiles(patterns) {
const options = this.options,
- fileCache = this._fileCache,
+ lintResultCache = this._lintResultCache,
configHelper = this.config;
const cacheFile = getCacheFile(this.options.cacheLocation || this.options.cacheFile, this.options.cwd);
@@ -514,21 +510,6 @@ class CLIEngine {
fs.unlinkSync(cacheFile);
}
- /**
- * Calculates the hash of the config file used to validate a given file
- * @param {string} filename The path of the file to retrieve a config object for to calculate the hash
- * @returns {string} the hash of the config
- */
- function hashOfConfigFor(filename) {
- const config = configHelper.getConfig(filename);
-
- if (!configHashCache.has(config)) {
- configHashCache.set(config, hash(`${pkg.version}_${stringify(config)}`));
- }
-
- return configHashCache.get(config);
- }
-
const startTime = Date.now();
const fileList = globUtil.listFilesToProcess(patterns, options);
const results = fileList.map(fileInfo => {
@@ -543,20 +524,12 @@ class CLIEngine {
* with the metadata and the flag that determines if
* the file has changed
*/
- const descriptor = fileCache.getFileDescriptor(fileInfo.filename);
- const hashOfConfig = hashOfConfigFor(fileInfo.filename);
- const changed = descriptor.changed || descriptor.meta.hashOfConfig !== hashOfConfig;
-
- if (!changed) {
- debug(`Skipping file since hasn't changed: ${fileInfo.filename}`);
-
- /*
- * Add the the cached results (always will be 0 error and
- * 0 warnings). We should not cache results for files that
- * failed, in order to guarantee that next execution will
- * process those files as well.
- */
- return descriptor.meta.results;
+ const cachedLintResults = lintResultCache.getCachedLintResults(fileInfo.filename);
+
+ if (cachedLintResults) {
+ debug(`Skipping file since it hasn't changed: ${fileInfo.filename}`);
+
+ return cachedLintResults;
}
}
@@ -567,30 +540,18 @@ class CLIEngine {
if (options.cache) {
results.forEach(result => {
- if (result.messages.length) {
-
- /*
- * if a file contains errors or warnings we don't want to
- * store the file in the cache so we can guarantee that
- * next execution will also operate on this file
- */
- fileCache.removeEntry(result.filePath);
- } else {
-
- /*
- * since the file passed we store the result here
- * TODO: it might not be necessary to store the results list in the cache,
- * since it should always be 0 errors/warnings
- */
- const descriptor = fileCache.getFileDescriptor(result.filePath);
-
- descriptor.meta.hashOfConfig = hashOfConfigFor(result.filePath);
- descriptor.meta.results = result;
- }
+
+ /*
+ * Store the lint result in the LintResultCache.
+ * NOTE: The LintResultCache will remove the file source and any
+ * other properties that are difficult to serialize, and will
+ * hydrate those properties back in on future lint runs.
+ */
+ lintResultCache.setCachedLintResults(result.filePath, result);
});
// persist the cache to disk
- fileCache.reconcile();
+ lintResultCache.reconcile();
}
const stats = calculateStatsPerRun(results);