diff --git a/pkg/linter/lib/src/rules/missing_code_block_language_in_doc_comment.dart b/pkg/linter/lib/src/rules/missing_code_block_language_in_doc_comment.dart index cf389f666353..1e147f6fab06 100644 --- a/pkg/linter/lib/src/rules/missing_code_block_language_in_doc_comment.dart +++ b/pkg/linter/lib/src/rules/missing_code_block_language_in_doc_comment.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/ast/ast.dart'; +import 'package:analyzer/dart/ast/doc_comment.dart'; import 'package:analyzer/dart/ast/visitor.dart'; import '../analyzer.dart'; @@ -69,13 +70,14 @@ class _Visitor extends SimpleAstVisitor { @override void visitComment(Comment node) { for (var codeBlock in node.codeBlocks) { - if (codeBlock.infoString == null) { - var openingCodeBlockFence = codeBlock.lines.first; - rule.reportLintForOffset( - openingCodeBlockFence.offset, - openingCodeBlockFence.length, - ); - } + if (codeBlock.infoString != null) continue; + if (codeBlock.type != CodeBlockType.fenced) continue; + + var openingCodeBlockFence = codeBlock.lines.first; + rule.reportLintForOffset( + openingCodeBlockFence.offset, + openingCodeBlockFence.length, + ); } } } diff --git a/pkg/linter/test/rules/missing_code_block_language_in_doc_comment_test.dart b/pkg/linter/test/rules/missing_code_block_language_in_doc_comment_test.dart index 6d92587540a1..779e45dfe070 100644 --- a/pkg/linter/test/rules/missing_code_block_language_in_doc_comment_test.dart +++ b/pkg/linter/test/rules/missing_code_block_language_in_doc_comment_test.dart @@ -22,6 +22,7 @@ class MissingCodeBlockLanguageInDocCommentTest extends LintRuleTest { /// ```dart /// test /// ``` +class A {} '''); } @@ -43,6 +44,17 @@ class A {} '''); } + test_indentedCodeBlock() async { + await assertNoDiagnostics(r''' +/// Example: +/// +/// var printer = Printer(); +/// printer.printToStdout(); +/// +class A {} +'''); + } + test_missingLanguage() async { await assertDiagnostics(r''' /// ```