-
Notifications
You must be signed in to change notification settings - Fork 889
Bad suggestions from the no-any rule #2491
Comments
I'm inclined to agree, I think we can just remove the second & third parts of that suggestion and say "Consider replacing it with a more precise type." (rule suppression is a global concept and doesn't need to be noted in any specific rule). Any objections @mprobst or @alexeagle? |
I'm okay with that Adi.
|
Hm, what does this mean for the auto-fixer, though? If we no longer suggest |
The empty type is a lot more type-safe than |
I think the original post referred to a manual lint fix that misinterpreted the rule failure location & suggestion, not an auto-fix using |
I see. In any case I agree that auto-fixing with |
Within Google, based on user feedback, we've amended this error message to link to our (internal) docs that have a few paragraphs describing the various ways to fix this. Unfortunately it's hard to fit all the information a user needs in a one-liner. Our docs open with three broad categories of fixes and then goes into where each one applies: "In circumstances where you want to use any, consider one of:
|
In my experience, developers use the |
Chris: `{}` gives strong checks, they are just super restrictive (don't
allow properties to be accessed). So that at least can be a prod for
developers not to avoid `any` and then fix it up to use the correct type.
At least that's what we're seeing in usage over here.
… |
@mprobst that's not 100% true in every case though. IMO the point of a fix is to replace the bad code portion with the 100% correct alternative, usually for style-related code. replace I'd argue that this rule is different because there's no alternative to I think perhaps this rule should have an option to suggest/fix |
This is a great example where we've conflated a linter and a formatter.
A formatter has 100% correct fixes, so we just run it blindly without
asking it for individual diagnostic messages for each wrong spot.
Anything that has a 100% correct fix (like fixing up all quotes to
double/single) can therefore move into the formatter.
If it's in the linter, I believe it may have different fixes depending on
the developer:
- suppress this instance because I want it this way
- fix it in the conservative way: maintain the current semantics even if
the pattern looks wrong
- try to restore the original developer intent, but possibly breaking
something
I think developers should *always* inspect the suggestion in these cases.
We could also offer multiple suggestions (this is allowed in the API)
…On Tue, Apr 11, 2017 at 9:58 AM Chris Barr ***@***.***> wrote:
@mprobst <https://github.com/mprobst> that's not 100% true in every case
though. IMO the point of a fix is to replace the bad code portion with the
100% correct alternative, usually for style-related code. replace var
with let, or replace " with ', add spaces or semicolons where they are
expected. Stuff like that.
I'd argue that this rule is different because there's no alternative to
any that's 100% correct all the time (well, at least not one that can be
auto-fixed).
I think perhaps this rule should have an option to suggest/fix any with {}
to give developers the best of both worlds with what they need for each
app. In the apps I work on, I *never* want to suggest that a developer
should use {} as an alternative to any, but clearly other developers do.
We all have a different context for the apps we work on, so I think an
option here might be helpful.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2491 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAC5Iw9aU7l9nqJnizjYLJQWUp2kK80-ks5ru7FBgaJpZM4My1kk>
.
|
@ChrisMBarr do you remember why you closed this? Still seems like we should remove the fixer for no-any |
@alexeagle Oh yes, sorry. I was under the impression that the auto-fixer was already removed and this issue was forgotten about. Sorry. Re-opened now. |
The changes in wording from #2164 are, in my opinion, a very bad idea. It gives a bad suggestion which basically encourages the use of
{}
overany
- both of these are not ideal if the goal is to use strong typing in a project. The current text reads:It states that
any
loses type-safety, but to be fair, so does{}
.I have developers on my team now using
{}
as a type, which in no way describes the object properly, but now there are no lint violations thrown for this new bad typing.Here's a screenshot of a recent commit where the developer just did what the rule said to do, but not 100% understanding it.
(note their commit message on the left side)
the type
ng.IPromise<any>
got converted to{}
, but the correct solution here was to use the typeng.IPromise<void>
Can this text be reverted, or possibly changed in some way to not entourage weak typing?
The text was updated successfully, but these errors were encountered: