Skip to content

Commit b6e2699

Browse files
committed
fix(valid-types): ensure when in closure mode, that this and define tags have types
1 parent 7022f65 commit b6e2699

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9058,6 +9058,13 @@ function quux () {}
90589058
function quux () {}
90599059
// Settings: {"jsdoc":{"mode":"closure"}}
90609060
// Message: Syntax error in type: BadTypeChecked<
9061+
9062+
/**
9063+
* @define
9064+
*/
9065+
function quux () {}
9066+
// Settings: {"jsdoc":{"mode":"closure"}}
9067+
// Message: Tag @define must have a type
90619068
````
90629069
90639070
The following patterns are not considered problems:
@@ -9227,6 +9234,11 @@ function quux () {}
92279234
*/
92289235
function quux () {}
92299236
// Settings: {"jsdoc":{"mode":"closure"}}
9237+
9238+
/**
9239+
* @define
9240+
*/
9241+
function quux () {}
92309242
````
92319243
92329244

src/iterateJsdoc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ const getUtils = (
215215
};
216216

217217
utils.tagMustHaveTypePosition = (tagName) => {
218-
return jsdocUtils.tagMustHaveTypePosition(tagName);
218+
return jsdocUtils.tagMustHaveTypePosition(mode, tagName);
219219
};
220220

221221
utils.tagMightHaveTypePosition = (tagName) => {

src/jsdocUtils.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,11 @@ const tagMightHaveTypePosition = (mode, tag) => {
345345
tagsWithOptionalTypePosition.includes(tag);
346346
};
347347

348-
const tagMustHaveTypePosition = (tag) => {
348+
const tagMustHaveTypePosition = (mode, tag) => {
349+
if (mode === 'closure') {
350+
return tagsWithMandatoryTypePositionClosure.includes(tag);
351+
}
352+
349353
return tagsWithMandatoryTypePosition.includes(tag);
350354
};
351355

test/rules/assertions/validTypes.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,25 @@ export default {
304304
},
305305
},
306306
},
307+
{
308+
code: `
309+
/**
310+
* @define
311+
*/
312+
function quux () {}
313+
`,
314+
errors: [
315+
{
316+
line: 3,
317+
message: 'Tag @define must have a type',
318+
},
319+
],
320+
settings: {
321+
jsdoc: {
322+
mode: 'closure',
323+
},
324+
},
325+
},
307326
],
308327
valid: [
309328
{
@@ -566,5 +585,13 @@ export default {
566585
},
567586
},
568587
},
588+
{
589+
code: `
590+
/**
591+
* @define
592+
*/
593+
function quux () {}
594+
`,
595+
},
569596
],
570597
};

0 commit comments

Comments
 (0)