-
Notifications
You must be signed in to change notification settings - Fork 227
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
Change .Verify
to fail when no issues are reported
#9250
Conversation
f784e57
to
a61b70a
Compare
a3ecee4
to
6cf0904
Compare
a61b70a
to
fd4d546
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow that was a lot, left some comments (some are nitpicks!)
@@ -27,21 +27,20 @@ public static class DiagnosticVerifier | |||
private const string AD0001 = nameof(AD0001); | |||
private const string LineContinuationVB12 = "BC36716"; // Visual Basic 12.0 does not support line continuation comments. | |||
|
|||
public static void Verify( | |||
public static int Verify( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please align the parameters consistently across the file, either placing Compilation compilation
inlined with the method declaration or changing the other methods
public static void Verify( | ||
Compilation compilation, | ||
DiagnosticAnalyzer[] analyzers, | ||
CompilationErrorBehavior checkMode, // ToDo: Remove this parameter in https://github.com/SonarSource/sonar-dotnet/issues/8588 | ||
string additionalFilePath = null, | ||
string[] onlyDiagnostics = null, | ||
string[] additionalSourceFiles = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I prefer the old parameter alignment tho (opinionated)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I was simply following our coding style.
int a; | ||
(var shortSalt, a) = (new byte[15], 42); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make it actually require C# 10 (mixing assignment and declaration in deconstruction). However, since I removed the comment in the test file, this change does not need to be in this PR. I'll revert it.
int a; | ||
(var rgb, a) = (new byte[16], 42); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as the other. Reverted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still see it 🤔
analyzers/tests/SonarAnalyzer.TestFramework.Test/Verification/VerifierTest.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this file about? if it's just adding more UTs for SE rules please cherry-pick the changes and move them into a different PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added by accident.
analyzers/SonarAnalyzer.lutconfig
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Educational: what is this file about?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Live Unit Testing. I committed it by accident.
analyzers/tests/SonarAnalyzer.TestFramework/Verification/DiagnosticVerifier.cs
Show resolved
Hide resolved
0739ae1
to
994abcc
Compare
16a8b88
to
8f4f5f6
Compare
8f4f5f6
to
9f79a69
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Only nitpicks left
{ | ||
public void Foo<T>(Action action1, Action<T> action2, Action<T, T> action3, Action<T, T, T> action4, Action<T, T, T, T> action5) { } | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty line
{ | ||
public void Foo<T>(Func<T> func1, Func<T, T> func2, Func<T, T, T> func3, Func<T, T, T, T> func4) { } | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty line
{ | ||
public void Foo(int* pointer) { } // Error [CS0214] | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty line
{ | ||
public ConsoleColor Foo(ConsoleColor c) { return ConsoleColor.Black; } | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty line
@@ -44,7 +44,8 @@ public class CallerInformationParametersShouldBeLastTest | |||
|
|||
[TestMethod] | |||
public void CallerInformationParametersShouldBeLast_CSharp11() => | |||
builder.AddPaths("CallerInformationParametersShouldBeLast.CSharp11.cs").WithOptions(ParseOptionsHelper.FromCSharp11).Verify(); | |||
builder.AddPaths("CallerInformationParametersShouldBeLast.CSharp11.cs").WithOptions(ParseOptionsHelper.FromCSharp11) | |||
.VerifyNoIssues(); // overriding an abstract default implementation is compliant |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was not solved although it's marked with 👍
@@ -10,7 +10,8 @@ public class C | |||
// If the field is not initialized and nullable is set to enabled then | |||
// there's a warning "CS8618: Non-nullable property 'MyProperty' must contain a non-null value when exiting constructor. Consider declaring the property as nullable." | |||
// To silence the warning one needs to use a field initializer and the suppression operator. We should not raise and issue in the case ! is present. | |||
public object MyProperty { get; set; } = default!; // Compliant | |||
public object Noncompliant { get; set; } = default; // FN |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it documented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you asking if there is a ticket for this? I did not create one. The rule is non-sonarway - I don't think it's worth tracking this.
@@ -1,8 +1,10 @@ | |||
class SomeClass(int arg) | |||
{ | |||
public void RandomMethod1() { } | |||
public void RandomMethod1() { } // Noncompliant |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this compliant before? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because there was no other overload for RandomMethod1
present.
interface Foo | ||
{ | ||
[DllImport("mynativelib")] | ||
extern public static void Bar(string s, int x); // FN |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documented somewhere? aka GH issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know. I did not write the test. I just merged it from the .CSharp10
file.
int a; | ||
(var rgb, a) = (new byte[16], 42); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still see it 🤔
int a; | ||
(var rgb, a) = (new byte[16], 42); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
Quality Gate passed for 'Sonar .NET Java Plugin'Issues Measures |
Quality Gate passed for 'SonarAnalyzer for .NET'Issues Measures |
Fixes #9237
Based on #9259
This branch has two commits:
Verify
toVerifyNoIssues
. Sometimes with a comment, sometimes the reason is clear from context.Verify
toVerifyNoIssuesIgnoreErrors
. Pay special attention to these, because they can, if used wrongly, hide problems.Side note: Ignore the branch names. They are confusing, unfortunately.