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 no-unsafe-return #1644

Merged
merged 1 commit into from Mar 3, 2020
Merged

Conversation

bradzacher
Copy link
Member

@bradzacher bradzacher commented Feb 26, 2020

See #791

I think it's better to introduce these as a number of separate rules.
It makes it easier for people to opt in to the rules, and keeps each implementation small and focused.
This also makes it easier and faster to build and release, as we can build and release smaller rules instead of releasing one monolithic rule.

Based off of #1643


This rule does two things:

  1. it checks all function returns and errors if you return any.
  2. if the type is not explicitly any, it compares a return type with the function signature's return type, comparing the generic parameters to ensure no unsafe assignment is occurring:
    • i.e. this will error in the lint rule, but is "safe" in TS
      function foo(): Set<string> { return new Set<any>([1]) }

@bradzacher bradzacher added enhancement: new plugin rule New rule request for eslint-plugin blocked by another PR PRs which are ready to go but waiting on another PR labels Feb 26, 2020
@typescript-eslint
Copy link
Contributor

Thanks for the PR, @bradzacher!

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.

@bradzacher bradzacher linked an issue Feb 26, 2020 that may be closed by this pull request
@bradzacher bradzacher changed the base branch from master to no-unsafe-member-access February 28, 2020 07:22
@bradzacher bradzacher force-pushed the no-unsafe-return branch 2 times, most recently from 47ba6e8 to 296b0e7 Compare March 3, 2020 07:24
@bradzacher bradzacher changed the base branch from no-unsafe-member-access to master March 3, 2020 08:15
@codecov
Copy link

codecov bot commented Mar 3, 2020

Codecov Report

Merging #1644 into master will decrease coverage by 0.01%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master    #1644      +/-   ##
==========================================
- Coverage   95.37%   95.36%   -0.02%     
==========================================
  Files         146      147       +1     
  Lines        6836     6904      +68     
  Branches     1964     1984      +20     
==========================================
+ Hits         6520     6584      +64     
- Misses        111      112       +1     
- Partials      205      208       +3     
Impacted Files Coverage Δ
...ckages/eslint-plugin/src/rules/no-unsafe-return.ts 95.00% <0.00%> (ø)

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.

New set of rules: no-unsafe-*
1 participant