Skip to content

Commit c8612b2

Browse files
committed
fix: allow typedefs with no initial whitespace; fixes #1217
Also: - test: add test for invalid typedef
1 parent 2544b12 commit c8612b2

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

docs/rules/no-undefined-types.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,5 +1020,14 @@ const otherFile = require('./other-file');
10201020
* @param {otherFile.MyType} a
10211021
*/
10221022
function f(a) {}
1023+
1024+
/**@typedef {import('restify').Request} Request */
1025+
/**@typedef {import('./types').helperError} helperError */
1026+
1027+
/**
1028+
* @param {Request} b
1029+
* @param {helperError} c
1030+
*/
1031+
function a (b, c) {}
10231032
````
10241033

src/rules/noUndefinedTypes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export default iterateJsdoc(({
115115
const allComments = sourceCode.getAllComments();
116116
const comments = allComments
117117
.filter((comment) => {
118-
return (/^\*\s/v).test(comment.value);
118+
return (/^\*(?!\*)/v).test(comment.value);
119119
})
120120
.map((commentNode) => {
121121
return parseComment(commentNode, '');

test/rules/assertions/noUndefinedTypes.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,24 @@ export default /** @type {import('../index.js').TestCases} */ ({
633633
},
634634
],
635635
},
636+
{
637+
code: `
638+
/*** @typedef {object} SomeType */
639+
/**
640+
* @param {SomeType} foo - Bar.
641+
*/
642+
function quux(foo) {
643+
644+
}
645+
`,
646+
errors: [
647+
{
648+
line: 4,
649+
message: 'The type \'SomeType\' is undefined.',
650+
},
651+
],
652+
ignoreReadme: true,
653+
},
636654
],
637655
valid: [
638656
{
@@ -1740,5 +1758,17 @@ export default /** @type {import('../index.js').TestCases} */ ({
17401758
function f(a) {}
17411759
`,
17421760
},
1761+
{
1762+
code: `
1763+
/**@typedef {import('restify').Request} Request */
1764+
/**@typedef {import('./types').helperError} helperError */
1765+
1766+
/**
1767+
* @param {Request} b
1768+
* @param {helperError} c
1769+
*/
1770+
function a (b, c) {}
1771+
`,
1772+
},
17431773
],
17441774
});

0 commit comments

Comments
 (0)