-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New: symbol-description
rule (fixes #6778)
#6825
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
Conversation
@jrencz, thanks for your PR! By analyzing the annotation information on this pull request, we identified @nzakas, @alberto and @kaicataldo to be potential reviewers |
LGTM |
b53b42b
to
57f7be5
Compare
LGTM |
Thank you for this PR! I added |
+1 |
Issue has been accepted. |
@@ -0,0 +1,94 @@ | |||
# Require/Disallow Symbol Description (symbol-description) | |||
|
|||
The `Symbol` constructor may have optional description: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: it's not a constructor, just a function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Then no-new-symbol
should be fixed as well - I based this one on that.
The
Symbol
constructor is not intended to be used with thenew
operator
I'll fix it as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jrencz I would recommend fixing those docs in a separate issue/PR (if you weren't already thinking of doing that)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a really great start @jrencz. My comments are mostly just fine-tuning what you already have here. |
|
||
## When Not To Use It | ||
|
||
This rule should not be used in ES3/5 environments and in case you don't want to enforce either presence or omission of `description`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this might be a little awkward as one sentence, and would do better broken up into two sentences.
For example:
This rule should not be used in ES3/5 environments. In addition, this rule can be safely turned off if you don't want to enforce either the presence or the omission of description
when creating Symbols.
Not a huge deal-- your call on whether you want to change or not.
This is looking really good. Just two things from me:
|
LGTM |
@platinumazure @nzakas than you for the review. I applied all of @nzakas comments (I have option removal commit ready yet not pushed). I'll add tests @platinumazure asked for (but |
@jrencz Thanks! I'm wondering, though, maybe we should just remove the "always" option altogether and have |
LGTM |
1 similar comment
LGTM |
State of the PR: I need to add rules suggested by @platinumazure. All other comments were applied. |
> console.log(foo); | ||
// Symbol(foo) | ||
|
||
var bar = foo + ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This actually throws an error. Symbols cannot be coerced.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right
LGTM |
2 similar comments
LGTM |
LGTM |
|
||
## Rule Details | ||
|
||
This rule allows enforcing or disallowing symbol descriptions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I like "allows" followed by "disallowing", seems a bit confusing. I think it's better to follow the language we used in other rules like arrow-body-style
, func-name
, etc. "This rule can enforce or disallow the use of braces around arrow function body."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now it's more like, "This rules requires a description when creating symbols."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
Just a few minor comments about documentation, otherwise LGTM. |
@@ -0,0 +1,61 @@ | |||
# Require Symbol Description (symbol-description) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These words should be all lowercase
Friendly ping @jrencz, need any help? |
@platinumazure I had no time to start. I'll try today |
d9ef644
to
e0f7a71
Compare
LGTM |
1 similar comment
LGTM |
@platinumazure I added the tests you suggested. It turns out my implementation (which is combined from There's one case which you didn't mention and i'm not sure if it can be covered: Symbol = function () {};
Symbol(); If symbol is reassigned in the same scope as it's called but before it's called (you'r point 3 was about redefining after it's called). |
@mysticatea Is the issue which @jrencz raised here possible to catch via escope? |
I think the current implementation is good. We need dynamic analysis to detect completely the timing of the overwrites, but ESLint is a static analyzer 😄 . |
} | ||
|
||
return { | ||
"Program:exit": () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel this :
and =>
are extra.
"Program:exit"() {
(I'm sorry, very nit-picking.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should object-shorthand
(which we have on in the codebase I think?) catch this? I guess it might not due to this
working differently...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It depends on whether you treat it as a method that should use the object's this
or a regular function that may only react to the this
from the outer environment in the place of its definition.
Both could be used in the same project based on various circumstances.
@mysticatea I'll defer to your opinion. If you think the current implementation is good and that we probably can't do better, feel free to merge (if enough people have looked at it, in your view, and enough time has passed). Thanks! |
Oops, sorry, I had been asked about re-assignments, not redeclarations. Hmm, interesting. variable && variable.references.some(r => r.isWrite()) This is a check of re-assignment (though it doesn't detect timing...). I think fine that we add the check. But if we don't add the check, it will be warned by |
I think it sticks to the policy that each rule should overlap with others as little as possible. Let's stick to what we have now then. I'm going to squash it now and It looks like it's ready to be merged (at least from my point of view) |
eb52c28
to
d0f0496
Compare
LGTM |
We don't need to check for reassignment, only that |
Lgtm, just waiting another day for others to review. |
LGTM. |
LGTM |
LGTM. Thanks @jrencz for working on this! |
What issue does this pull request address?
#6778
What changes did you make? (Give an overview)
I implemented
symbol-description
ruleIs there anything you'd like reviewers to focus on?
TODO:
Symbol
is redefinedSymbol()
should be validSymbol
is shadowedSymbol()
should be valid