Skip to content

Commit 4f3c48e

Browse files
committed
fix: tag removal for 0-line tags (if other tags present, only blank out the tag; otherwise, remove to end of block); fixes #1040
1 parent 152e8c2 commit 4f3c48e

File tree

3 files changed

+115
-3
lines changed

3 files changed

+115
-3
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5013,6 +5013,27 @@ function Test() {
50135013
}
50145014
// Settings: {"jsdoc":{"tagNamePreference":{"returns":"return"}}}
50155015
// Message: Invalid JSDoc tag (preference). Replace "constructor" JSDoc tag with "class".
5016+
5017+
/** @typedef {Object} MyObject
5018+
* @property {string} id - my id
5019+
*/
5020+
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
5021+
// Message: '@typedef' is redundant when using a type system.
5022+
5023+
/**
5024+
* @property {string} id - my id
5025+
*/
5026+
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
5027+
// Message: '@property' is redundant when using a type system.
5028+
5029+
/** @typedef {Object} MyObject */
5030+
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
5031+
// Message: '@typedef' is redundant when using a type system.
5032+
5033+
/** @typedef {Object} MyObject
5034+
*/
5035+
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
5036+
// Message: '@typedef' is redundant when using a type system.
50165037
````
50175038

50185039
The following patterns are not considered problems:

src/iterateJsdoc.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,11 +407,15 @@ const getUtils = (
407407
} = jsdoc.source[spliceIdx].tokens;
408408

409409
/* istanbul ignore if -- Currently want to clear entirely if removing tags */
410-
if (!removeEmptyBlock && (end || delimiter === '/**')) {
410+
if (
411+
spliceIdx === 0 && jsdoc.tags.length >= 2 ||
412+
!removeEmptyBlock && (end || delimiter === '/**')
413+
) {
411414
const {
412415
tokens,
413416
} = jsdoc.source[spliceIdx];
414417
for (const item of [
418+
'postDelimiter',
415419
'tag',
416420
'postTag',
417421
'type',
@@ -423,10 +427,10 @@ const getUtils = (
423427
tokens[item] = '';
424428
}
425429
} else {
426-
jsdoc.source.splice(spliceIdx, spliceCount - tagSourceOffset);
430+
jsdoc.source.splice(spliceIdx, spliceCount - tagSourceOffset + (spliceIdx ? 0 : jsdoc.source.length));
431+
tagSource.splice(tagIdx + tagSourceOffset, spliceCount - tagSourceOffset + (spliceIdx ? 0 : jsdoc.source.length));
427432
}
428433

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

432436
return true;

test/rules/assertions/checkTagNames.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,93 @@ export default {
925925
},
926926
},
927927
},
928+
{
929+
code: `
930+
/** @typedef {Object} MyObject
931+
* @property {string} id - my id
932+
*/
933+
`,
934+
errors: [
935+
{
936+
line: 2,
937+
message: '\'@typedef\' is redundant when using a type system.',
938+
},
939+
{
940+
line: 3,
941+
message: '\'@property\' is redundant when using a type system.',
942+
},
943+
],
944+
options: [
945+
{
946+
typed: true,
947+
},
948+
],
949+
output: `
950+
/**
951+
* @property {string} id - my id
952+
*/
953+
`,
954+
},
955+
{
956+
code: `
957+
/**
958+
* @property {string} id - my id
959+
*/
960+
`,
961+
errors: [
962+
{
963+
line: 3,
964+
message: '\'@property\' is redundant when using a type system.',
965+
},
966+
],
967+
options: [
968+
{
969+
typed: true,
970+
},
971+
],
972+
output: `
973+
/**
974+
* id - my id
975+
*/
976+
`,
977+
},
978+
{
979+
code: `
980+
/** @typedef {Object} MyObject */
981+
`,
982+
errors: [
983+
{
984+
line: 2,
985+
message: '\'@typedef\' is redundant when using a type system.',
986+
},
987+
],
988+
options: [
989+
{
990+
typed: true,
991+
},
992+
],
993+
output: `
994+
`,
995+
},
996+
{
997+
code: `
998+
/** @typedef {Object} MyObject
999+
*/
1000+
`,
1001+
errors: [
1002+
{
1003+
line: 2,
1004+
message: '\'@typedef\' is redundant when using a type system.',
1005+
},
1006+
],
1007+
options: [
1008+
{
1009+
typed: true,
1010+
},
1011+
],
1012+
output: `
1013+
`,
1014+
},
9281015
],
9291016
valid: [
9301017
{

0 commit comments

Comments
 (0)