Navigation Menu

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): [no-unsafe-assignment/return] allow assigning any => unknown #2371

Merged
merged 3 commits into from Aug 10, 2020

Conversation

yasarsid
Copy link
Contributor

@yasarsid yasarsid commented Aug 7, 2020

Fixes #2325

Overview

This PR looks to relax restrictions to allow any => unknown assignment for no-unsafe-assignment and no-unsafe-return.

Approach

Initially we are checking for Any or AnyArray as senderType, if found we used to stop processing with the relevant message.
Now we additionally check if the recieverType is Unknown or Unknown array. If yes - then we do not treat this as an error case.

Special Focus

I would like you to specifically look at the coding style, so that we don't adversely affect future contributors. I have tried to align with the existing style. Feel free to point out where we could align more.

Checklist

  • Have updated the documentation for these rule and called these relaxation separately.
  • Have added UTs for the cases added.

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @yasarsid!

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.

@codecov
Copy link

codecov bot commented Aug 7, 2020

Codecov Report

Merging #2371 into master will increase coverage by 0.05%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #2371      +/-   ##
==========================================
+ Coverage   93.10%   93.15%   +0.05%     
==========================================
  Files         285      285              
  Lines        9125     9150      +25     
  Branches     2504     2513       +9     
==========================================
+ Hits         8496     8524      +28     
+ Misses        302      301       -1     
+ Partials      327      325       -2     
Flag Coverage Δ
#unittest 93.15% <100.00%> (+0.05%) ⬆️

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

Impacted Files Coverage Δ
...es/eslint-plugin/src/rules/no-unsafe-assignment.ts 80.50% <100.00%> (+0.33%) ⬆️
...ckages/eslint-plugin/src/rules/no-unsafe-return.ts 100.00% <100.00%> (+5.00%) ⬆️
packages/eslint-plugin/src/util/types.ts 83.24% <100.00%> (+1.15%) ⬆️
packages/visitor-keys/src/visitor-keys.ts 100.00% <0.00%> (ø)
...nt-plugin/src/rules/no-unused-vars-experimental.ts 91.48% <0.00%> (ø)
packages/typescript-estree/src/convert.ts 98.36% <0.00%> (+0.01%) ⬆️
...ckages/scope-manager/src/referencer/TypeVisitor.ts 89.55% <0.00%> (+0.15%) ⬆️

@bradzacher bradzacher added the bug Something isn't working label Aug 7, 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.

Thanks for doing this! The changes LGTM.

One request:
could you please add some tests for isUnsafeAssignment into
https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/tests/util/isUnsafeAssignment.test.ts

Great work!

@bradzacher bradzacher added enhancement New feature or request awaiting response Issues waiting for a reply from the OP or another party and removed bug Something isn't working labels Aug 9, 2020
@yasarsid
Copy link
Contributor Author

@bradzacher - Good catch for missing UTs. 👍

As suggested - have added tests in isUnsafeAssignment.test.ts

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.

ezpz - thanks for your work!

@bradzacher bradzacher removed the awaiting response Issues waiting for a reply from the OP or another party label Aug 10, 2020
@bradzacher bradzacher changed the title feat(eslint-plugin): [no-unsafe-assignment/return] Relax restrictions to allow any => unknown assignment feat(eslint-plugin): [no-unsafe-assignment/return] allow assigning any => unknown Aug 10, 2020
@bradzacher bradzacher merged commit e7528e6 into typescript-eslint:master Aug 10, 2020
etaoins added a commit to seek-oss/eslint-config-seek that referenced this pull request Aug 20, 2020
The last few versions of `@typescript/eslint` have contained fixes to
deal with the changes in the TypeScript 4 AST. They should still work
against TypeScript 3.

This also pulls in typescript-eslint/typescript-eslint#2371 which allows
assigning `any` to `unknown` in more situations.
etaoins added a commit to seek-oss/eslint-config-seek that referenced this pull request Aug 20, 2020
The last few versions of `@typescript/eslint` have contained fixes to
deal with the changes in the TypeScript 4 AST. They should still work
against TypeScript 3.

This also pulls in typescript-eslint/typescript-eslint#2371 which allows
assigning `any` to `unknown` in more situations.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[no-unsafe-assignment/return] Relax restrictions to allow any => unknown assignment
2 participants