Skip to content
This repository was archived by the owner on Jul 16, 2023. It is now read-only.

fix: format-comment is listing the macros from dart doc. #823

Merged
merged 4 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
final _comments = <_CommentInfo>[];

Expand Down Expand Up @@ -44,20 +49,26 @@ class _Visitor extends RecursiveAstVisitor<void> {

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));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}