-
Notifications
You must be signed in to change notification settings - Fork 9
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
Add optional -license.year
flag
#46
Conversation
Allow repositories to configure the start date of their Copyright claims.
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.
Thanks and nice tests! Left purely non-blocking comments.
license/license.go
Outdated
// Validate license year | ||
year := 2015 |
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.
Perhaps we could make this a package-level constant.
license/license.go
Outdated
year := 2015 | ||
if licenseYear != "" { | ||
if y, err := strconv.Atoi(licenseYear); err != nil { | ||
return nil, fmt.Errorf("invalid license year: %v", err) |
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.
nit: I'd generally use %w
for errors, but not a big deal.
license/license.go
Outdated
@@ -51,7 +55,9 @@ var generatedHeaders = []string{ | |||
|
|||
func init() { | |||
Analyzer.Flags.StringVar(&ignoreFilesPattern, "ignore", "", "Comma separated list of files to ignore") | |||
Analyzer.Flags.StringVar(&licenseYear, "year", "2015", "Year to use in license header (2015-present)") |
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.
Any reason for the year to be parsed as string vs integer?
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.
Couple suggestions, if you (or Aider :) ) feel strongly about the current implementation let me know
license/license.go
Outdated
@@ -51,7 +55,9 @@ var generatedHeaders = []string{ | |||
|
|||
func init() { | |||
Analyzer.Flags.StringVar(&ignoreFilesPattern, "ignore", "", "Comma separated list of files to ignore") | |||
Analyzer.Flags.StringVar(&licenseYear, "year", "2015", "Year to use in license header (2015-present)") |
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 is only ever really used as an integer, so could we parse it as one rather than a string that is later converted? I think this would also mean error checking happens automatically
license/license.go
Outdated
EEAnalyzer.Flags.StringVar(&ignoreFilesPattern, "ignore", "", "Comma separated list of files to ignore") | ||
EEAnalyzer.Flags.StringVar(&licenseYear, "year", "2015", "Year to use in license header (2015-present)") |
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 here
license/license.go
Outdated
year := 2015 | ||
if licenseYear != "" { | ||
if y, err := strconv.Atoi(licenseYear); err != nil { | ||
return nil, fmt.Errorf("invalid license year: %v", err) | ||
} else { | ||
currentYear := time.Now().Year() | ||
if y < 2015 || y > currentYear { | ||
return nil, fmt.Errorf("license year must be between 2015 and %d", currentYear) | ||
} | ||
year = y | ||
} | ||
} | ||
|
||
expectedLine1 := fmt.Sprintf(licenseLine1Format, year) |
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.
With the above change, this would simplify down to
// Validate license year
currentYear := time.Now().Year()
if licenseYear < 2015 || licenseYear > currentYear {
return nil, fmt.Errorf("license year must be between 2015 and %d", currentYear)
}
expectedLine1 := fmt.Sprintf(licenseLine1Format, licenseYear)
Perhaps a good idea to use a constant for the MinYear
of 2015? Not likely to change I guess
When I opened the review editor @streamer45 hadn't posted yet. We're on the same page though! |
Sweet, thank you both @nickmisasi & @streamer45 for the concurrent, but compatible opinions :) Pushed changes for the constant and |
Summary
Allow repositories to configure the start date of their Copyright claims, e.g.
requires
Ticket Link
None