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] better report message for void used as a constituent inside a function return type #5274

Merged
merged 53 commits into from Oct 29, 2022
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
5b79028
feat: update repository
kmin-jeong Apr 7, 2022
5c3af4d
remove duplicate examples
kmin-jeong Apr 7, 2022
f5674a8
feat:add about re-exporting --isolatedModules in When Not To Use It
kmin-jeong Apr 7, 2022
d47eeb4
feat: add exmaples
kmin-jeong Apr 8, 2022
6f74fea
fix: remove duplicate examples in correct
kmin-jeong Apr 8, 2022
7fb6dc7
fix:correct words
kmin-jeong Apr 8, 2022
e77ae67
fix: fix space-between
kmin-jeong Apr 8, 2022
2572fd6
fix: fix code
kmin-jeong Apr 8, 2022
40f496f
fix: fix code space
kmin-jeong Apr 8, 2022
b508138
fix: check error
kmin-jeong Apr 8, 2022
70dc242
fix:missed examples
kmin-jeong Apr 8, 2022
c895ad8
feat: read review and fix them
kmin-jeong Apr 8, 2022
6158e57
feat: add two taps
kmin-jeong Apr 8, 2022
c4a25fd
fix: add <!--tabs-->
kmin-jeong Apr 8, 2022
cc71bea
feat: fix explaination about `isolatedmodules`
kmin-jeong Apr 8, 2022
251f49e
fix: fix explain about `isolatedModules`
kmin-jeong Apr 8, 2022
d42a546
fis: modify When no to use it
kmin-jeong Apr 9, 2022
f1c3ce4
fix: revert change log
kmin-jeong Apr 9, 2022
4246b6b
fix: add lint
kmin-jeong Apr 9, 2022
c1af45c
fix: add lint
kmin-jeong Apr 10, 2022
42d8958
add: fix code
kmin-jeong Apr 10, 2022
efd3668
fix:fix docs splits
kmin-jeong Apr 10, 2022
8b4f9de
feat: add lint
kmin-jeong Apr 10, 2022
24c0f2e
Update packages/eslint-plugin/docs/rules/consistent-type-exports.md
JoshuaKGoldberg Apr 10, 2022
2f2bb8d
Merge branch 'main' into master
kmin-jeong Apr 11, 2022
05377bd
Merge branch 'typescript-eslint:main' into master
kmin-jeong Apr 12, 2022
b5df9a8
Merge branch 'typescript-eslint:main' into master
kmin-jeong Apr 18, 2022
e3e6a0c
Merge branch 'typescript-eslint:main' into master
kmin-jeong Jun 14, 2022
d844fe3
Merge branch 'typescript-eslint:main' into master
kmin-jeong Jun 27, 2022
4119247
Merge branch 'typescript-eslint:main' into master
kmin-jeong Jun 30, 2022
bcccb43
feat:change error message better
kmin-jeong Jun 30, 2022
8154c5c
fix:separating message and made types about union
kmin-jeong Jun 30, 2022
aeb5cad
fix: separate error message
kmin-jeong Jun 30, 2022
ae4ffba
Merge branch 'typescript-eslint:main' into master
kmin-jeong Jun 30, 2022
3c531e8
fix:fix mistake type
kmin-jeong Jun 30, 2022
af8cede
fix:fix typo
kmin-jeong Jun 30, 2022
87f169c
Merge branch 'main' into feat/5255
kmin-jeong Jun 30, 2022
f7627e7
fix:fix error message in case of union
kmin-jeong Jul 2, 2022
4b24d17
Merge branch 'typescript-eslint:main' into master
kmin-jeong Jul 2, 2022
8822312
Merge branch 'main' into feat/5255
kmin-jeong Jul 2, 2022
0c452d8
Merge branch 'master' of https://github.com/kmin-jeong/typescript-esl…
kmin-jeong Jul 2, 2022
9a9982d
Merge branch 'feat/5255' of https://github.com/kmin-jeong/typescript-…
kmin-jeong Jul 2, 2022
dfa5f37
Merge branch 'main' into feat/5255
kmin-jeong Jul 6, 2022
3ae90bf
fix:fix error message in InvalidVoidForUnion
kmin-jeong Jul 24, 2022
f31f829
Merge branch 'typescript-eslint:main' into feat/5255
kmin-jeong Jul 24, 2022
9d4199b
Merge branch 'main' into feat/5255
kmin-jeong Aug 18, 2022
369f447
fix: add logic about union
kmin-jeong Aug 18, 2022
1a9d56d
feat: add test case
kmin-jeong Aug 18, 2022
4329328
Merge branch 'main' into feat/5255
kmin-jeong Aug 18, 2022
7bc3031
Merge branch 'main' into feat/5255
kmin-jeong Aug 18, 2022
1c48645
Merge branch 'main' into feat/5255
kmin-jeong Oct 27, 2022
ad238bc
Switched change to just enhance error message
JoshuaKGoldberg Oct 27, 2022
20d46de
oops comment
JoshuaKGoldberg Oct 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 36 additions & 4 deletions packages/eslint-plugin/src/rules/no-invalid-void-type.ts
Expand Up @@ -4,14 +4,17 @@ import * as util from '../util';
interface Options {
allowInGenericTypeArguments?: boolean | string[];
allowAsThisParameter?: boolean;
allowUnionType?: boolean;
invalidUnionParameter?: boolean | string[];
}

type MessageIds =
| 'invalidVoidForGeneric'
| 'invalidVoidNotReturnOrGeneric'
| 'invalidVoidNotReturn'
| 'invalidVoidNotReturnOrThisParam'
| 'invalidVoidNotReturnOrThisParamOrGeneric';
| 'invalidVoidNotReturnOrThisParamOrGeneric'
| 'InvalidVoidForUnion';

export default util.createRule<[Options], MessageIds>({
name: 'no-invalid-void-type',
Expand All @@ -31,6 +34,8 @@ export default util.createRule<[Options], MessageIds>({
'void is only valid as return type or type of `this` parameter.',
invalidVoidNotReturnOrThisParamOrGeneric:
'void is only valid as a return type or generic type variable or the type of a `this` parameter.',
InvalidVoidForUnion:
kmin-jeong marked this conversation as resolved.
Show resolved Hide resolved
'void is not valid as a type constituent in a return type.',
},
schema: [
{
Expand All @@ -49,15 +54,33 @@ export default util.createRule<[Options], MessageIds>({
allowAsThisParameter: {
type: 'boolean',
},
invalidUnionParameter: {
oneOf: [
{ type: 'boolean' },
{
type: 'array',
items: { type: 'string' },
minLength: 1,
},
],
},
allowUnionType: {
type: 'boolean',
},
},
additionalProperties: false,
},
],
},
defaultOptions: [
{ allowInGenericTypeArguments: true, allowAsThisParameter: false },
{
allowInGenericTypeArguments: true,
allowAsThisParameter: false,
invalidUnionParameter: true,
allowUnionType:true,
},
],
create(context, [{ allowInGenericTypeArguments, allowAsThisParameter }]) {
create(context, [{ allowInGenericTypeArguments, allowAsThisParameter, invalidUnionParameter,allowUnionType }]) {
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
const validParents: AST_NODE_TYPES[] = [
AST_NODE_TYPES.TSTypeAnnotation, //
];
Expand Down Expand Up @@ -123,6 +146,15 @@ export default util.createRule<[Options], MessageIds>({
node,
});
}

if (!invalidUnionParameter) {
context.report({
messageId: invalidUnionParameter
? 'InvalidVoidForUnion'
: 'InvalidVoidForUnion',
node,
});
}
}

/**
Expand Down Expand Up @@ -188,7 +220,7 @@ export default util.createRule<[Options], MessageIds>({

context.report({
messageId:
allowInGenericTypeArguments && allowAsThisParameter
allowInGenericTypeArguments && allowAsThisParameter && allowUnionType
? 'invalidVoidNotReturnOrThisParamOrGeneric'
: allowInGenericTypeArguments
? 'invalidVoidNotReturnOrGeneric'
Expand Down
22 changes: 22 additions & 0 deletions packages/eslint-plugin/tests/rules/no-invalid-void-type.test.ts
Expand Up @@ -98,6 +98,28 @@ function foo(): void | never {
],
});

ruleTester.run('invalidUnionParameter:true', rule, {
valid: [
{
code: 'type allowUnion = string | number',
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
options: [{ allowUnionType: true }],
},
],
invalid: [
{
code: 'type invalidVoidUnion = void | number;',
options: [{ invalidUnionParameter: false }],
errors: [
{
messageId: 'InvalidVoidForUnion',
line: 1,
column: 25,
},
],
},
],
});

ruleTester.run('allowInGenericTypeArguments: true', rule, {
valid: [
'function func(): void {}',
Expand Down