Skip to content
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 non-nullable-type-assertion-style #2624

Conversation

JoshuaKGoldberg
Copy link
Member

Fixes #202.

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @JoshuaKGoldberg!

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.

@JoshuaKGoldberg JoshuaKGoldberg force-pushed the non-nullable-type-assertion-style branch from ed64bf9 to 7f691fd Compare October 2, 2020 05:00
@bradzacher bradzacher added the enhancement: new plugin rule New rule request for eslint-plugin label Oct 2, 2020
@JoshuaKGoldberg JoshuaKGoldberg force-pushed the non-nullable-type-assertion-style branch from 7f691fd to 33853dd Compare October 11, 2020 18:34
@JoshuaKGoldberg JoshuaKGoldberg force-pushed the non-nullable-type-assertion-style branch from 33853dd to 7c4e7ed Compare October 11, 2020 18:48
@codecov
Copy link

codecov bot commented Oct 11, 2020

Codecov Report

Merging #2624 (8112c89) into master (84a77cc) will increase coverage by 0.02%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #2624      +/-   ##
==========================================
+ Coverage   92.75%   92.77%   +0.02%     
==========================================
  Files         309      310       +1     
  Lines       10335    10367      +32     
  Branches     2927     2934       +7     
==========================================
+ Hits         9586     9618      +32     
  Misses        346      346              
  Partials      403      403              
Flag Coverage Δ
unittest 92.77% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
packages/eslint-plugin/src/configs/all.ts 100.00% <ø> (ø)
...gin/src/rules/non-nullable-type-assertion-style.ts 100.00% <100.00%> (ø)

@JoshuaKGoldberg JoshuaKGoldberg marked this pull request as ready for review October 11, 2020 18:59
Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code itself LGTM.


I wonder if this rule could also check for this case:

type T = string | null;
declare const x: T;

const y = x as NonNullable<T>;
// should be
const y = x!;

packages/eslint-plugin/typings/typescript.d.ts Outdated Show resolved Hide resolved
@bradzacher bradzacher added the awaiting response Issues waiting for a reply from the OP or another party label Oct 25, 2020
@JoshuaKGoldberg
Copy link
Member Author

Adding NonNullable SGTM - I'll be mostly out of availability the next couple of weeks, but hopefully will either find time to sneak it in with then or should be able to get to later. 👍

@JoshuaKGoldberg
Copy link
Member Author

Amusingly, even though I took a month and a half to get back to this, it's already supported: the logic just checks for whether the types are the same but for null and/or undefined added. So NonNullable and any of equivalents are supported already. Added test cases!

@bradzacher bradzacher removed the awaiting response Issues waiting for a reply from the OP or another party label Dec 12, 2020
Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks for your work!

@bradzacher bradzacher changed the title feat(eslint-plugin): new rule: non-nullable-type-assertion-style feat(eslint-plugin): add rule non-nullable-type-assertion-style Dec 13, 2020
@bradzacher bradzacher merged commit 7eee44f into typescript-eslint:master Dec 13, 2020
@JoshuaKGoldberg JoshuaKGoldberg deleted the non-nullable-type-assertion-style branch December 13, 2020 05:29
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement: new plugin rule New rule request for eslint-plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rule proposal: Prefer non-null assertion operator over type assertion
2 participants