Skip to content

Commit

Permalink
fix(valid-types): whitelist pratt parser keywords; fixes #1221
Browse files Browse the repository at this point in the history
  • Loading branch information
brettz9 committed Apr 4, 2024
1 parent 9e9fed5 commit ab5624b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/rules/check-tag-names.md
Expand Up @@ -722,7 +722,7 @@ function quux (foo) {}
*/
function quux (foo) {}
// Settings: {"jsdoc":{"mode":"jsdoc"}}
// Message: Invalid JSDoc tag name "internal".
// Message: Invalid JSDoc tag name "import".

/**
* @externs
Expand Down
10 changes: 10 additions & 0 deletions docs/rules/valid-types.md
Expand Up @@ -877,5 +877,15 @@ function quux() {
/**
* An inline {@link text} tag with content.
*/

/**
* @param typeof
* @param readonly
* @param import
* @param is
*/
function quux() {

}
````

12 changes: 11 additions & 1 deletion src/rules/validTypes.js
Expand Up @@ -10,6 +10,13 @@ const inlineTags = new Set([
'tutorial',
]);

const jsdocTypePrattKeywords = new Set([
'typeof',
'readonly',
'import',
'is',
]);

const asExpression = /as\s+/u;

const suppressTypes = new Set([
Expand Down Expand Up @@ -107,7 +114,10 @@ export default iterateJsdoc(({
* @returns {boolean}
*/
const validNamepathParsing = function (namepath, tagName) {
if (tryParsePathIgnoreError(namepath)) {
if (
tryParsePathIgnoreError(namepath) ||
jsdocTypePrattKeywords.has(namepath)
) {
return true;
}

Expand Down
13 changes: 13 additions & 0 deletions test/rules/assertions/validTypes.js
Expand Up @@ -1856,5 +1856,18 @@ export default {
*/
`,
},
{
code: `
/**
* @param typeof
* @param readonly
* @param import
* @param is
*/
function quux() {
}
`
},
],
};

0 comments on commit ab5624b

Please sign in to comment.