-
Notifications
You must be signed in to change notification settings - Fork 724
SONARJAVA-6269 S1451 should correctly handle empty headerFormat #5580
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
Changes from all commits
5f47ccc
5c9bbeb
c0f6858
0874843
ce69613
73c9fc9
dfabda9
58d4bbf
4ef6850
07834df
5ab2f12
689e1ad
ba3fca5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
|
|
||
| package checks.FileHeaderCheck; | ||
|
|
||
| public class ClassBlankLine { | ||
| } | ||
| // Compliant | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| /* | ||
| * <Your-Product-Name> | ||
| * Copyright (c) <Year-From>-<Year-To> <Your-Company-Name> | ||
| * | ||
| * Please configure this header in your SonarCloud/SonarQube quality profile. | ||
| */ | ||
| package checks.FileHeaderCheck; | ||
|
|
||
| public class ClassDefaultHeader { | ||
| } | ||
| // Compliant (default header) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package checks.FileHeaderCheck; | ||
|
|
||
| public class ClassNoBlankLine { | ||
| } | ||
| // Compliant |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,6 +98,26 @@ void test() { | |
| .onFile(mainCodeSourcesPath("checks/FileHeaderCheck/Class3.java")) | ||
| .withCheck(check) | ||
| .verifyNoIssues(); | ||
|
|
||
| check = new FileHeaderCheck(); | ||
| check.headerFormat = ""; | ||
| CheckVerifier.newVerifier() | ||
| .onFile(mainCodeSourcesPath("checks/FileHeaderCheck/ClassBlankLine.java")) | ||
| .withCheck(check) | ||
| .verifyNoIssues(); | ||
|
Comment on lines
+102
to
+107
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The real non-regex regression test is
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The real regression test for the non-regex fix is
|
||
|
|
||
| check = new FileHeaderCheck(); | ||
| check.headerFormat = ""; | ||
| CheckVerifier.newVerifier() | ||
| .onFile(mainCodeSourcesPath("checks/FileHeaderCheck/ClassNoBlankLine.java")) | ||
| .withCheck(check) | ||
| .verifyNoIssues(); | ||
|
|
||
| check = new FileHeaderCheck(); | ||
| CheckVerifier.newVerifier() | ||
| .onFile(mainCodeSourcesPath("checks/FileHeaderCheck/ClassDefaultHeader.java")) | ||
| .withCheck(check) | ||
| .verifyNoIssues(); | ||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -139,6 +159,22 @@ void regex() { | |
| .onFile(mainCodeSourcesPath("checks/FileHeaderCheck/Regex4.java")) | ||
| .withCheck(check) | ||
| .verifyIssues(); | ||
|
|
||
| check = new FileHeaderCheck(); | ||
| check.headerFormat = ""; | ||
| check.isRegularExpression = true; | ||
| CheckVerifier.newVerifier() | ||
| .onFile(mainCodeSourcesPath("checks/FileHeaderCheck/ClassBlankLine.java")) | ||
| .withCheck(check) | ||
| .verifyNoIssues(); | ||
|
|
||
| check = new FileHeaderCheck(); | ||
| check.headerFormat = ""; | ||
| check.isRegularExpression = true; | ||
| CheckVerifier.newVerifier() | ||
| .onFile(mainCodeSourcesPath("checks/FileHeaderCheck/ClassNoBlankLine.java")) | ||
| .withCheck(check) | ||
| .verifyNoIssues(); | ||
| } | ||
|
|
||
| @Test | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -429,8 +429,8 @@ void do_not_filter_checks_when_no_autoscan() throws IOException { | |
| "CustomRepository:CustomMainCheck", | ||
| "CustomRepository:CustomJspCheck", | ||
| "CustomRepository:CustomTestCheck", | ||
| // not in SonarWay (FileHeaderCheck) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this test still need a fix? I could not reproduce it locally. If it does, could we find a different rule, not in SonarWay, which fails? Maybe S1166. We can discuss it offline. |
||
| "java:S1451", | ||
| // not in SonarWay (CatchUsesExceptionWithContextCheck) | ||
| "java:S1166", | ||
| // main check in SonarWay (DefaultPackageCheck) | ||
| "java:S1220", | ||
| // main check in SonarWay, not supported by autoscan (CombineCatchCheck) | ||
|
|
||
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.
ClassDefaultHeader.java?