Skip to content
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

Merged
merged 5 commits into from
Jan 23, 2025
Merged

Conversation

lieut-data
Copy link
Member

Summary

Allow repositories to configure the start date of their Copyright claims, e.g.

$(GO) vet -vettool=$(GOBIN)/mattermost-govet -license -license.year=2020 ./server/...

requires

// Copyright (c) 2020-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

Ticket Link

None

Allow repositories to configure the start date of their Copyright
claims.
@lieut-data lieut-data requested a review from streamer45 January 22, 2025 20:01
Copy link
Contributor

@streamer45 streamer45 left a 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.

Comment on lines 69 to 70
// Validate license year
year := 2015
Copy link
Contributor

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.

year := 2015
if licenseYear != "" {
if y, err := strconv.Atoi(licenseYear); err != nil {
return nil, fmt.Errorf("invalid license year: %v", err)
Copy link
Contributor

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.

@@ -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)")
Copy link
Contributor

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?

Copy link

@nickmisasi nickmisasi left a 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

@@ -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)")

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

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)")

Choose a reason for hiding this comment

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

Same here

Comment on lines 70 to 83
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)

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

@nickmisasi
Copy link

When I opened the review editor @streamer45 hadn't posted yet. We're on the same page though!

@lieut-data
Copy link
Member Author

Sweet, thank you both @nickmisasi & @streamer45 for the concurrent, but compatible opinions :)

Pushed changes for the constant and fmt, and investigating IntVar. It doesn't "just work" like I'd hope, but will investigate.

@lieut-data lieut-data merged commit 3f08281 into new Jan 23, 2025
5 checks passed
@lieut-data lieut-data deleted the parameterize-license-year branch January 23, 2025 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants