Skip to content

Commit c51ee4f

Browse files
authored
fix(no-undefined-types): exempt global requires from undefined property checks; fixes #1425 (#1426)
1 parent feb65e4 commit c51ee4f

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

docs/rules/no-undefined-types.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,5 +996,13 @@ class SomeClass {
996996
*
997997
* @member {Intl.Collator}
998998
*/
999+
1000+
const otherFile = require('./other-file');
1001+
1002+
/**
1003+
* A function
1004+
* @param {otherFile.MyType} a
1005+
*/
1006+
function f(a) {}
9991007
````
10001008

src/rules/noUndefinedTypes.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,19 @@ export default iterateJsdoc(({
312312
return `${name}.${property}`;
313313
}).filter(Boolean),
314314
];
315+
case 'VariableDeclarator':
316+
if (/** @type {import('@typescript-eslint/types').TSESTree.Identifier} */ (
317+
/** @type {import('@typescript-eslint/types').TSESTree.CallExpression} */ (
318+
globalItem?.init
319+
)?.callee)?.name === 'require'
320+
) {
321+
imports.push(/** @type {import('@typescript-eslint/types').TSESTree.Identifier} */ (
322+
globalItem.id
323+
).name);
324+
break;
325+
}
326+
327+
return [];
315328
}
316329

317330
return [

test/rules/assertions/noUndefinedTypes.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,5 +1729,16 @@ export default /** @type {import('../index.js').TestCases} */ ({
17291729
*/
17301730
`,
17311731
},
1732+
{
1733+
code: `
1734+
const otherFile = require('./other-file');
1735+
1736+
/**
1737+
* A function
1738+
* @param {otherFile.MyType} a
1739+
*/
1740+
function f(a) {}
1741+
`,
1742+
},
17321743
],
17331744
});

0 commit comments

Comments
 (0)