Skip to content

Commit

Permalink
fix(check-tag-names): should have previously auto-allowed `settings…
Browse files Browse the repository at this point in the history
….jsdoc.structuredTags` tags
  • Loading branch information
brettz9 committed Jan 23, 2021
1 parent 3896162 commit 5f586fd
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .README/rules/check-tag-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ Because the tags indicated as replacements in
`settings.jsdoc.tagNamePreference` will automatically be considered as valid,
the above works.

Likewise are the tag keys of `settings.jsdoc.structuredTags` automatically
considered as valid (as their defining an expected structure for tags implies
the tags may be used).

For [TypeScript](https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html#supported-jsdoc)
(or Closure), when `settings.jsdoc.mode` is set to `typescript` or `closure`,
one may also use the following:
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3394,6 +3394,10 @@ Because the tags indicated as replacements in
`settings.jsdoc.tagNamePreference` will automatically be considered as valid,
the above works.

Likewise are the tag keys of `settings.jsdoc.structuredTags` automatically
considered as valid (as their defining an expected structure for tags implies
the tags may be used).

For [TypeScript](https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html#supported-jsdoc)
(or Closure), when `settings.jsdoc.mode` is set to `typescript` or `closure`,
one may also use the following:
Expand Down Expand Up @@ -3476,6 +3480,11 @@ The following patterns are considered problems:
let a;
// Message: Invalid JSDoc tag name "typoo".

/** @typoo {string} */
let a;
// Settings: {"jsdoc":{"structuredTags":{"parameter":{"name":"namepath-referencing","required":["type","name"],"type":true}}}}
// Message: Invalid JSDoc tag name "typoo".

/**
* @Param
*/
Expand Down Expand Up @@ -3829,6 +3838,14 @@ function quux (foo) {
}
// Settings: {"jsdoc":{"tagNamePreference":{"param":"arg"}}}

/**
* @parameter foo
*/
function quux (foo) {

}
// Settings: {"jsdoc":{"structuredTags":{"parameter":{"name":"namepath-referencing","required":["type","name"],"type":true}}}}

/**
* @bar foo
*/
Expand Down
8 changes: 6 additions & 2 deletions src/rules/checkTagNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export default iterateJsdoc(({
const {definedTags = []} = context.options[0] || {};

let definedPreferredTags = [];
const {tagNamePreference} = settings;
const {tagNamePreference, structuredTags} = settings;
const definedStructuredTags = Object.keys(structuredTags);
const definedNonPreferredTags = Object.keys(tagNamePreference);
if (definedNonPreferredTags.length) {
definedPreferredTags = Object.values(tagNamePreference).map((preferredTag) => {
Expand All @@ -38,7 +39,10 @@ export default iterateJsdoc(({

jsdoc.tags.forEach((jsdocTag) => {
const tagName = jsdocTag.tag;
if (utils.isValidTag(tagName, [...definedTags, ...definedPreferredTags, ...definedNonPreferredTags])) {
if (utils.isValidTag(tagName, [
...definedTags, ...definedPreferredTags, ...definedNonPreferredTags,
...definedStructuredTags,
])) {
let preferredTagName = utils.getPreferredTagName({
allowObjectReturn: true,
defaultMessage: `Blacklisted tag found (\`@${tagName}\`)`,
Expand Down
44 changes: 44 additions & 0 deletions test/rules/assertions/checkTagNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,29 @@ export default {
},
],
},
{
code: `
/** @typoo {string} */
let a;
`,
errors: [
{
line: 2,
message: 'Invalid JSDoc tag name "typoo".',
},
],
settings: {
jsdoc: {
structuredTags: {
parameter: {
name: 'namepath-referencing',
required: ['type', 'name'],
type: true,
},
},
},
},
},
{
code: `
/**
Expand Down Expand Up @@ -597,6 +620,27 @@ export default {
},
},
},
{
code: `
/**
* @parameter foo
*/
function quux (foo) {
}
`,
settings: {
jsdoc: {
structuredTags: {
parameter: {
name: 'namepath-referencing',
required: ['type', 'name'],
type: true,
},
},
},
},
},
{
code: `
/**
Expand Down

0 comments on commit 5f586fd

Please sign in to comment.