Skip to content

Commit 977c604

Browse files
committed
Fix #3070
1 parent 6aba264 commit 977c604

5 files changed

Lines changed: 27 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ title: Changelog
99
- Improved handling of comments for type aliases which have been declaration merged with functions, #3064.
1010
- Fixed anchor link generation to members named `$`, #3065.
1111
- Corrected typing of the `plugin` option to permit functions, #3066.
12+
- Warnings about unused `@param` tags will now be properly suppressed when they come from declaration files and
13+
the suppressCommentWarningsInDeclarationFiles option is enabled, #3070.
1214
- Fixed conversion of types referencing type parameters on functions, #3071.
1315

1416
### Thanks!

src/lib/converter/plugins/CommentPlugin.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ export class CommentPlugin extends ConverterComponent {
148148
@Option("defaultCategory")
149149
accessor defaultCategory!: string;
150150

151+
@Option("suppressCommentWarningsInDeclarationFiles")
152+
accessor suppressCommentWarningsInDeclarationFiles!: boolean;
153+
151154
private _excludeKinds: number | undefined;
152155
private get excludeNotDocumentedKinds(): number {
153156
this._excludeKinds ??= this.application.options
@@ -406,7 +409,8 @@ export class CommentPlugin extends ConverterComponent {
406409
if (reflection.comment) {
407410
if (
408411
reflection.comment.label &&
409-
!/[A-Z_][A-Z0-9_]/.test(reflection.comment.label)
412+
!/[A-Z_][A-Z0-9_]/.test(reflection.comment.label) &&
413+
!this.suppressCommentWarnings(reflection.comment)
410414
) {
411415
context.logger.warn(
412416
i18n.label_0_for_1_cannot_be_referenced(
@@ -421,7 +425,7 @@ export class CommentPlugin extends ConverterComponent {
421425
group,
422426
reflection.comment.modifierTags,
423427
);
424-
if (intersect.size > 1) {
428+
if (intersect.size > 1 && !this.suppressCommentWarnings(reflection.comment)) {
425429
const [a, b] = intersect;
426430
context.logger.warn(
427431
i18n.modifier_tag_0_is_mutually_exclusive_with_1_in_comment_for_2(
@@ -724,7 +728,7 @@ export class CommentPlugin extends ConverterComponent {
724728

725729
moveNestedParamTags(/* in-out */ paramTags, params, comment.sourcePath);
726730

727-
if (!comment.inheritedFromParentDeclaration) {
731+
if (!comment.inheritedFromParentDeclaration && !this.suppressCommentWarnings(comment)) {
728732
for (const tag of paramTags) {
729733
this.application.logger.warn(
730734
i18n.signature_0_has_unused_param_with_name_1(
@@ -735,6 +739,11 @@ export class CommentPlugin extends ConverterComponent {
735739
}
736740
}
737741
}
742+
743+
private suppressCommentWarnings(comment: Comment) {
744+
return this.suppressCommentWarningsInDeclarationFiles &&
745+
/\.d\.(ts|mts|cts)$/.test(comment.sourcePath || "");
746+
}
738747
}
739748

740749
function inTypeLiteral(refl: Reflection | undefined) {

src/lib/utils-common/path.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,8 @@ export namespace NormalizedPathUtils {
161161
}
162162
return { name: name.substring(0, lastDot), ext: name.substring(lastDot) };
163163
}
164+
165+
export function isDeclarationFilePath(path: NormalizedPath) {
166+
return /\.d\.(ts|mts|cts)$/.test(path);
167+
}
164168
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export class NumberArray extends Array<number> {
2+
foo() {}
3+
}

src/test/issues.c2.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2304,6 +2304,12 @@ describe("Issue Tests", () => {
23042304
equal(Comment.combineDisplayParts(project.children[1].signatures?.[0].comment?.summary), "B");
23052305
});
23062306

2307+
it("#3070 does not warn due to bad comment in declaration file", () => {
2308+
app.options.setValue("excludeExternals", false);
2309+
app.options.setValue("suppressCommentWarningsInDeclarationFiles", true);
2310+
convert();
2311+
});
2312+
23072313
it("#3071 correctly handles substitution types", () => {
23082314
const project = convert();
23092315
const m = querySig(project, "m");

0 commit comments

Comments
 (0)