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

Create rule S6513: ExcludeFromCodeCoverage attributes should include a justification #1624

Merged
merged 9 commits into from
Mar 14, 2023

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Mar 9, 2023

You can preview this rule here (updated a few minutes after each push).

Implemented by SonarSource/sonar-dotnet#6593

@github-actions github-actions bot added the dotnet label Mar 9, 2023
@martin-strecker-sonarsource martin-strecker-sonarsource changed the title Create rule S6513 Create rule S6513: ExcludeFromCodeCoverage attributes should include a justification Mar 9, 2023
@martin-strecker-sonarsource martin-strecker-sonarsource marked this pull request as ready for review March 9, 2023 11:40
Y = coordinates.Y
End Function

<ExcludeFromCodeCoverage(Justification:="Code generated by the Visual Studio refactoring.")>
Copy link
Contributor

Choose a reason for hiding this comment

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

I would drop "the" (4 times).

@@ -0,0 +1 @@
The https://learn.microsoft.com/dotnet/api/system.diagnostics.codeanalysis.excludefromcodecoverageattribute[ExcludeFromCodeCoverageAttribute] is used to exclude portions of code from https://learn.microsoft.com/dotnet/core/testing/unit-testing-code-coverage[code coverage reporting]. Code uncovered by unit tests is bad practice and needs a justification.
Copy link
Contributor

Choose a reason for hiding this comment

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

"not covered" instead of "uncovered"

"is a bad practice"

 for Compliant/Noncompliant code
Copy link
Contributor

@Corniel Corniel left a comment

Choose a reason for hiding this comment

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

So far LGTM. It might be worth pointing out that it is only possible to specify a justification since .NET 5.0.

@antonioaversa antonioaversa self-requested a review March 13, 2023 13:41
Copy link
Contributor

@antonioaversa antonioaversa left a comment

Choose a reason for hiding this comment

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

LGTM, just aesthetics.

rules/S6513/csharp/rule.adoc Outdated Show resolved Hide resolved
rules/S6513/csharp/rule.adoc Outdated Show resolved Hide resolved
@@ -0,0 +1 @@
The https://learn.microsoft.com/dotnet/api/system.diagnostics.codeanalysis.excludefromcodecoverageattribute[ExcludeFromCodeCoverageAttribute] is used to exclude portions of code from https://learn.microsoft.com/dotnet/core/testing/unit-testing-code-coverage[code coverage reporting]. Code not covered by unit tests is a bad practice and needs a justification.
Copy link
Contributor

Choose a reason for hiding this comment

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

I would say that the bad practice is the use of the attribute, to avoid covering code, rather than the code itself. The code is an object and can't be seen as a practice.

Copy link
Contributor

Choose a reason for hiding this comment

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

This change wasn't applied.
What I meant with my comment above was that Code that [...] is a bad practice. should actually be something like Leaving code that [...] is a bad practice. since an object such as code can't be seen as a practice, which is an action (on the object).

Having code that [...] is a bad practice doesn't count as an action, imo.
In other words, the code is not responsible for the mistakes of its author :-)

rules/S6513/vbnet/rule.adoc Outdated Show resolved Hide resolved
rules/S6513/vbnet/rule.adoc Outdated Show resolved Hide resolved
rules/S6513/vbnet/rule.adoc Show resolved Hide resolved
@Corniel
Copy link
Contributor

Corniel commented Mar 14, 2023

Happy that you addressed .NET 5. @antonioaversa I agree that leaving out the not relevant code makes the snippets easier to process.

Copy link
Contributor

@antonioaversa antonioaversa left a comment

Choose a reason for hiding this comment

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

LGTM! I agree with the change of severity.

Concerning the scope: I would argue that providing a justification when you exclude code from coverage would be a good practice in test code too (e.g. "Used for mocking."). At the same time I would expect a lot of positive cases when using the rule in test projects, and I understand the conservative approach.

@sonarsource-next
Copy link

SonarQube Quality Gate for 'rspec-tools'

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

@sonarsource-next
Copy link

SonarQube Quality Gate for 'rspec-frontend'

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

@martin-strecker-sonarsource martin-strecker-sonarsource deleted the rule/add-RSPEC-S6513 branch March 14, 2023 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants