Skip to content

Commit 7763b99

Browse files
JoshuaKGoldbergbrettz9
authored andcommitted
Fixed up defaulting and such
1 parent abf466d commit 7763b99

File tree

3 files changed

+52
-16
lines changed

3 files changed

+52
-16
lines changed

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4605,14 +4605,14 @@ let a;
46054605
/** @abstract */
46064606
let a;
46074607
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
4608-
// Message: '@abstract' is generally redundant outside of `declare` contexts when using a type system.
4608+
// Message: '@abstract' is redundant outside of ambient (`declare`/`.d.ts`) contexts when using a type system.
46094609

46104610
const a = {
46114611
/** @abstract */
46124612
b: true,
46134613
};
46144614
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
4615-
// Message: '@abstract' is generally redundant outside of `declare` contexts when using a type system.
4615+
// Message: '@abstract' is redundant outside of ambient (`declare`/`.d.ts`) contexts when using a type system.
46164616

46174617
/** @template */
46184618
let a;
@@ -4984,6 +4984,14 @@ function Test() {
49844984
The following patterns are not considered problems:
49854985

49864986
````js
4987+
/** @default 0 */
4988+
let a;
4989+
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
4990+
4991+
/** @default 0 */
4992+
declare let a;
4993+
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
4994+
49874995
/** @abstract */
49884996
let a;
49894997
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
@@ -5002,13 +5010,9 @@ function test() {
50025010
}
50035011
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
50045012

5005-
/** @abstract - default */
5006-
let a;
5007-
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
5008-
50095013
/** @template name */
50105014
let a;
5011-
// "jsdoc/check-tag-names": ["error"|"warn", {"definedTags":["template"],"typed":true}]
5015+
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
50125016

50135017
/** @param param - takes information */
50145018
function takesOne(param) {}

src/rules/checkTagNames.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ const typedTagsAlwaysUnnecessary = new Set([
2525
'typedef',
2626
]);
2727

28+
const typedTagsNeedingName = new Set([
29+
'template',
30+
]);
31+
2832
const typedTagsUnnecessaryOutsideDeclare = new Set([
2933
'abstract',
3034
'access',
@@ -114,7 +118,7 @@ export default iterateJsdoc(({
114118
return false;
115119
}
116120

117-
if (jsdocTag.name === 'default') {
121+
if (jsdocTag.tag === 'default') {
118122
return false;
119123
}
120124

@@ -159,8 +163,8 @@ export default iterateJsdoc(({
159163
return true;
160164
}
161165

162-
if (jsdocTag.tag === 'template' && !jsdocTag.name) {
163-
reportWithTypeRemovalFixer('\'@template\' without a name is redundant when using a type system.', jsdocTag, tagIndex);
166+
if (typedTagsNeedingName.has(jsdocTag.tag) && !jsdocTag.name) {
167+
reportWithTypeRemovalFixer(`'@${jsdocTag.tag}' without a name is redundant when using a type system.`, jsdocTag, tagIndex);
164168
return true;
165169
}
166170

@@ -178,10 +182,15 @@ export default iterateJsdoc(({
178182
continue;
179183
}
180184

181-
if (utils.isValidTag(tagName, [
182-
...definedTags, ...definedPreferredTags, ...definedNonPreferredTags,
185+
const validTags = [
186+
...definedTags,
187+
...definedPreferredTags,
188+
...definedNonPreferredTags,
183189
...definedStructuredTags,
184-
])) {
190+
...typed ? typedTagsNeedingName : [],
191+
];
192+
193+
if (utils.isValidTag(tagName, validTags)) {
185194
let preferredTagName = utils.getPreferredTagName({
186195
allowObjectReturn: true,
187196
defaultMessage: `Blacklisted tag found (\`@${tagName}\`)`,

test/rules/assertions/checkTagNames.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,32 @@ export default {
885885
},
886886
],
887887
valid: [
888+
{
889+
code: `
890+
/** @default 0 */
891+
let a;
892+
`,
893+
filename: 'file.ts',
894+
options: [
895+
{
896+
typed: true,
897+
},
898+
],
899+
parser: require.resolve('@typescript-eslint/parser'),
900+
},
901+
{
902+
code: `
903+
/** @default 0 */
904+
declare let a;
905+
`,
906+
filename: 'file.d.ts',
907+
options: [
908+
{
909+
typed: true,
910+
},
911+
],
912+
parser: require.resolve('@typescript-eslint/parser'),
913+
},
888914
{
889915
code: `
890916
/** @abstract */
@@ -945,9 +971,6 @@ export default {
945971
`,
946972
options: [
947973
{
948-
definedTags: [
949-
'template',
950-
],
951974
typed: true,
952975
},
953976
],

0 commit comments

Comments
 (0)