Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions addlicense/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,14 @@ func hasLicense(b []byte) bool {
if len(b) < 1000 {
n = len(b)
}
return bytes.Contains(bytes.ToLower(b[:n]), []byte("copyright")) ||
bytes.Contains(bytes.ToLower(b[:n]), []byte("mozilla public")) ||
bytes.Contains(bytes.ToLower(b[:n]), []byte("spdx-license-identifier"))
// Convert to lowercase for case-insensitive matching
content := bytes.ToLower(b[:n])

// Check for different variations of copyright/license headers
return bytes.Contains(content, []byte("copyright")) ||
bytes.Contains(content, []byte("copyright (c)")) ||
bytes.Contains(content, []byte("the opentofu authors")) ||
bytes.Contains(content, []byte("hashicorp, inc.")) ||
bytes.Contains(content, []byte("mozilla public")) ||
bytes.Contains(content, []byte("spdx-license-identifier"))
Copy link

Choose a reason for hiding this comment

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

Issue: Adding conditions in the above manner is not scalable

The current implementation is okay for small number of scenarios but adding more || conditions will make it unreadable. Also, the repo is currently consumed at a number of places and the above changes might not be required by everyone.
It will be great if you can come up with a solution where the different conditions can be supplied by the users as a config according to their use cases

}