Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5013,6 +5013,27 @@ function Test() {
}
// Settings: {"jsdoc":{"tagNamePreference":{"returns":"return"}}}
// Message: Invalid JSDoc tag (preference). Replace "constructor" JSDoc tag with "class".

/** @typedef {Object} MyObject
* @property {string} id - my id
*/
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
// Message: '@typedef' is redundant when using a type system.

/**
* @property {string} id - my id
*/
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
// Message: '@property' is redundant when using a type system.

/** @typedef {Object} MyObject */
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
// Message: '@typedef' is redundant when using a type system.

/** @typedef {Object} MyObject
*/
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
// Message: '@typedef' is redundant when using a type system.
````

The following patterns are not considered problems:
Expand Down
10 changes: 7 additions & 3 deletions src/iterateJsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,15 @@ const getUtils = (
} = jsdoc.source[spliceIdx].tokens;

/* istanbul ignore if -- Currently want to clear entirely if removing tags */
if (!removeEmptyBlock && (end || delimiter === '/**')) {
if (
spliceIdx === 0 && jsdoc.tags.length >= 2 ||
!removeEmptyBlock && (end || delimiter === '/**')
) {
const {
tokens,
} = jsdoc.source[spliceIdx];
for (const item of [
'postDelimiter',
'tag',
'postTag',
'type',
Expand All @@ -423,10 +427,10 @@ const getUtils = (
tokens[item] = '';
}
} else {
jsdoc.source.splice(spliceIdx, spliceCount - tagSourceOffset);
jsdoc.source.splice(spliceIdx, spliceCount - tagSourceOffset + (spliceIdx ? 0 : jsdoc.source.length));
tagSource.splice(tagIdx + tagSourceOffset, spliceCount - tagSourceOffset + (spliceIdx ? 0 : jsdoc.source.length));
}

tagSource.splice(tagIdx + tagSourceOffset, spliceCount - tagSourceOffset);
lastIndex = sourceIndex;

return true;
Expand Down
87 changes: 87 additions & 0 deletions test/rules/assertions/checkTagNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,93 @@ export default {
},
},
},
{
code: `
/** @typedef {Object} MyObject
* @property {string} id - my id
*/
`,
errors: [
{
line: 2,
message: '\'@typedef\' is redundant when using a type system.',
},
{
line: 3,
message: '\'@property\' is redundant when using a type system.',
},
],
options: [
{
typed: true,
},
],
output: `
/**
* @property {string} id - my id
*/
`,
},
{
code: `
/**
* @property {string} id - my id
*/
`,
errors: [
{
line: 3,
message: '\'@property\' is redundant when using a type system.',
},
],
options: [
{
typed: true,
},
],
output: `
/**
* id - my id
*/
`,
},
{
code: `
/** @typedef {Object} MyObject */
`,
errors: [
{
line: 2,
message: '\'@typedef\' is redundant when using a type system.',
},
],
options: [
{
typed: true,
},
],
output: `
`,
},
{
code: `
/** @typedef {Object} MyObject
*/
`,
errors: [
{
line: 2,
message: '\'@typedef\' is redundant when using a type system.',
},
],
options: [
{
typed: true,
},
],
output: `
`,
},
],
valid: [
{
Expand Down