Skip to content

Commit

Permalink
fix(valid-types): ensure when in closure mode, that this and `def…
Browse files Browse the repository at this point in the history
…ine` tags have types
  • Loading branch information
brettz9 committed Dec 1, 2019
1 parent 7022f65 commit b6e2699
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
12 changes: 12 additions & 0 deletions README.md
Expand Up @@ -9058,6 +9058,13 @@ function quux () {}
function quux () {}
// Settings: {"jsdoc":{"mode":"closure"}}
// Message: Syntax error in type: BadTypeChecked<
/**
* @define
*/
function quux () {}
// Settings: {"jsdoc":{"mode":"closure"}}
// Message: Tag @define must have a type
````
The following patterns are not considered problems:
Expand Down Expand Up @@ -9227,6 +9234,11 @@ function quux () {}
*/
function quux () {}
// Settings: {"jsdoc":{"mode":"closure"}}
/**
* @define
*/
function quux () {}
````
2 changes: 1 addition & 1 deletion src/iterateJsdoc.js
Expand Up @@ -215,7 +215,7 @@ const getUtils = (
};

utils.tagMustHaveTypePosition = (tagName) => {
return jsdocUtils.tagMustHaveTypePosition(tagName);
return jsdocUtils.tagMustHaveTypePosition(mode, tagName);
};

utils.tagMightHaveTypePosition = (tagName) => {
Expand Down
6 changes: 5 additions & 1 deletion src/jsdocUtils.js
Expand Up @@ -345,7 +345,11 @@ const tagMightHaveTypePosition = (mode, tag) => {
tagsWithOptionalTypePosition.includes(tag);
};

const tagMustHaveTypePosition = (tag) => {
const tagMustHaveTypePosition = (mode, tag) => {
if (mode === 'closure') {
return tagsWithMandatoryTypePositionClosure.includes(tag);
}

return tagsWithMandatoryTypePosition.includes(tag);
};

Expand Down
27 changes: 27 additions & 0 deletions test/rules/assertions/validTypes.js
Expand Up @@ -304,6 +304,25 @@ export default {
},
},
},
{
code: `
/**
* @define
*/
function quux () {}
`,
errors: [
{
line: 3,
message: 'Tag @define must have a type',
},
],
settings: {
jsdoc: {
mode: 'closure',
},
},
},
],
valid: [
{
Expand Down Expand Up @@ -566,5 +585,13 @@ export default {
},
},
},
{
code: `
/**
* @define
*/
function quux () {}
`,
},
],
};

0 comments on commit b6e2699

Please sign in to comment.