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

Chore: small opt to improve readability #10241

Merged
merged 2 commits into from
Jun 9, 2018

Conversation

aladdin-add
Copy link
Member

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

[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[x] Other, please explain:

What changes did you make? (Give an overview)
use config.unshift() to avoid calling config.reverse() -- more clear, and a little perf win.

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

@aladdin-add aladdin-add added the chore This change is not user-facing label Apr 19, 2018
@platinumazure
Copy link
Member

I see configs are being set in reverse order (from their current setting), but I don't see a corresponding change in whichever module is reading from this.configCache. Do we need to ensure that the cached configurations are read in a different order?

@aladdin-add
Copy link
Member Author

not sure why reverse order -- the change was just as-is.

@@ -209,7 +209,7 @@ class Config {
const localConfigHierarchyCache = this.configCache.getHierarchyLocalConfigs(localConfigDirectory);

if (localConfigHierarchyCache) {
const localConfigHierarchy = localConfigHierarchyCache.concat(configs.reverse());
const localConfigHierarchy = localConfigHierarchyCache.concat(configs);

this.configCache.setHierarchyLocalConfigs(searched, localConfigHierarchy);
return localConfigHierarchy;
Copy link
Member

Choose a reason for hiding this comment

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

I'm confused about this part of the change. Since localConfigHierarchy is returned here, it seems like this change will affect the behavior of the function, because localConfigHierarchy will have some configs in the wrong order. Is this intentional?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure it's wrong order -- I replaced all configs.push(localConfig); => configs.unshift(localConfig); , so configs could always be reverse (same ) order as before. am I missing something?

Copy link
Member

Choose a reason for hiding this comment

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

Since configs is used on line 212 instead of configs.reverse(), the configs will be stored in the cache in the opposite order from before.

This isn't necessarily a problem if this function is the only function that reads from that cache, but it could cause a problem if there are other parts of the code that read from the cache and expect the reverse order.

Copy link
Member Author

Choose a reason for hiding this comment

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

oh, sorry for misleading. Actually configs would be always reverse order, so the line 212 is the same as before configs.reverse().

image

@platinumazure
Copy link
Member

@not-an-aardvark Are your concerns addressed here?

@kaicataldo kaicataldo merged commit a370da2 into eslint:master Jun 9, 2018
@kaicataldo
Copy link
Member

Thanks for contributing!

@aladdin-add aladdin-add deleted the chore/opt-config branch June 9, 2018 20:39
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Dec 8, 2018
@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 Dec 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion chore This change is not user-facing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants