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

fix(valid-types): whitelist pratt parser keywords #1222

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion docs/rules/check-tag-names.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -1856,5 +1856,18 @@ export default {
*/
`,
},
{
code: `
/**
* @param typeof
* @param readonly
* @param import
* @param is
*/
function quux() {

}
`
},
],
};