diff --git a/common/changes/@microsoft/tsdoc/fix-issue-453_2026-09-11-02-30.json b/common/changes/@microsoft/tsdoc/fix-issue-453_2026-09-11-02-30.json new file mode 100644 index 00000000..08de98a9 --- /dev/null +++ b/common/changes/@microsoft/tsdoc/fix-issue-453_2026-09-11-02-30.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@microsoft/tsdoc", + "comment": "Add missing tsdoc-unsupported-html-name to TSDocConfiguration.allTsdocMessageIds so eslint-plugin-tsdoc does not crash when reportUnsupportedHtmlElements is enabled (GitHub #453)", + "type": "patch" + } + ], + "packageName": "@microsoft/tsdoc" +} diff --git a/tsdoc/src/parser/TSDocMessageId.ts b/tsdoc/src/parser/TSDocMessageId.ts index ebdc4acf..f6f9e0fb 100644 --- a/tsdoc/src/parser/TSDocMessageId.ts +++ b/tsdoc/src/parser/TSDocMessageId.ts @@ -486,6 +486,7 @@ export const allTsdocMessageIds: string[] = [ 'tsdoc-text-after-html-string', 'tsdoc-missing-html-end-tag', 'tsdoc-malformed-html-name', + 'tsdoc-unsupported-html-name', 'tsdoc-code-fence-opening-indent', 'tsdoc-code-fence-specifier-syntax', 'tsdoc-code-fence-closing-indent', diff --git a/tsdoc/src/parser/__tests__/TSDocMessageId.test.ts b/tsdoc/src/parser/__tests__/TSDocMessageId.test.ts new file mode 100644 index 00000000..cbd41e43 --- /dev/null +++ b/tsdoc/src/parser/__tests__/TSDocMessageId.test.ts @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. +// See LICENSE in the project root for license information. + +import { TSDocConfiguration } from '../../configuration/TSDocConfiguration'; +import type { ParserMessage } from '../ParserMessage'; +import type { ParserContext } from '../ParserContext'; +import { TSDocMessageId } from '../TSDocMessageId'; +import { TSDocParser } from '../TSDocParser'; + +test('allTsdocMessageIds includes every TSDocMessageId enum value', () => { + const configuration: TSDocConfiguration = new TSDocConfiguration(); + const missing: string[] = []; + for (const key of Object.keys(TSDocMessageId)) { + const messageId: string = TSDocMessageId[key as keyof typeof TSDocMessageId]; + if (!configuration.isKnownMessageId(messageId)) { + missing.push(messageId); + } + } + expect(missing).toEqual([]); +}); + +test('unsupported HTML elements report a known message id', () => { + const configuration: TSDocConfiguration = new TSDocConfiguration(); + configuration.setSupportedHtmlElements([]); + configuration.validation.reportUnsupportedHtmlElements = true; + + const tsdocParser: TSDocParser = new TSDocParser(configuration); + const parserContext: ParserContext = tsdocParser.parseString(['/**', ' * ', ' */'].join('\n')); + + const unsupportedHtmlMessages: ParserMessage[] = parserContext.log.messages.filter( + (message: ParserMessage) => message.messageId === TSDocMessageId.UnsupportedHtmlElementName + ); + expect(unsupportedHtmlMessages.length).toBeGreaterThan(0); + + for (const message of parserContext.log.messages) { + expect(configuration.isKnownMessageId(message.messageId)).toEqual(true); + } +});