Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New rule S4663: Comments should not be empty #6672

Merged
merged 27 commits into from Feb 3, 2023

Conversation

gregory-paidis-sonarsource
Copy link
Contributor

Fixes #6663

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good approach. I think Partition can be made a bit more readable and we need to be careful to allocate not too much. Some pieces need to be shifted around between the base class and the derived classes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some annotations.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. The IsKind/IsAnyKind approach looks good.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some cosmetic changes and we should be fine.

Comment on lines 42 to 43
CheckTrivia(c, token.LeadingTrivia);
CheckTrivia(c, token.TrailingTrivia);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CheckTrivia(c, token.LeadingTrivia);
CheckTrivia(c, token.TrailingTrivia);
// Hotpath: Don't allocate the trivia enumerable if not needed
if (token.HasLeadingTrivia)
{
CheckTrivia(c, token.LeadingTrivia);
}
if (token.HasTrailingTrivia)
{
CheckTrivia(c, token.TrailingTrivia);
}


foreach (var trivium in trivia)
{
if (IsSimpleComment(trivium)) // put it on the current block of "//"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method name AddTriviaToPartition says it already.

Suggested change
if (IsSimpleComment(trivium)) // put it on the current block of "//"
if (IsSimpleComment(trivium))

if (IsSimpleComment(trivium)) // put it on the current block of "//"
{
AddTriviaToPartition(ref current, trivium);
firstEndOfLineFound = false;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

firstEndOfLineFound = false; can be moved to AddTriviaToPartition.

Suggested change
firstEndOfLineFound = false;

CloseCurrentPartition(ref current, ref partitions, ref firstEndOfLineFound);
}
// This handles an empty line, for example:
// // some comment \n <- EOL found, set to true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

firstEndOfLineFound should be mentioned once to make clear what the "true/false" refers to.

Suggested change
// // some comment \n <- EOL found, set to true
// // some comment \n <- EOL found, firstEndOfLineFound set to true

current.Add(trivia);
}

// Hotpath: Don't capture variables

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be on the first local function.

Suggested change
// Hotpath: Don't capture variables

CloseCurrentPartition(ref current, ref partitions, ref firstEndOfLineFound);
return partitions;

static void AddTriviaToPartition(ref List<SyntaxTrivia> current, SyntaxTrivia trivia)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static void AddTriviaToPartition(ref List<SyntaxTrivia> current, SyntaxTrivia trivia)
// Hotpath: Don't capture variables.
static void AddTriviaToPartition(ref List<SyntaxTrivia> current, SyntaxTrivia trivia)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. But one small issue still to be resoved.

Comment on lines 64 to 65
public SyntaxKind RightShiftAssignmentStatement => SyntaxKind.RightShiftAssignmentExpression;
public SyntaxKind RightShiftExpression => SyntaxKind.RightShiftExpression;
public SyntaxKind RefKeyword => SyntaxKind.RefKeyword;
public SyntaxKind ReturnStatement => SyntaxKind.ReturnStatement;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order is mixed up.

@sonarcloud
Copy link

sonarcloud bot commented Feb 2, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarcloud
Copy link

sonarcloud bot commented Feb 2, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 9 Code Smells

97.4% 97.4% Coverage
0.6% 0.6% Duplication

@gregory-paidis-sonarsource gregory-paidis-sonarsource merged commit 81d0d19 into master Feb 3, 2023
@gregory-paidis-sonarsource gregory-paidis-sonarsource deleted the greg/implement-S4663 branch February 3, 2023 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New rule S4663: Comments should not be empty
2 participants