Skip to content

Commit

Permalink
Add suppressCommentWarningsInDeclarationFiles option
Browse files Browse the repository at this point in the history
Resolves #2611
  • Loading branch information
Gerrit0 committed Jun 23, 2024
1 parent 8ebd7db commit 657eb4b
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Unreleased

### Features

- Added a `--suppressCommentWarningsInDeclarationFiles` option to disable warnings from
parsing comments in declaration files, #2611.

### Bug Fixes

- The `text` non-highlighted language no longer causes warnings when rendering, #2610.
Expand Down
1 change: 1 addition & 0 deletions src/lib/converter/comments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface CommentParserConfig {
inlineTags: Set<string>;
modifierTags: Set<string>;
jsDocCompatibility: JsDocCompatibility;
suppressCommentWarningsInDeclarationFiles: boolean;
}

const jsDocCommentKinds = [
Expand Down
7 changes: 7 additions & 0 deletions src/lib/converter/comments/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ export function parseComment(
return comment;

function warningImpl(message: TranslatedString, token: Token) {
if (
config.suppressCommentWarningsInDeclarationFiles &&
file.fileName.endsWith(".d.ts")
) {
return;
}
logger.warn(message, token.pos, file);
}
}
Expand All @@ -135,6 +141,7 @@ export function parseCommentString(
ignoreUnescapedBraces: true,
inheritDocTag: true,
},
suppressCommentWarningsInDeclarationFiles: true,
};

const reentry = new TextParserReentryState();
Expand Down
4 changes: 4 additions & 0 deletions src/lib/converter/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,10 @@ export class Converter extends ChildableComponent<
),
jsDocCompatibility:
this.application.options.getValue("jsDocCompatibility"),
suppressCommentWarningsInDeclarationFiles:
this.application.options.getValue(
"suppressCommentWarningsInDeclarationFiles",
),
};

// Can't be included in options because the TSDoc parser blows up if we do.
Expand Down
1 change: 1 addition & 0 deletions src/lib/utils/options/declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ export interface TypeDocOptionMap {
useTsLinkResolution: boolean;
preserveLinkText: boolean;
jsDocCompatibility: JsDocCompatibility;
suppressCommentWarningsInDeclarationFiles: boolean;
blockTags: `@${string}`[];
inlineTags: `@${string}`[];
modifierTags: `@${string}`[];
Expand Down
6 changes: 6 additions & 0 deletions src/lib/utils/options/sources/typedoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,12 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
},
});

options.addDeclaration({
name: "suppressCommentWarningsInDeclarationFiles",
help: (i18n) => i18n.help_lang(),
type: ParameterType.Boolean,
});

options.addDeclaration({
name: "commentStyle",
help: (i18n) => i18n.help_commentStyle(),
Expand Down
1 change: 1 addition & 0 deletions src/test/comments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,7 @@ describe("Comment Parser", () => {
ignoreUnescapedBraces: false,
inheritDocTag: false,
},
suppressCommentWarningsInDeclarationFiles: false,
};

it("Should recognize @defaultValue as code", () => {
Expand Down
4 changes: 4 additions & 0 deletions src/test/converter2/issues/gh2611.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* @tagThatIsNotDefined
*/
export var num: number;
13 changes: 13 additions & 0 deletions src/test/issues.c2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1589,4 +1589,17 @@ describe("Issue Tests", () => {

logger.expectNoOtherMessages();
});

it("#2611 can suppress warnings from comments in declaration files", () => {
convert();
logger.expectMessage(
"warn: Encountered an unknown block tag @tagThatIsNotDefined",
);
logger.expectNoOtherMessages();
logger.reset();

app.options.setValue("suppressCommentWarningsInDeclarationFiles", true);
convert();
logger.expectNoOtherMessages();
});
});

0 comments on commit 657eb4b

Please sign in to comment.