Skip to content

Commit ab5624b

Browse files
committed
fix(valid-types): whitelist pratt parser keywords; fixes #1221
1 parent 9e9fed5 commit ab5624b

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

docs/rules/check-tag-names.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ function quux (foo) {}
722722
*/
723723
function quux (foo) {}
724724
// Settings: {"jsdoc":{"mode":"jsdoc"}}
725-
// Message: Invalid JSDoc tag name "internal".
725+
// Message: Invalid JSDoc tag name "import".
726726

727727
/**
728728
* @externs

docs/rules/valid-types.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,5 +877,15 @@ function quux() {
877877
/**
878878
* An inline {@link text} tag with content.
879879
*/
880+
881+
/**
882+
* @param typeof
883+
* @param readonly
884+
* @param import
885+
* @param is
886+
*/
887+
function quux() {
888+
889+
}
880890
````
881891

src/rules/validTypes.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ const inlineTags = new Set([
1010
'tutorial',
1111
]);
1212

13+
const jsdocTypePrattKeywords = new Set([
14+
'typeof',
15+
'readonly',
16+
'import',
17+
'is',
18+
]);
19+
1320
const asExpression = /as\s+/u;
1421

1522
const suppressTypes = new Set([
@@ -107,7 +114,10 @@ export default iterateJsdoc(({
107114
* @returns {boolean}
108115
*/
109116
const validNamepathParsing = function (namepath, tagName) {
110-
if (tryParsePathIgnoreError(namepath)) {
117+
if (
118+
tryParsePathIgnoreError(namepath) ||
119+
jsdocTypePrattKeywords.has(namepath)
120+
) {
111121
return true;
112122
}
113123

test/rules/assertions/validTypes.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,5 +1856,18 @@ export default {
18561856
*/
18571857
`,
18581858
},
1859+
{
1860+
code: `
1861+
/**
1862+
* @param typeof
1863+
* @param readonly
1864+
* @param import
1865+
* @param is
1866+
*/
1867+
function quux() {
1868+
1869+
}
1870+
`
1871+
},
18591872
],
18601873
};

0 commit comments

Comments
 (0)