Skip to content

Commit 1c38930

Browse files
sebastian-fredriksson-bernholtzbrettz9
authored andcommittedMar 17, 2025
fix(no-undefined-types): allow any available identifier; fixes #178,#1342
1 parent 6e0f752 commit 1c38930

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed
 

‎docs/rules/no-undefined-types.md

+9
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,15 @@ function quux(foo) {
807807

808808
quux(0);
809809

810+
function quux() {
811+
const foo = 1;
812+
/** {@link foo} */
813+
const bar = foo;
814+
console.log(bar);
815+
}
816+
817+
quux();
818+
810819
/**
811820
* @import BadImportIgnoredByThisRule
812821
*/

‎src/rules/noUndefinedTypes.js

+14
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,19 @@ export default iterateJsdoc(({
222222
// Program scope inside
223223
const cjsOrESMScope = globalScope.childScopes[0]?.block?.type === 'Program';
224224

225+
/**
226+
* @param {import("eslint").Scope.Scope | null} scope
227+
* @returns {Set<string>}
228+
*/
229+
const getValidRuntimeIdentifiers = (scope) => {
230+
return scope
231+
? new Set([
232+
...new Set(scope.variables.map(({ name }) => name)),
233+
...getValidRuntimeIdentifiers(scope.upper),
234+
])
235+
: new Set();
236+
};
237+
225238
const allDefinedTypes = new Set(globalScope.variables.map(({
226239
name,
227240
}) => {
@@ -247,6 +260,7 @@ export default iterateJsdoc(({
247260
.concat(importTags)
248261
.concat(definedTypes)
249262
.concat(/** @type {string[]} */ (definedPreferredTypes))
263+
.concat(...getValidRuntimeIdentifiers(node && sourceCode.getScope(node)))
250264
.concat(
251265
settings.mode === 'jsdoc' ?
252266
[] :

‎test/rules/assertions/noUndefinedTypes.js

+12
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,18 @@ export default /** @type {import('../index.js').TestCases} */ ({
14821482
'no-unused-vars': 'error',
14831483
},
14841484
},
1485+
{
1486+
code: `
1487+
function quux() {
1488+
const foo = 1;
1489+
/** {@link foo} */
1490+
const bar = foo;
1491+
console.log(bar);
1492+
}
1493+
1494+
quux();
1495+
`,
1496+
},
14851497
{
14861498
code: `
14871499
/**

0 commit comments

Comments
 (0)
Please sign in to comment.