diff --git a/CHANGELOG.md b/CHANGELOG.md index bd262aca4b..e9c28b4618 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +* fix: [`format-comment`](https://dartcodemetrics.dev/docs/rules/common/format-comment) is listing the macros from dart doc. * feat: add static code diagnostic [`avoid-non-ascii-symbols`](https://dartcodemetrics.dev/docs/rules/common/avoid-non-ascii-symbols). * feat: remove declaration in [`prefer-immediate-return`](https://dartcodemetrics.dev/docs/rules/common/prefer-immediate-return). * fix: correctly handle disabling rules with false. diff --git a/lib/src/analyzers/lint_analyzer/rules/rules_list/format_comment/visitor.dart b/lib/src/analyzers/lint_analyzer/rules/rules_list/format_comment/visitor.dart index 69485f21ce..3c83a2db08 100644 --- a/lib/src/analyzers/lint_analyzer/rules/rules_list/format_comment/visitor.dart +++ b/lib/src/analyzers/lint_analyzer/rules/rules_list/format_comment/visitor.dart @@ -5,6 +5,11 @@ const commentsOperator = { _CommentType.documentation: '///', }; +final _regMacrosExp = RegExp('{@(template|macro) .+}'); +const _macrosEndExp = '{@endtemplate}'; +const _ignoreExp = 'ignore:'; +const _ignoreForFileExp = 'ignore_for_file:'; + class _Visitor extends RecursiveAstVisitor { final _comments = <_CommentInfo>[]; @@ -44,20 +49,26 @@ class _Visitor extends RecursiveAstVisitor { var text = commentText.trim(); - if (text.isEmpty || - text.startsWith('ignore:') || - text.startsWith('ignore_for_file:')) { - return; - } else { - text = text.trim(); - final upperCase = text[0] == text[0].toUpperCase(); - final lastSymbol = _punctuation.contains(text[text.length - 1]); - final hasEmptySpace = commentText[0] == ' '; - final incorrectFormat = !upperCase || !hasEmptySpace || !lastSymbol; - final single = commentToken.previous == null && commentToken.next == null; + final isIgnoreComment = + text.startsWith(_ignoreExp) || text.startsWith(_ignoreForFileExp); + + final isMacros = _regMacrosExp.hasMatch(text) || text == _macrosEndExp; + + { + if (text.isEmpty || isIgnoreComment || isMacros) { + return; + } else { + text = text.trim(); + final upperCase = text[0] == text[0].toUpperCase(); + final lastSymbol = _punctuation.contains(text[text.length - 1]); + final hasEmptySpace = commentText[0] == ' '; + final incorrectFormat = !upperCase || !hasEmptySpace || !lastSymbol; + final single = + commentToken.previous == null && commentToken.next == null; - if (incorrectFormat && single) { - _comments.add(_CommentInfo(type, commentToken)); + if (incorrectFormat && single) { + _comments.add(_CommentInfo(type, commentToken)); + } } } } diff --git a/test/src/analyzers/lint_analyzer/rules/rules_list/format_comment/examples/example_documentation.dart b/test/src/analyzers/lint_analyzer/rules/rules_list/format_comment/examples/example_documentation.dart index d266b454c9..c670c8e891 100644 --- a/test/src/analyzers/lint_analyzer/rules/rules_list/format_comment/examples/example_documentation.dart +++ b/test/src/analyzers/lint_analyzer/rules/rules_list/format_comment/examples/example_documentation.dart @@ -16,3 +16,15 @@ void greet(String name) { /// deletes the file at [path] from the file system. void delete(String path) {} + +/// {@template template_name} +void f1() {} + +/// {@endtemplate} +void f2() {} + +/// {@macro template_name} +void f3() {} + +/// {@template my_project.my_class.my_method} +void f4() {}