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-invalid-void-type] allow union of void and allowInGenericTypeArguments #1960

Merged
merged 10 commits into from
May 17, 2020

Conversation

sinyovercosy
Copy link
Contributor

@sinyovercosy sinyovercosy commented May 1, 2020

Fixes #1956
Fixes #1946

isValidUnionType is checked if the parent of a VoidKeyword is a UnionType. This function only returns true on a union consisting of void, never, or valid generic types parametrized by void, respecting the allowInGenericTypeArguments option. The function should hopefully be extensible if need be in the future.

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @sinyovercosy!

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 added the enhancement: plugin rule option New rule option for an existing eslint-plugin rule label May 1, 2020
@codecov
Copy link

codecov bot commented May 1, 2020

Codecov Report

Merging #1960 into master will decrease coverage by 0.01%.
The diff coverage is 90.90%.

@@            Coverage Diff             @@
##           master    #1960      +/-   ##
==========================================
- Coverage   93.93%   93.91%   -0.02%     
==========================================
  Files         172      172              
  Lines        7828     7843      +15     
  Branches     2245     2253       +8     
==========================================
+ Hits         7353     7366      +13     
  Misses        217      217              
- Partials      258      260       +2     
Flag Coverage Δ
#unittest 93.91% <90.90%> (-0.02%) ⬇️
Impacted Files Coverage Δ
...es/eslint-plugin/src/rules/no-invalid-void-type.ts 94.44% <90.90%> (-5.56%) ⬇️

@Raynos
Copy link

Raynos commented May 2, 2020

Thanks for making this fix.

Comment on lines 75 to 93
if (
member.type === AST_NODE_TYPES.TSTypeReference &&
member.typeParameters?.type ===
AST_NODE_TYPES.TSTypeParameterInstantiation
) {
const sourceCode = context.getSourceCode();
const fullyQualifiedName = sourceCode
.getText(member.typeName)
.replace(/ /gu, '');

return (
fullyQualifiedName === 'Promise' &&
member.typeParameters.params.length === 1 &&
member.typeParameters.params[0].type ===
AST_NODE_TYPES.TSVoidKeyword
);
}
return false;
}
Copy link
Member

Choose a reason for hiding this comment

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

Hmmm.
I think this should follow the same rule as the base check.
i.e. instead of special casing Promise, it should allow all generic types if allowInGenericTypeArguments: true, or just the whitelisted ones if allowInGenericTypeArguments: string[].

@bradzacher bradzacher added the awaiting response Issues waiting for a reply from the OP or another party label May 4, 2020
@bradzacher bradzacher removed the awaiting response Issues waiting for a reply from the OP or another party label May 4, 2020
@Raynos
Copy link

Raynos commented May 16, 2020

I ran into this issue again today.

I believe review feedback has been addressed in this PR; Can this get another review or a merge ?

@bradzacher bradzacher changed the title feat(eslint-plugin): [no-invalid-void-type] allow union of void and Promise<void> feat(eslint-plugin): [no-invalid-void-type] allow union of void and allowInGenericTypeArguments May 17, 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 this!

@bradzacher bradzacher merged commit 1bc105a into typescript-eslint:master May 17, 2020
@sinyovercosy sinyovercosy deleted the no-invalid-void-type branch May 18, 2020 00:48
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement: plugin rule option New rule option for an existing eslint-plugin rule
Projects
None yet
4 participants