Skip to content

declare var to fix scope error #15265

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

Merged
merged 1 commit into from
May 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ define([
}

if (parent && config && config.length) {
for (i = 0; i < config.length; i++) {
for (var i = 0; i < config.length; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @kieronthomas, thank you for collaboration.
According to Magento Code Style guideline we should declare a variables in the top of the function.

Choose a reason for hiding this comment

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

@VladimirZaets nothing to do with me, I think you meant to refer to @keithbentrup ^

Copy link
Contributor Author

@keithbentrup keithbentrup May 17, 2018

Choose a reason for hiding this comment

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

Ok @VladimirZaets so update it accordingly if you need to. It's a P1 ticket that's crashing browsers. Fix it and move on.

Incidentally, that rule may be part of the reason why the error exists in the first place ... with this perhaps ill-advised rule, declaring vars far removed from their use.

For your consideration,

  1. https://stackoverflow.com/questions/5053073/is-defining-every-variable-at-the-top-always-the-best-approach
  2. https://medium.com/@bluepnume/theres-no-need-to-define-all-javascript-vars-once-at-the-top-of-a-function-and-there-hasn-t-been-a66b31f21822

Also linking to the whole style guide without linking to the specific rule isn't particularly helpful. You're asking contributors to follow rules that you can't even find/link to.

I couldn't even find the rule googling and limiting the domain to just site:devdocs.magento.com. The most relevant section that I could find with a bit of searching which has no mention of declaring it at the top: https://devdocs.magento.com/guides/v2.3/coding-standards/code-standard-javascript.html#variable-declarations. You have to go parse the eslint configuration json to actually find the rule you're bringing up.

Lastly, I doubt you're going to fix all the other unrelated errors picked up by the linter for this file, so arbitrarily fixing it for these and not others seems capricious.

Anyway, I'm more concerned with this being resolved. You now know the cause of the error and the solution. You don't need anything further from me to bring it to a resolution.

Copy link
Contributor

Choose a reason for hiding this comment

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

@keithbentrup if there is such rule we cannot violate it. Changing existing conventions is out of scope for PR processing.

@VladimirZaets we can probably move var declaration to a proper place on our side as an additional commit.

categoryLoader.processCategoryTree(parent, config, i);
}
}
Expand All @@ -185,7 +185,7 @@ define([
if ((node.childNodes.length > 0) || (node.loaded === false && node.loading === false)) {
hash.children = [];

for (i = 0, len = node.childNodes.length; i < len; i++) {
for (var i = 0, len = node.childNodes.length; i < len; i++) {
/* eslint-disable */
if (!hash.children) {
hash.children = [];
Expand Down