Skip to content

Commit 657eb4b

Browse files
committed
Add suppressCommentWarningsInDeclarationFiles option
Resolves #2611
1 parent 8ebd7db commit 657eb4b

File tree

9 files changed

+42
-0
lines changed

9 files changed

+42
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Unreleased
22

3+
### Features
4+
5+
- Added a `--suppressCommentWarningsInDeclarationFiles` option to disable warnings from
6+
parsing comments in declaration files, #2611.
7+
38
### Bug Fixes
49

510
- The `text` non-highlighted language no longer causes warnings when rendering, #2610.

src/lib/converter/comments/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export interface CommentParserConfig {
2222
inlineTags: Set<string>;
2323
modifierTags: Set<string>;
2424
jsDocCompatibility: JsDocCompatibility;
25+
suppressCommentWarningsInDeclarationFiles: boolean;
2526
}
2627

2728
const jsDocCommentKinds = [

src/lib/converter/comments/parser.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ export function parseComment(
109109
return comment;
110110

111111
function warningImpl(message: TranslatedString, token: Token) {
112+
if (
113+
config.suppressCommentWarningsInDeclarationFiles &&
114+
file.fileName.endsWith(".d.ts")
115+
) {
116+
return;
117+
}
112118
logger.warn(message, token.pos, file);
113119
}
114120
}
@@ -135,6 +141,7 @@ export function parseCommentString(
135141
ignoreUnescapedBraces: true,
136142
inheritDocTag: true,
137143
},
144+
suppressCommentWarningsInDeclarationFiles: true,
138145
};
139146

140147
const reentry = new TextParserReentryState();

src/lib/converter/converter.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,10 @@ export class Converter extends ChildableComponent<
693693
),
694694
jsDocCompatibility:
695695
this.application.options.getValue("jsDocCompatibility"),
696+
suppressCommentWarningsInDeclarationFiles:
697+
this.application.options.getValue(
698+
"suppressCommentWarningsInDeclarationFiles",
699+
),
696700
};
697701

698702
// Can't be included in options because the TSDoc parser blows up if we do.

src/lib/utils/options/declaration.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ export interface TypeDocOptionMap {
196196
useTsLinkResolution: boolean;
197197
preserveLinkText: boolean;
198198
jsDocCompatibility: JsDocCompatibility;
199+
suppressCommentWarningsInDeclarationFiles: boolean;
199200
blockTags: `@${string}`[];
200201
inlineTags: `@${string}`[];
201202
modifierTags: `@${string}`[];

src/lib/utils/options/sources/typedoc.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,12 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
685685
},
686686
});
687687

688+
options.addDeclaration({
689+
name: "suppressCommentWarningsInDeclarationFiles",
690+
help: (i18n) => i18n.help_lang(),
691+
type: ParameterType.Boolean,
692+
});
693+
688694
options.addDeclaration({
689695
name: "commentStyle",
690696
help: (i18n) => i18n.help_commentStyle(),

src/test/comments.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,7 @@ describe("Comment Parser", () => {
10941094
ignoreUnescapedBraces: false,
10951095
inheritDocTag: false,
10961096
},
1097+
suppressCommentWarningsInDeclarationFiles: false,
10971098
};
10981099

10991100
it("Should recognize @defaultValue as code", () => {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* @tagThatIsNotDefined
3+
*/
4+
export var num: number;

src/test/issues.c2.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,4 +1589,17 @@ describe("Issue Tests", () => {
15891589

15901590
logger.expectNoOtherMessages();
15911591
});
1592+
1593+
it("#2611 can suppress warnings from comments in declaration files", () => {
1594+
convert();
1595+
logger.expectMessage(
1596+
"warn: Encountered an unknown block tag @tagThatIsNotDefined",
1597+
);
1598+
logger.expectNoOtherMessages();
1599+
logger.reset();
1600+
1601+
app.options.setValue("suppressCommentWarningsInDeclarationFiles", true);
1602+
convert();
1603+
logger.expectNoOtherMessages();
1604+
});
15921605
});

0 commit comments

Comments
 (0)