Skip to content

Commit efbcb1c

Browse files
authored
fix(no-undefined-types): exempt import tags from property checks; fixes #1416 (#1417)
1 parent e9ff4c7 commit efbcb1c

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

docs/rules/no-undefined-types.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,5 +943,33 @@ export class Code {
943943
/** @type {AGlobal.AnotherMethod} */
944944
static #test5
945945
}
946+
947+
import jsdoc from "eslint-plugin-jsdoc";
948+
949+
/**
950+
* @import { Linter } from "eslint"
951+
*/
952+
953+
/**
954+
* @type {Linter.Config}
955+
*/
956+
export default [
957+
{
958+
plugins: { jsdoc },
959+
rules: {
960+
"jsdoc/no-undefined-types": "error"
961+
}
962+
}
963+
];
964+
965+
/**
966+
* @typedef {object} Abc
967+
* @property {string} def Some string
968+
*/
969+
970+
/**
971+
* @type {Abc['def']}
972+
*/
973+
export const a = 'someString';
946974
````
947975

src/rules/noUndefinedTypes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,8 @@ export default iterateJsdoc(({
440440
// Avoid appending for imports and globals since we don't want to
441441
// check their properties which may or may not exist
442442
!imports.includes(val) && !globals.includes(val) &&
443+
!importTags.includes(val) &&
444+
!typedefDeclarations.includes(val) &&
443445
currNode && 'right' in currNode &&
444446
currNode.right?.type === 'JsdocTypeProperty') {
445447
val = val + '.' + currNode.right.value;

test/rules/assertions/noUndefinedTypes.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,5 +1657,40 @@ export default /** @type {import('../index.js').TestCases} */ ({
16571657
parser: typescriptEslintParser,
16581658
},
16591659
},
1660+
{
1661+
code: `
1662+
import jsdoc from "eslint-plugin-jsdoc";
1663+
1664+
/**
1665+
* @import { Linter } from "eslint"
1666+
*/
1667+
1668+
/**
1669+
* @type {Linter.Config}
1670+
*/
1671+
export default [
1672+
{
1673+
plugins: { jsdoc },
1674+
rules: {
1675+
"jsdoc/no-undefined-types": "error"
1676+
}
1677+
}
1678+
];
1679+
`,
1680+
},
1681+
{
1682+
code: `
1683+
/**
1684+
* @typedef {object} Abc
1685+
* @property {string} def Some string
1686+
*/
1687+
1688+
/**
1689+
* @type {Abc['def']}
1690+
*/
1691+
export const a = 'someString';
1692+
1693+
`,
1694+
},
16601695
],
16611696
});

0 commit comments

Comments
 (0)