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
feat: upgrade plugin to v2.3.3 #177
Conversation
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 happy with this.
src/index.ts
Outdated
@@ -75,6 +75,7 @@ export = { | |||
'@typescript-eslint/no-namespace': 'error', | |||
'@typescript-eslint/no-non-null-assertion': 'error', | |||
'@typescript-eslint/no-this-alias': ['error', { allowDestructuring: true }], | |||
'@typescript-eslint/no-unnecessary-condition': 'error', |
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.
6457bb0
to
e6259a2
Compare
@swansontec would you like to review? |
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.
Yeah, this sounds like a really useful rule! I'm for it 👍
This new rule generally makes sense, but there are some edge cases where it can get in the way, like unit testing or sanitizing incoming data. If you are writing a library designed for external consumption, you might do something like this: function doMath (x: number): number {
if (typeof x !== 'number') throw new TypeError('We only support numbers')
return x * 2
} The runtime check is redundant with the Typescript types, but it exists for the benefit of any Vanilla Javascript users. The only way to keep this code working is to switch to an assertion library, like |
Hmmm, Not really sure what my opinion is on this 🤔 |
@swansontec You make a very valid point. I wonder if there is any way to get typescript to generate those type assertions automatically when compiling down to vanilla js? Probably not, but that would be an interesting project to help improve vanilla js type-safety. Edit: Looks like a package already exists for this: https://github.com/fabiandev/ts-runtime |
So we have a rule here that in TypeScript tells you, "hey, don't check this type at run-time because according to type checking it's what you expect". This is great, because it lets you know that you made a wrong assumption about what that value could be. So we'd like to have this. But, if your code happens to be imported and used sans TypeScript, then you might decide that it's appropriate to type-check at run-time. I've heard some developers call this "defensive programming". Is it dichotomous or is there a balance to run-time type checking sans static type checking? If a library expects a string and is provided a number, should it throw with a nice error message or should it throw "foo.match is not a function" or silently behave unexpectedly? Is it acceptable to enable this rule and use |
I agree that this rule is helpful in a lot of cases (where you have strong type information), but not all projects have these guarantees. Enabling this rule could really make life difficult for those projects, so I don't think it is the kind of clean win that belongs in Standard.js. The reason Standard.js can get away with being non-configurable is that it takes a generous "one-size-fits-all" approach. Anybody can enable Standard.js on their project and be happy; Standard.js doesn't block any legitimate coding patterns (at least, none that I have noticed in my 4 years of using it). The trade-off is that Standard.js doesn't enforce as many "best practices" as it could. For instance, Standard.js doesn't include the |
e6259a2
to
cfbc821
Compare
Thank you for the input, @LinusU, @toddbluhm and @swansontec. I've deferred |
Closes #154.