Skip to content

Commit 43fff88

Browse files
committed
fix(require-template): check TSDeclareFunction (including overloads) for templates; fixes #1462
1 parent 5603da9 commit 43fff88

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

.README/rules/require-template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Checks to see that `@template` tags are present for any detected type
44
parameters.
55

6-
Currently checks `ClassDeclaration`, `FunctionDeclaration`,
6+
Currently checks `ClassDeclaration`, `FunctionDeclaration`, `TSDeclareFunction`,
77
`TSInterfaceDeclaration` or `TSTypeAliasDeclaration` such as:
88

99
```ts

docs/rules/require-template.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Checks to see that `@template` tags are present for any detected type
66
parameters.
77

8-
Currently checks `ClassDeclaration`, `FunctionDeclaration`,
8+
Currently checks `ClassDeclaration`, `FunctionDeclaration`, `TSDeclareFunction`,
99
`TSInterfaceDeclaration` or `TSTypeAliasDeclaration` such as:
1010

1111
```ts
@@ -221,6 +221,18 @@ export default class <NumType> {
221221
* @returns {[D, V | undefined]}
222222
*/
223223
// Message: Missing @template D
224+
225+
/**
226+
* @param bar
227+
* @param baz
228+
* @returns
229+
*/
230+
function foo<T>(bar: T, baz: number): T;
231+
function foo<T>(bar: T, baz: boolean): T;
232+
function foo<T>(bar: T, baz: number | boolean): T {
233+
return bar;
234+
}
235+
// Message: Missing @template T
224236
````
225237

226238

src/rules/requireTemplate.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export default iterateJsdoc(({
4242
/**
4343
* @param {import('@typescript-eslint/types').TSESTree.FunctionDeclaration|
4444
* import('@typescript-eslint/types').TSESTree.ClassDeclaration|
45+
* import('@typescript-eslint/types').TSESTree.TSDeclareFunction|
4546
* import('@typescript-eslint/types').TSESTree.TSInterfaceDeclaration|
4647
* import('@typescript-eslint/types').TSESTree.TSTypeAliasDeclaration} aliasDeclaration
4748
*/
@@ -79,6 +80,7 @@ export default iterateJsdoc(({
7980
switch (nde.type) {
8081
case 'ClassDeclaration':
8182
case 'FunctionDeclaration':
83+
case 'TSDeclareFunction':
8284
case 'TSInterfaceDeclaration':
8385
case 'TSTypeAliasDeclaration':
8486
checkTypeParams(nde);
@@ -97,6 +99,7 @@ export default iterateJsdoc(({
9799
switch (nde.declaration?.type) {
98100
case 'ClassDeclaration':
99101
case 'FunctionDeclaration':
102+
case 'TSDeclareFunction':
100103
case 'TSInterfaceDeclaration':
101104
case 'TSTypeAliasDeclaration':
102105
checkTypeParams(nde.declaration);

test/rules/assertions/requireTemplate.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,29 @@ export default /** @type {import('../index.js').TestCases} */ ({
403403
},
404404
],
405405
},
406+
{
407+
code: `
408+
/**
409+
* @param bar
410+
* @param baz
411+
* @returns
412+
*/
413+
function foo<T>(bar: T, baz: number): T;
414+
function foo<T>(bar: T, baz: boolean): T;
415+
function foo<T>(bar: T, baz: number | boolean): T {
416+
return bar;
417+
}
418+
`,
419+
errors: [
420+
{
421+
line: 2,
422+
message: 'Missing @template T',
423+
},
424+
],
425+
languageOptions: {
426+
parser: typescriptEslintParser,
427+
},
428+
},
406429
],
407430
valid: [
408431
{

0 commit comments

Comments
 (0)