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

Docs: list another related rule in no-undefined #8467

Merged
merged 2 commits into from
Apr 23, 2017

Conversation

ethanresnick
Copy link
Contributor

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

[x] 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
[ ] Other, please explain:

What changes did you make? (Give an overview)

Addded no-shadow-restricted-names as a related rule to no-undefined's documentation, because some people might want to flag all shadowing of undefined (as the former does) and then not use the no-undefined rule.

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

@mention-bot
Copy link

@ethanresnick, thanks for your PR! By analyzing the history of the files in this pull request, we identified @nzakas, @michaelficarra and @BYK to be potential reviewers.

@jsf-clabot
Copy link

jsf-clabot commented Apr 16, 2017

CLA assistant check
All committers have signed the CLA.

@eslintbot
Copy link

LGTM

@platinumazure
Copy link
Member

Hi @ethanresnick, thanks for the PR!

Hmm... This is a tough one for me. It's a pretty limited sort of relationship and potentially one should also link no-restricted-globals for non-shadowing cases, and then you have two tenuous "related rules".

I wonder if there should instead be a paragraph somewhere higher in the documentation which says all uses of undefined are forbidden by this rule and that anyone who just wants to avoid reassignments to undefined should use rules X and Y...

If others on the team think this is okay as is, I definitely don't want to stand in the way. I just wanted to throw out a thought, that's all.

@not-an-aardvark not-an-aardvark added the documentation Relates to ESLint's documentation label Apr 18, 2017
Copy link
Member

@not-an-aardvark not-an-aardvark left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks!

@not-an-aardvark
Copy link
Member

@platinumazure If it helps as a datapoint, I hadn't realized that no-shadow-restricted-names existed, so this PR was useful to me. 😄

@platinumazure
Copy link
Member

@not-an-aardvark Thanks, makes sense.

I'm just worried that the change might be incomplete. no-shadow-restricted-names picks up on new variable declarations that shadow the undefined global:

var undefined = "true";

It won't pick up on reassignments:

undefined = "true";

So I think we should figure out what we want to recommend for that case and include that in this change.

@not-an-aardvark
Copy link
Member

I agree that it's not a drop-in replacement, but the rules do share some functionality, so I think it's reasonable to call them "related".

@platinumazure
Copy link
Member

@not-an-aardvark I have no problem with including no-shadow-restricted-names as a related rule anymore, I promise. I just want to make sure the reassign case is also covered.

@ethanresnick
Copy link
Contributor Author

@platinumazure How would you suggest I edit this to cover the reassign case?

@platinumazure
Copy link
Member

@ethanresnick Looks like no-global-assign will treat undefined as a "read-only" (or at least "shouldn't be modified") global by default, so I think it might be sufficient to add that users might also consider using no-global-assign as well as no-shadow-restricted-names in order to avoid reassignments to or shadowing of undefined but allowing reads of that same variable.

So if you just add no-global-assign to the Related Rules and a quick paragraph in the rule details about using those two rules to block reassigns to undefined while still allowing the use of the rule, then I'll be happy. 😄

@eslintbot
Copy link

LGTM

@ethanresnick
Copy link
Contributor Author

@platinumazure That makes sense. I've updated the PR to reference no-global-assign too. In the process of adding the new paragraph, I tried to clean up the prose a bit too, so things would still flow.

@eslintbot
Copy link

LGTM

@eslintbot
Copy link

LGTM

@platinumazure
Copy link
Member

Looks like you have some markdown linting errors (trailing space); please review and fix at your convenience and let us know if you need help. Thanks!

@eslintbot
Copy link

LGTM

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 a few small requested changes about the narrative flow of the documentation. Basically, we can't really say that being undefined-free is "alternative" in this rule because that is the whole point of the rule. Instead, using no-shadow-restricted-names and no-global-assign should be regarded as "alternative" and should be written second (IMO).

Sorry for all the nitpicks. I'm really looking forward to landing this once we can get the flow in the right order!

@@ -14,24 +14,15 @@ function doSomething(data) {
}
```

This represents a problem for `undefined` that doesn't exist for `null`, which is a keyword and primitive value that can neither be overwritten nor shadowed.
Because `undefined` can be overwritten or shadowed, reading `undefined` can give an unexpected value. (This is not the case for `null`, which is a keyword that always produces the same value.) To guard against this, you can use the [no-global-assign](no-global-assign.md) and [no-shadow-restricted-names](no-shadow-restricted-names.md) rules.
Copy link
Member

Choose a reason for hiding this comment

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

I like the changes you make before "To guard against this"; however, I think it would make more sense to extract the rest to its own paragraph and make it clear that that is an alternative to using this rule to flag all uses of undefined. (And I would put that paragraph below the next one-- see comment below.)

See comment below


All uninitialized variables automatically get the value of `undefined`:
Alternatively, you can avoid all uses of `undefined`, which is what some style guides recommend. Those style guides then recommend:
Copy link
Member

Choose a reason for hiding this comment

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

In the context of this rule, it doesn't make sense to say an undefined-free coding style is "alternative". In this rule, that would be the primary use case. So I would lead this paragraph by saying that this rule allows you to avoid all uses of undefined. Then, below the style guide recommendations, I would suggest moving the excerpt I called out above (starting with "To guard against this") and make that paragraph the new "alternative" paragraph.

The alternative to using this rule (for flagging all uses of undefined) is to enable those two rules, which will flag writes to undefined but allow reads.

Hope this makes sense and doesn't sound arbitrary. Let me know if I can clarify anything!

@eslintbot
Copy link

LGTM

@ethanresnick
Copy link
Contributor Author

@platinumazure Your feedback makes perfect sense, and I've updated the PR to address it. Lmk if anything else needs work, or if you want me to squash the commits.

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 so much for making those changes! I'm gonna leave this open to make sure other team members can review.

@platinumazure
Copy link
Member

@not-an-aardvark Since your review, a few changes have been made, mostly at my suggestion. Please feel free to re-review if you wish.

Copy link
Member

@not-an-aardvark not-an-aardvark 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 for working on this!

@not-an-aardvark not-an-aardvark merged commit 9c3da77 into eslint:master Apr 23, 2017
@ethanresnick ethanresnick deleted the patch-1 branch April 24, 2017 04:03
@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 documentation Relates to ESLint's documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants