-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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 rule no-confusing-non-null-assertion
#1941
Conversation
Thanks for the PR, @zhangciwu! typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community. The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately. Thanks again! 🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day. |
A problem: in the doc, code are altered by git hooks,
Now I remove code block language describer to avoid this transformation (Some other rule "fix" it? ) And lack of languege describer cause a markdown lint error…… |
Codecov Report
@@ Coverage Diff @@
## master #1941 +/- ##
==========================================
- Coverage 93.45% 93.40% -0.06%
==========================================
Files 171 172 +1
Lines 7813 7844 +31
Branches 2227 2239 +12
==========================================
+ Hits 7302 7327 +25
- Misses 244 245 +1
- Partials 267 272 +5
|
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.
mostly LGTM.
a few comments.
Also one additional case that should also be handled by this
let x: null | string = null;
x! = 'a';
// looks similar to x != 'a'
// should fix to
x = 'a';
packages/eslint-plugin/src/rules/confusing-non-null-assertion-like-not-equal.ts
Outdated
Show resolved
Hide resolved
packages/eslint-plugin/src/rules/confusing-non-null-assertion-like-not-equal.ts
Outdated
Show resolved
Hide resolved
packages/eslint-plugin/src/rules/confusing-non-null-assertion-like-not-equal.ts
Outdated
Show resolved
Hide resolved
packages/eslint-plugin/src/rules/confusing-non-null-assertion-like-not-equal.ts
Outdated
Show resolved
Hide resolved
packages/eslint-plugin/src/rules/confusing-non-null-assertion-like-not-equal.ts
Outdated
Show resolved
Hide resolved
packages/eslint-plugin/docs/rules/confusing-non-null-assertion-like-not-equal.md
Outdated
Show resolved
Hide resolved
packages/eslint-plugin/docs/rules/confusing-non-null-assertion-like-not-equal.md
Outdated
Show resolved
Hide resolved
@bradzacher Great idea for |
…-like-not-equal.md Co-authored-by: Brad Zacher <brad.zacher@gmail.com>
…like-not-equal.ts Co-authored-by: Brad Zacher <brad.zacher@gmail.com>
…like-not-equal.ts Co-authored-by: Brad Zacher <brad.zacher@gmail.com>
…like-not-equal.ts Co-authored-by: Brad Zacher <brad.zacher@gmail.com>
@bradzacher But for |
packages/eslint-plugin/docs/rules/no-confusing-non-null-assertion.md
Outdated
Show resolved
Hide resolved
…ion.md Co-authored-by: Brad Zacher <brad.zacher@gmail.com>
confusing-non-null-assertion-like-not-equal
no-confusing-non-null-assertion
packages/eslint-plugin/tests/rules/no-confusing-non-null-assertion.test.ts
Show resolved
Hide resolved
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.
logic lgtm - one change for the tests
…tion.test.ts Co-authored-by: Brad Zacher <brad.zacher@gmail.com>
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.
thanks for your work!
no-confusing-non-null-assertion
no-confusing-non-null-assertion
Fixes #1940
Using a non-null assertions(
!
) and an equals test(==
) together makes code looks very similar with not equals test(!==
), look at below code:I have submit an issue on typescript repo
Issue: Easy misunderstanding: "! ==="
, and a PR to fix it.And I think it's good for many people to avoid this writing by composing a lint rule
Doc at
packages/eslint-plugin/docs/rules/confusing-non-null-assertion-like-not-equal.md
in this PR