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: prefer-const false negative about eslintUsed (fixes #5837) #6971

Merged
merged 1 commit into from Aug 26, 2016

Conversation

mysticatea
Copy link
Member

@mysticatea mysticatea commented Aug 24, 2016

Fixes #5837.

This PR makes prefer-const warning used variables by context.markVariableAsUsed(name) API, on except global scope.

/*exported*/ comments also are using eslintUsed.
I thought prefer-const should not warn foo in the following code.

/*exported foo*/
let foo = 1

prefer-const still ignore used global variables by context.markVariableAsUsed(name) API (since /*exported*/ comment is applied to only global variables).
But this PR will improve the issue.
In most cases, the variables that react/jsx-use-vars marks are on Node.js/CommonJS scope or Module scope.

EDIT: This needs minor bump since this will increase warnings.

@mention-bot
Copy link

@mysticatea, thanks for your PR! By analyzing the annotation information on this pull request, we identified @NickHeiner, @vitorbal and @nzakas to be potential reviewers

@eslintbot
Copy link

LGTM

@@ -82,7 +82,7 @@ function canBecomeVariableDeclaration(identifier) {
* Otherwise, null.
*/
function getIdentifierIfShouldBeConst(variable, ignoreReadBeforeAssign) {
if (variable.eslintUsed) {
if (variable.eslintUsed && variable.scope.type === "global") {
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment in the JSDoc to explain why you're checking for global scope?

@nzakas
Copy link
Member

nzakas commented Aug 24, 2016

Lgtm, just one note about updating a comment to explain this change.

@eslintbot
Copy link

LGTM

1 similar comment
@ilyavolodin
Copy link
Member

LGTM

@nzakas nzakas merged commit ca3d448 into master Aug 26, 2016
@mysticatea mysticatea deleted the issue5837 branch August 27, 2016 08:13
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 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 Feb 6, 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants