Skip to content

Commit 4901870

Browse files
SulimanAbdulrazzaqbrettz9
authored andcommitted
fix(prefer-import-tag): only exempt @typedef itself, not every name-defining tag
With the default `exemptTypedefs`, the rule skipped the `import()` types of `@param`, `@property`, `@const` and the other name-defining tags, so they were never reported or fixed. Only `@typedef` defines a type alias.
1 parent df6e281 commit 4901870

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

‎src/rules/preferImportTag.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,9 @@ export default iterateJsdoc(({
491491
for (const tag of jsdoc.tags) {
492492
const mightHaveTypePosition = utils.tagMightHaveTypePosition(tag.tag);
493493
const hasTypePosition = mightHaveTypePosition === true && Boolean(tag.type);
494-
if (hasTypePosition && (!exemptTypedefs || !utils.isNameOrNamepathDefiningTag(tag.tag))) {
494+
// Only the `@typedef` itself is exempt; `@param`, `@property`, `@const`,
495+
// etc. are not type aliases and their `import()` types are reported
496+
if (hasTypePosition && (!exemptTypedefs || tag.tag !== 'typedef')) {
495497
iterateInlineImports(tag);
496498
}
497499
}

‎test/rules/assertions/preferImportTag.js‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,10 @@ let linter;
10691069
let x;
10701070
`,
10711071
errors: [
1072+
{
1073+
line: 3,
1074+
message: 'Inline `import()` found; prefer `@import`',
1075+
},
10721076
{
10731077
line: 7,
10741078
message: 'Inline `import()` found; prefer `@import`',
@@ -1077,11 +1081,11 @@ let linter;
10771081
output: `
10781082
/** @import * as eslint from 'eslint'; */
10791083
/**
1080-
* @param {import('eslint').Linter} linter
1084+
* @param {eslint.Linter} linter
10811085
*/
10821086
function quux (linter) {}
10831087
1084-
/** @type {eslint.Linter} */
1088+
/** @type {import('eslint').Linter} */
10851089
let x;
10861090
`,
10871091
},
@@ -1098,6 +1102,10 @@ let linter;
10981102
function load () {}
10991103
`,
11001104
errors: [
1105+
{
1106+
line: 4,
1107+
message: 'Inline `import()` found; prefer `@import`',
1108+
},
11011109
{
11021110
line: 8,
11031111
message: 'Inline `import()` found; prefer `@import`',
@@ -1107,11 +1115,11 @@ let linter;
11071115
/** @import * as $k$$l$config$k$js from './config.js'; */
11081116
/**
11091117
* @typedef {object} Options
1110-
* @property {import('./config.js').Config} config
1118+
* @property {$k$$l$config$k$js.Config} config
11111119
*/
11121120
11131121
/**
1114-
* @returns {$k$$l$config$k$js.Config}
1122+
* @returns {import('./config.js').Config}
11151123
*/
11161124
function load () {}
11171125
`,
@@ -1125,17 +1133,21 @@ let linter;
11251133
let x;
11261134
`,
11271135
errors: [
1136+
{
1137+
line: 2,
1138+
message: 'Inline `import()` found; prefer `@import`',
1139+
},
11281140
{
11291141
line: 5,
11301142
message: 'Inline `import()` found; prefer `@import`',
11311143
},
11321144
],
11331145
output: `
11341146
/** @import * as eslint from 'eslint'; */
1135-
/** @const {import('eslint').Linter} LINTER */
1147+
/** @const {eslint.Linter} LINTER */
11361148
const LINTER = getLinter();
11371149
1138-
/** @type {eslint.Linter} */
1150+
/** @type {import('eslint').Linter} */
11391151
let x;
11401152
`,
11411153
},

0 commit comments

Comments
 (0)