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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: ensure configs from a plugin are cached separately (fixes #8792) #8798

Merged
merged 3 commits into from Jun 26, 2017

Conversation

not-an-aardvark
Copy link
Member

What is the purpose of this pull request? (put an "X" next to item)

[x] Bug fix (#8792)

What changes did you make? (Give an overview)

Config files are cached by file path to avoid needing to load the same config file twice. However, configs provided by plugins all have the same file path (the index file of the plugin). This created a bug when loading multiple configs for the same plugin where only the highest-precedence config from that plugin would be loaded. All other configs from that plugin would be considered identical by the cache, so they would all end up getting pulled from the cache as the same config.

This commit updates the caching logic to use the config full name as a cache index. This is still the file path when resolving a config from the filesystem, but it is the unique plugin config identifier (e.g. 'plugin:foo/node-config') when resolving a plugin config.

Is there anything you'd like reviewers to focus on?

Are there any other places where we assume that the filePath of a resolved config is unique?

Config files are cached by file path to avoid needing to load the same config file twice. However, configs provided by plugins all have the same file path (the index file of the plugin). This created a bug when loading multiple configs for the same plugin where only the highest-precedence config from that plugin would be loaded. All other configs from that plugin would be considered identical by the cache, so they would all end up getting pulled from the cache as the same config.

This commit updates the caching logic to use the config full name as a cache index. This is still the file path when resolving a config from the filesystem, but it is the unique plugin config identifier (e.g. 'plugin:foo/node-config') when resolving a plugin config.
@not-an-aardvark not-an-aardvark added accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly core Relates to ESLint's core APIs and features patch candidate This issue may necessitate a patch release in the next few days regression Something broke labels Jun 25, 2017
@eslintbot
Copy link

LGTM

@mention-bot
Copy link

@not-an-aardvark, thanks for your PR! By analyzing the history of the files in this pull request, we identified @nzakas, @mysticatea and @smably to be potential reviewers.

Copy link
Contributor

@smably smably left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to hear about the bugs in this release. I was worried that might happen. Thanks for cleaning up my mess!

@@ -524,7 +527,7 @@ function resolve(filePath, relativeTo) {
function loadFromDisk(resolvedPath, configContext) {
const dirname = path.dirname(resolvedPath.filePath),
lookupPath = getLookupPath(dirname);
let config = loadConfigFile(resolvedPath);
let config = loadConfigFile(resolvedPath, configContext);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loadConfigFile doesn't seem to take a second argument. Was this change deliberate?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, this was unintentional, thanks. While working on this I initially considered adding a second argument to loadConfigFile, but then I forgot to remove it here.

@eslintbot
Copy link

LGTM

@not-an-aardvark
Copy link
Member Author

not-an-aardvark commented Jun 25, 2017

Sorry to hear about the bugs in this release. I was worried that might happen. Thanks for cleaning up my mess!

No worries -- the codebase probably should have had more tests for this even before you started working on it. 😅

Configs are complicated. It's hard to tell whether a change will break something if it's untested, especially if you haven't worked on the codebase before.

@smably
Copy link
Contributor

smably commented Jun 25, 2017

Yes, very complicated, as I discovered even before these bugs appeared!

Copy link
Member

@platinumazure platinumazure left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some small comment updates, otherwise this LGTM, thanks!

this.localHierarchyCache = new Map();
this.mergedVectorCache = new Map();
this.mergedCache = new Map();
}

/**
* Gets a config object from the cache for the specified config file path.
* @param {string} configFilePath the absolute path to the config file
* @param {string} configFullName the absolute path to the config file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this line be updated to match lib/config/config-file.js lines 491-492?

}

/**
* Sets a config object in the cache for the specified config file path.
* @param {string} configFilePath the absolute path to the config file
* @param {string} configFullName the absolute path to the config file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this line be updated to match lib/config/config-file.js lines 491-492?

@eslintbot
Copy link

LGTM

@not-an-aardvark
Copy link
Member Author

@platinumazure Updated, good catch.

Copy link
Member

@platinumazure platinumazure left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly core Relates to ESLint's core APIs and features patch candidate This issue may necessitate a patch release in the next few days regression Something broke
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants