-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(eslint-plugin): add no-unnecessary-type-assertion rule #157
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(eslint-plugin): add no-unnecessary-type-assertion rule #157
Conversation
Codecov Report
@@ Coverage Diff @@
## master #157 +/- ##
==========================================
+ Coverage 95.69% 95.76% +0.06%
==========================================
Files 49 50 +1
Lines 2487 2526 +39
Branches 373 373
==========================================
+ Hits 2380 2419 +39
Misses 63 63
Partials 44 44
|
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 unsure if adding fixer for this rule is good idea, if someone did cast, than most likely it was needed for something.
packages/eslint-plugin/lib/rules/no-unnecessary-type-assertion.js
Outdated
Show resolved
Hide resolved
Sometimes extraneous casts are left around after refactoring, or an upgrade of the compiler where it got smarter about inferring types. Either way, I think that fixing is the right move for no-op casts because it is always safe... do you have any counter examples where it's not safe? |
packages/eslint-plugin/docs/rules/no-unnecessary-type-assertion.md
Outdated
Show resolved
Hide resolved
packages/eslint-plugin/lib/rules/no-unnecessary-type-assertion.js
Outdated
Show resolved
Hide resolved
*/ | ||
|
||
'use strict'; | ||
const tsutils = require('tsutils'); |
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.
@uniqueiniquity @JamesHenry Upgraded to latest canary (1.1.2-alpha.4
) to work around #161.
Which then triggered
$ yarn run lint:ts
$ eslint . --ext .ts,.tsx --max-warnings=0
Error: Cannot find module 'tsutils'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
at Function.Module._load (internal/modules/cjs/loader.js:507:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (C:\REDACTED\node_modules\@typescript-eslint\eslint-plugin\lib\rules\no-unnecessary-type-assertion.js:7:17)
Had to add tsutils
to package.json
. Is that expected ?
Maybe a slight addition to the README would be helpful regarding this. Or even better, add tsutils
as a dependency of that plugin.
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.
@nulltoken My mistake. I'm not sure how I missed adding it to the package.json and it still managed to pass the tests...
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.
Oh, I get it; tslint
is being installed as a dev dependency, and that happens to pull in tsutils
so it works in a dev scenario. I'll get a fix up right now.
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.
👍
Managed to forget to add `tsutils` as a true dependency to `eslint-plugin` in #157.
LGTM |
Adding equivalent of TSLint's
no-unnecessary-type-assertion
.