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AAM,SAAS,GAAc,iBAAS,CAAC,eAAe,CACpD,UAAU,CAAC,IAAI,EACf,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAChB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CACjB,CAAC;wBAEF,8BAA8B;wBAC9B,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;4BACzB,SAAS;wBACX,CAAC;wBACD,iCAAiC;wBACjC,IAAI,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;4BAChD,SAAS;wBACX,CAAC;wBAED,MAAM,aAAa,GAAkB,WAAW,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;wBACvE,KAAK,MAAM,OAAO,IAAI,aAAa,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;4BACjD,OAAO,CAAC,MAAM,CAAC;gCACb,GAAG,EAAE;oCACH,KAAK,EAAE,UAAU,CAAC,eAAe,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC;oCACxD,GAAG,EAAE,UAAU,CAAC,eAAe,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC;iCACvD;gCACD,SAAS,EAAE,OAAO,CAAC,SAAS;gCAC5B,IAAI,EAAE;oCACJ,eAAe,EAAE,OAAO,CAAC,eAAe;iCACzC;6BACF,CAAC,CAAC;wBACL,CAAC;oBACH,CAAC;gBACH,CAAC,CAAC;gBAEF,OAAO;oBACL,OAAO,EAAE,kBAAkB;iBAC5B,CAAC;YACJ,CAAC;SACF;KACF;CACF,CAAC;AAEF,iBAAS,MAAM,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\r\n// See LICENSE in the project root for license information.\r\n\r\nimport type * as eslint from 'eslint';\r\nimport type * as ESTree from 'estree';\r\nimport { TSDocParser, TextRange, TSDocConfiguration, type ParserContext } from '@microsoft/tsdoc';\r\nimport type { TSDocConfigFile } from '@microsoft/tsdoc-config';\r\n\r\nimport { Debug } from './Debug';\r\nimport { ConfigCache } from './ConfigCache';\r\n\r\nconst tsdocMessageIds: { [x: string]: string } = {};\r\n\r\nconst defaultTSDocConfiguration: TSDocConfiguration = new TSDocConfiguration();\r\ndefaultTSDocConfiguration.allTsdocMessageIds.forEach((messageId: string) => {\r\n tsdocMessageIds[messageId] = `${messageId}: {{unformattedText}}`;\r\n});\r\n\r\ninterface IPlugin {\r\n rules: { [x: string]: eslint.Rule.RuleModule };\r\n}\r\n\r\nconst plugin: IPlugin = {\r\n rules: {\r\n // NOTE: The actual ESLint rule name will be \"tsdoc/syntax\". It is calculated by deleting \"eslint-plugin-\"\r\n // from the NPM package name, and then appending this string.\r\n syntax: {\r\n meta: {\r\n messages: {\r\n 'error-loading-config-file': 'Error loading TSDoc config file:\\n{{details}}',\r\n 'error-applying-config': 'Error applying TSDoc configuration: {{details}}',\r\n ...tsdocMessageIds\r\n },\r\n type: 'problem',\r\n docs: {\r\n description: 'Validates that TypeScript documentation comments conform to the TSDoc standard',\r\n category: 'Stylistic Issues',\r\n // This package is experimental\r\n recommended: false,\r\n url: 'https://tsdoc.org/pages/packages/eslint-plugin-tsdoc'\r\n }\r\n },\r\n create: (context: eslint.Rule.RuleContext) => {\r\n const sourceFilePath: string = context.getFilename();\r\n Debug.log(`Linting: \"${sourceFilePath}\"`);\r\n\r\n const tsdocConfiguration: TSDocConfiguration = new TSDocConfiguration();\r\n\r\n try {\r\n const tsdocConfigFile: TSDocConfigFile = ConfigCache.getForSourceFile(sourceFilePath);\r\n if (!tsdocConfigFile.fileNotFound) {\r\n if (tsdocConfigFile.hasErrors) {\r\n context.report({\r\n loc: { line: 1, column: 1 },\r\n messageId: 'error-loading-config-file',\r\n data: {\r\n details: tsdocConfigFile.getErrorSummary()\r\n }\r\n });\r\n }\r\n\r\n try {\r\n tsdocConfigFile.configureParser(tsdocConfiguration);\r\n } catch (e) {\r\n context.report({\r\n loc: { line: 1, column: 1 },\r\n messageId: 'error-applying-config',\r\n data: {\r\n details: e.message\r\n }\r\n });\r\n }\r\n }\r\n } catch (e) {\r\n context.report({\r\n loc: { line: 1, column: 1 },\r\n messageId: 'error-loading-config-file',\r\n data: {\r\n details: `Unexpected exception: ${e.message}`\r\n }\r\n });\r\n }\r\n\r\n const tsdocParser: TSDocParser = new TSDocParser(tsdocConfiguration);\r\n\r\n const sourceCode: eslint.SourceCode = context.getSourceCode();\r\n const checkCommentBlocks: (node: ESTree.Node) => void = function (node: ESTree.Node) {\r\n for (const comment of sourceCode.getAllComments()) {\r\n if (comment.type !== 'Block') {\r\n continue;\r\n }\r\n if (!comment.range) {\r\n continue;\r\n }\r\n\r\n const textRange: TextRange = TextRange.fromStringRange(\r\n sourceCode.text,\r\n comment.range[0],\r\n comment.range[1]\r\n );\r\n\r\n // Smallest comment is \"/***/\"\r\n if (textRange.length < 5) {\r\n continue;\r\n }\r\n // Make sure it starts with \"/**\"\r\n if (textRange.buffer[textRange.pos + 2] !== '*') {\r\n continue;\r\n }\r\n\r\n const parserContext: ParserContext = tsdocParser.parseRange(textRange);\r\n for (const message of parserContext.log.messages) {\r\n context.report({\r\n loc: {\r\n start: sourceCode.getLocFromIndex(message.textRange.pos),\r\n end: sourceCode.getLocFromIndex(message.textRange.end)\r\n },\r\n messageId: message.messageId,\r\n data: {\r\n unformattedText: message.unformattedText\r\n }\r\n });\r\n }\r\n }\r\n };\r\n\r\n return {\r\n Program: checkCommentBlocks\r\n };\r\n }\r\n }\r\n }\r\n};\r\n\r\nexport = plugin;\r\n"]}
\No newline at end of file