diff --git a/eslint-plugin/src/configs/recommended.ts b/eslint-plugin/src/configs/recommended.ts new file mode 100644 index 00000000..74cd72ea --- /dev/null +++ b/eslint-plugin/src/configs/recommended.ts @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. +// See LICENSE in the project root for license information. + +import type { Linter } from 'eslint'; + +const config: Linter.Config = { + rules: { + 'tsdoc/syntax': 'warn' + } +}; + +export default config; diff --git a/eslint-plugin/src/index.ts b/eslint-plugin/src/index.ts index ab0c35ae..c8e15e19 100644 --- a/eslint-plugin/src/index.ts +++ b/eslint-plugin/src/index.ts @@ -9,6 +9,7 @@ import type { TSDocConfigFile } from '@microsoft/tsdoc-config'; import { Debug } from './Debug'; import { ConfigCache } from './ConfigCache'; +import recommended from './configs/recommended'; const tsdocMessageIds: { [x: string]: string } = {}; @@ -19,6 +20,7 @@ defaultTSDocConfiguration.allTsdocMessageIds.forEach((messageId: string) => { interface IPlugin { rules: { [x: string]: eslint.Rule.RuleModule }; + configs: { [x: string]: eslint.Linter.Config }; } function getRootDirectoryFromContext(context: TSESLint.RuleContext): string | undefined { @@ -68,94 +70,3 @@ const plugin: IPlugin = { const tsConfigDir: string | undefined = getRootDirectoryFromContext( context as unknown as TSESLint.RuleContext ); - Debug.log(`Linting: "${sourceFilePath}"`); - - const tsdocConfiguration: TSDocConfiguration = new TSDocConfiguration(); - - try { - const tsdocConfigFile: TSDocConfigFile = ConfigCache.getForSourceFile(sourceFilePath, tsConfigDir); - if (!tsdocConfigFile.fileNotFound) { - if (tsdocConfigFile.hasErrors) { - context.report({ - loc: { line: 1, column: 1 }, - messageId: 'error-loading-config-file', - data: { - details: tsdocConfigFile.getErrorSummary() - } - }); - } - - try { - tsdocConfigFile.configureParser(tsdocConfiguration); - } catch (e) { - context.report({ - loc: { line: 1, column: 1 }, - messageId: 'error-applying-config', - data: { - details: e.message - } - }); - } - } - } catch (e) { - context.report({ - loc: { line: 1, column: 1 }, - messageId: 'error-loading-config-file', - data: { - details: `Unexpected exception: ${e.message}` - } - }); - } - - const tsdocParser: TSDocParser = new TSDocParser(tsdocConfiguration); - - const sourceCode: eslint.SourceCode = context.sourceCode ?? context.getSourceCode(); - function checkCommentBlocks(): void { - for (const comment of sourceCode.getAllComments()) { - if (comment.type !== 'Block') { - continue; - } - if (!comment.range) { - continue; - } - - const textRange: TextRange = TextRange.fromStringRange( - sourceCode.text, - comment.range[0], - comment.range[1] - ); - - // Smallest comment is "/***/" - if (textRange.length < 5) { - continue; - } - // Make sure it starts with "/**" - if (textRange.buffer[textRange.pos + 2] !== '*') { - continue; - } - - const parserContext: ParserContext = tsdocParser.parseRange(textRange); - for (const message of parserContext.log.messages) { - context.report({ - loc: { - start: sourceCode.getLocFromIndex(message.textRange.pos), - end: sourceCode.getLocFromIndex(message.textRange.end) - }, - messageId: message.messageId, - data: { - unformattedText: message.unformattedText - } - }); - } - } - } - - return { - Program: checkCommentBlocks - }; - } - } - } -}; - -export = plugin;