-
Notifications
You must be signed in to change notification settings - Fork 725
SONARJAVA-6198 S1451 should accept an empty headerFormat as the absence of any line #5576
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
a3f72fd
4eb1254
f0a1024
a7d266f
fb81953
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 | ||
|
|
|
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.
|
| 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 | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -67,14 +67,18 @@ public void setContext(JavaFileScannerContext context) { | |||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| } else { | ||||||||||||||||||
| expectedLines = headerFormat.split("(?:\r)?\n|\r"); | ||||||||||||||||||
| if (headerFormat.isEmpty()) { | ||||||||||||||||||
|
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. Conditional expression is IMO more readable:
Contributor
Author
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. I ended up handling the empty case before as it is also necessary to handle it when headerFormat is a regular expression (see #5577) |
||||||||||||||||||
| expectedLines = new String[] {}; | ||||||||||||||||||
| } else { | ||||||||||||||||||
| expectedLines = headerFormat.split("(?:\r)?\n|\r"); | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| visitFile(); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| private String getHeaderFormat() { | ||||||||||||||||||
| String format = headerFormat; | ||||||||||||||||||
| if(format.charAt(0) != '^') { | ||||||||||||||||||
| if (format.charAt(0) != '^') { | ||||||||||||||||||
|
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. Let's avoid reformatting unchanged code.
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. When The PR fixes the non-regex path for empty Consider guarding the same way as the non-regex path, or at minimum returning
Suggested change
|
||||||||||||||||||
| format = "^" + format; | ||||||||||||||||||
| } | ||||||||||||||||||
| return format; | ||||||||||||||||||
|
|
||||||||||||||||||
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 see that the existing samples do not use descriptive names, but I think this should not stop us here. How about a name like
ClassBlankLine.javaor something similar?