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

Declare variables before use #6806

Merged
merged 1 commit into from
Jul 5, 2019
Merged

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Jul 4, 2019

While working on #6805, I noticed that many variables were being used before they were declared. Technically this worked fine in practice because we were using the transform-es2015-block-scoping Babel plugin, which transforms let and const to var, which is hoisted. However, after removing that Babel transformation, many things broke.

All instances of variables or classes being used before declared have been fixed.

The no-use-before-define eslint rule has been added to catch these cases going forward. The rule is disabled for function declarations for the moment, because those are always hoisted. We could disable that too if we want to, but it's purely stylistic and would require a lot more changes.

@Gudahtt Gudahtt requested review from danjm and whymarrh as code owners July 4, 2019 16:33
@Gudahtt Gudahtt force-pushed the declare-before-use branch from 163821f to de9be90 Compare July 4, 2019 17:14
While working on MetaMask#6805, I noticed that many variables were being used
before they were declared. Technically this worked fine in practice
because we were using the `transform-es2015-block-scoping` Babel plugin,
which transforms `let` and `const` to `var`, which is hoisted. However,
after removing that Babel transformation, many things broke.

All instances of variables or classes being used before declared have
been fixed.

The `no-use-before-define` eslint rule has been added to catch these
cases going forward. The rule is disabled for function declarations for
the moment, because those are always hoisted. We could disable that too
if we want to, but it's purely stylistic and would require a lot more
changes.
@Gudahtt Gudahtt force-pushed the declare-before-use branch from de9be90 to ca62b14 Compare July 4, 2019 22:12
Copy link
Contributor

@danjm danjm left a comment

Choose a reason for hiding this comment

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

👏

Copy link
Contributor

@whymarrh whymarrh left a comment

Choose a reason for hiding this comment

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

Yes

@Gudahtt Gudahtt merged commit 95f1985 into MetaMask:develop Jul 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants