Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/rules/no-undefined-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -1092,5 +1092,10 @@ const getValue = () => {};
*/
const defineCustomElement = (tagName, component) => {
};

class Storage {
/** @type {globalThis.localStorage} */
#storage
}
````

9 changes: 8 additions & 1 deletion src/rules/noUndefinedTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ const extraTypes = [
'Array', 'Object', 'RegExp', 'Date', 'Function', 'Intl',
];

const globalTypes = [
'globalThis', 'global', 'window', 'self',
];

const typescriptGlobals = [
// https://www.typescriptlang.org/docs/handbook/utility-types.html
'Awaited',
Expand Down Expand Up @@ -470,6 +474,7 @@ export default iterateJsdoc(({
parsedType,
tag,
} of tagsWithTypes) {
// eslint-disable-next-line complexity -- Refactor
traverse(parsedType, (nde, parentNode) => {
/**
* @type {import('jsdoc-type-pratt-parser').NameResult & {
Expand Down Expand Up @@ -501,8 +506,10 @@ export default iterateJsdoc(({
!importTags.includes(val) &&
!extraTypes.includes(val) &&
!typedefDeclarations.includes(val) &&
!globalTypes.includes(val) &&
currNode && 'right' in currNode &&
currNode.right?.type === 'JsdocTypeProperty') {
currNode.right?.type === 'JsdocTypeProperty'
) {
val = val + '.' + currNode.right.value;
}
} while (currNode?.type === 'JsdocTypeNamePath');
Expand Down
13 changes: 13 additions & 0 deletions test/rules/assertions/noUndefinedTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1857,5 +1857,18 @@ export default /** @type {import('../index.js').TestCases} */ ({
};
`,
},
{
code: `
class Storage {
/** @type {globalThis.localStorage} */
#storage
}
`,
languageOptions: {
globals: {
localStorage: 'readonly',
},
},
},
],
});
Loading