SONARJAVA-6196 S1451 should provide a default template for headers#5578
SONARJAVA-6196 S1451 should provide a default template for headers#5578NoemieBenard wants to merge 7 commits intomasterfrom
Conversation
SummaryChanged S1451 (file header check) to provide a default header template instead of an empty default. The check previously required users to manually configure a The implementation also distinguishes between "no header required" (explicit empty string) and "default header" (the new template), ensuring that when What reviewers should knowKey changes to review:
Why this matters:
Watch for:
|
|
| check = new FileHeaderCheck(); | ||
| CheckVerifier.newVerifier() | ||
| .onFile(mainCodeSourcesPath("checks/FileHeaderCheck/Class6.java")) | ||
| .withCheck(check) | ||
| .verifyNoIssues(); |
There was a problem hiding this comment.
The test verifies that Class6.java (which contains the default header) is compliant — but there is no negative test asserting that a file without the default header gets flagged.
This gap matters concretely: if DEFAULT_HEADER_FORMAT ever became empty (e.g., due to a text-block indentation accident), the headerFormat.isEmpty() branch would fire, set expectedLines = {}, and matches() would return true for any file. The verifyNoIssues() call would still pass, giving a false sense of correctness.
Add a complementary case that runs the default FileHeaderCheck() against a file that lacks the header and asserts an issue is raised — something like:
check = new FileHeaderCheck();
CheckVerifier.newVerifier()
.onFile(mainCodeSourcesPath("checks/FileHeaderCheck/Class1.java"))
.withCheck(check)
.verifyIssueOnFile("Add or update the header of this file.");- Mark as noise




Add default template for headerFormat in S1451.