Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
go-version-file: '.go-version'

- name: run go lint
uses: golangci/golangci-lint-action@639cd343e1d3b897ff35927a75193d57cfcba299 # v3.6.0
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest
Expand Down
19 changes: 0 additions & 19 deletions .golangci.yaml

Choose a reason for hiding this comment

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

The config file is not required with golangci-lint v2. Disabled linters have been "reneabled" by this change and their errors have been fixed.

This file was deleted.

2 changes: 1 addition & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ for any unknown values. If you are running this command in CI, please use the
// Render it out!
f, err := os.Create(".copywrite.hcl")
cobra.CheckErr(err)
defer f.Close()
defer func() { cobra.CheckErr(f.Close()) }()

Choose a reason for hiding this comment

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

Fixes:

copywrite/cmd/init.go:104:16: Error return value of `f.Close` is not checked (errcheck)
                defer f.Close()
                             ^


err = configToHCL(*newConfig, f)
cobra.CheckErr(err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var licenseCmd = &cobra.Command{

// Input Validation
if conf.Project.CopyrightYear == 0 {
errYearNotFound := errors.New("Unable to automatically determine copyright year. Please specify it manually in the config or via the --year flag")
errYearNotFound := errors.New("unable to automatically determine copyright year: Please specify it manually in the config or via the --year flag")

Choose a reason for hiding this comment

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

Fixes:

copywrite/cmd/license.go:48:23: ST1005: error strings should not be capitalized (staticcheck)
                        errYearNotFound := errors.New("Unable to automatically determine copyright year. Please specify it manually in the config or via the --year flag")

Choose a reason for hiding this comment

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

Fixes:

copywrite/cmd/license.go:48:23: ST1005: error strings should not be capitalized (staticcheck)
                        errYearNotFound := errors.New("Unable to automatically determine copyright year. Please specify it manually in the config or via the --year flag")


cliLogger.Info("Copyright year was not supplied via config or via the --year flag. Attempting to infer from the year the GitHub repo was created.")
repo, err := github.DiscoverRepo()
Expand Down Expand Up @@ -78,7 +78,7 @@ var licenseCmd = &cobra.Command{
var file string

if len(licenseFiles) > 1 {
err = fmt.Errorf("More than one license file exists. Please review the following files and manually ensure only one is present: %s", licenseFiles)
err = fmt.Errorf("more than one license file exists: Please review the following files and manually ensure only one is present: %s", licenseFiles)

Choose a reason for hiding this comment

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

Fixes:

copywrite/cmd/license.go:81:10: ST1005: error strings should not be capitalized (staticcheck)
                        err = fmt.Errorf("More than one license file exists. Please review the following files and manually ensure only one is present: %s", licenseFiles)

cliLogger.Error(err.Error())
cobra.CheckErr(err)
return
Expand Down
8 changes: 4 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,25 +202,25 @@ func (c *Config) LoadCommandFlags(flagSet *pflag.FlagSet, mapping map[string]str
func (c *Config) LoadConfigFile(cfgPath string) error {
abs, err := filepath.Abs(cfgPath)
if err != nil {
return fmt.Errorf("Unable to determine config path: %w", err)
return fmt.Errorf("unable to determine config path: %w", err)

Choose a reason for hiding this comment

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

Fixes:

copywrite/config/config.go:205:10: ST1005: error strings should not be capitalized (staticcheck)
                return fmt.Errorf("Unable to determine config path: %w", err)

}
c.absCfgPath = abs

// If a config file exists, let's load it
if _, err := os.Stat(abs); err != nil {
return fmt.Errorf("Config file doesn't exist: %w", err)
return fmt.Errorf("config file doesn't exist: %w", err)
}

// Load HCL config.
err = c.globalKoanf.Load(file.Provider(abs), hcl.Parser(true))
if err != nil {
return fmt.Errorf("Unable to load config: %w", err)
return fmt.Errorf("unable to load config: %w", err)
}
Comment on lines 217 to 218

Choose a reason for hiding this comment

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

Fixes:

copywrite/config/config.go:217:10: ST1005: error strings should not be capitalized (staticcheck)
                return fmt.Errorf("Unable to load config: %w", err)


// Attempt to suss out a Config struct
err = c.globalKoanf.Unmarshal("", &c)
if err != nil {
return fmt.Errorf("Unable to unmarshal config: %w", err)
return fmt.Errorf("unable to unmarshal config: %w", err)

Choose a reason for hiding this comment

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

Fixes:

copywrite/config/config.go:223:10: ST1005: error strings should not be capitalized (staticcheck)
                return fmt.Errorf("Unable to unmarshal config: %w", err

}

return nil
Expand Down
8 changes: 4 additions & 4 deletions dispatch/dispatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ func WaitRunFinished(client *github.Client, opts Options, run github.WorkflowRun
case "in_progress":
// Do nothing, keep watching
default:
return fmt.Errorf("Workflow \"%s\" is in unrepairable state: %s", *run.Name, *this.Status)
return fmt.Errorf("workflow \"%s\" is in unrepairable state: %s", *run.Name, *this.Status)

Choose a reason for hiding this comment

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

Fixes:

copywrite/dispatch/dispatch.go:61:11: ST1005: error strings should not be capitalized (staticcheck)
                        return fmt.Errorf("Workflow \"%s\" is in unrepairable state: %s", *run.Name, *this.Status)

}
}

return fmt.Errorf("Timed out polling for workflow job")
return fmt.Errorf("timed out polling for workflow job")

Choose a reason for hiding this comment

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

Fixes:

copywrite/dispatch/dispatch.go:65:9: ST1005: error strings should not be capitalized (staticcheck)
        return fmt.Errorf("Timed out polling for workflow job")

}

// FindRun finds the most recent GitHub Actions run matching a given run name.
Expand All @@ -86,7 +86,7 @@ func FindRun(client *github.Client, opts Options, runName string) (github.Workfl
runs, _, err := client.Actions.ListWorkflowRunsByFileName(context.Background(), opts.GitHubOwner, opts.GitHubRepo, opts.WorkflowFileName, searchOpts)
if err != nil {
// TODO: handle rate limiting
return github.WorkflowRun{}, fmt.Errorf("Error attempting to find the \"%s\" workflow run: %w", runName, err)
return github.WorkflowRun{}, fmt.Errorf("error attempting to find the \"%s\" workflow run: %w", runName, err)

Choose a reason for hiding this comment

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

Fixes:

copywrite/dispatch/dispatch.go:89:33: ST1005: error strings should not be capitalized (staticcheck)
                        return github.WorkflowRun{}, fmt.Errorf("Error attempting to find the \"%s\" workflow run: %w", runName, err)

}

for _, v := range runs.WorkflowRuns {
Expand All @@ -97,7 +97,7 @@ func FindRun(client *github.Client, opts Options, runName string) (github.Workfl

time.Sleep(time.Duration(opts.SecondsBetweenPolls) * time.Second)
}
return github.WorkflowRun{}, fmt.Errorf("Timed out polling for workflow job")
return github.WorkflowRun{}, fmt.Errorf("timed out polling for workflow job")

Choose a reason for hiding this comment

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

Fixes:

copywrite/dispatch/dispatch.go:100:31: ST1005: error strings should not be capitalized (staticcheck)
        return github.WorkflowRun{}, fmt.Errorf("Timed out polling for workflow job")

}

// Worker spawns an instance of a goroutine that listens for new job requests
Expand Down
18 changes: 9 additions & 9 deletions github/actions/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type Annotation struct {
// ErrorNotInGHA is the error returned when a function can only
// execute in GitHub Actions, but the current execution
// environment is NOT GitHub Actions
var ErrorNotInGHA = errors.New("Not in GitHub Actions")
var ErrorNotInGHA = errors.New("not in GitHub Actions")

Choose a reason for hiding this comment

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

Fixes:

copywrite/github/actions/core.go:51:21: ST1005: error strings should not be capitalized (staticcheck)
var ErrorNotInGHA = errors.New("Not in GitHub Actions")


// New returns a new GitHub Actions Writer
func New(out io.Writer) *GHA {
Expand Down Expand Up @@ -76,12 +76,12 @@ func (gha *GHA) EnableGHAOutput() {
// https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#grouping-log-lines
func (gha *GHA) StartGroup(name string) {
if !gha.IsGHA() {
gha.println(text.Bold.Sprint(name))
_, _ = gha.println(text.Bold.Sprint(name))
return
}

out := "::group::" + name
gha.println(out)
_, _ = gha.println(out)
}

// EndGroup ends a GitHub Actions logging group
Expand All @@ -91,7 +91,7 @@ func (gha *GHA) EndGroup() {
return
}

gha.println("::endgroup::")
_, _ = gha.println("::endgroup::")
}

// SetOutput generates a GitHub Actions output for the current job
Expand Down Expand Up @@ -122,7 +122,7 @@ func (gha *GHA) SetJobSummary(content string) error {
func (gha *GHA) appendToFile(fileEnvVar string, content string) error {
path, exists := os.LookupEnv(fileEnvVar)
if !gha.IsGHA() || !exists {
return fmt.Errorf("Unable to set modify GitHub Actions environment file %s: %w", fileEnvVar, ErrorNotInGHA)
return fmt.Errorf("unable to set modify GitHub Actions environment file %s: %w", fileEnvVar, ErrorNotInGHA)

Choose a reason for hiding this comment

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

Fixes:

github/actions/core.go:125:10: ST1005: error strings should not be capitalized (staticcheck)
                return fmt.Errorf("Unable to set modify GitHub Actions environment file %s: %w", fileEnvVar, ErrorNotInGHA)

}

// Short cut if no content is provided
Expand All @@ -141,7 +141,7 @@ func (gha *GHA) appendToFile(fileEnvVar string, content string) error {
return err
}

defer f.Close()
defer func() { _ = f.Close() }()

Choose a reason for hiding this comment

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

Fixes:

github/actions/core.go:144:15: Error return value of `f.Close` is not checked (errcheck)
        defer f.Close()


_, err = f.WriteString(content)
if err != nil {
Expand Down Expand Up @@ -199,10 +199,10 @@ func (gha *GHA) newAnnotation(T string, a Annotation) {
// "::error file={name},line={line},endLine={endLine},title={title}::{message}"
// "::error file=app.js,line=1,title=Syntax Error::Missing semicolon"
str := fmt.Sprintf("::%s %s::%s", T, strings.Join(attributes, ","), a.Message)
gha.println(str)
_, _ = gha.println(str)
}

// println is an internal helper for printing to the expected output io.Writer
func (gha *GHA) println(i ...interface{}) {
fmt.Fprintln(gha.outWriter, i...)
func (gha *GHA) println(i ...interface{}) (int, error) {
return fmt.Fprintln(gha.outWriter, i...)
Comment on lines -206 to +207

Choose a reason for hiding this comment

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

Fixes:

github/actions/core.go:207:14: Error return value of `fmt.Fprintln` is not checked (errcheck)
        fmt.Fprintln(gha.outWriter, i...)

We are propagating the errors upward. Callers are swallowing the errors for now.

}
4 changes: 2 additions & 2 deletions github/actions/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ func Test_New(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
for k, v := range tt.env {
os.Setenv(k, v)
_ = os.Setenv(k, v)
fmt.Println("Setting env var " + k + " equal to " + v)
}

gha := New(&b)
assert.Equal(t, tt.expectedOutput.isGHA, gha.isGHA)

for k := range tt.env {
os.Unsetenv(k)
_ = os.Unsetenv(k)
Comment on lines -61 to +69

Choose a reason for hiding this comment

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

Fixes:

github/actions/core_test.go:61:14: Error return value of `os.Setenv` is not checked (errcheck)
                                os.Setenv(k, v)
                                         ^
github/actions/core_test.go:69:16: Error return value of `os.Unsetenv` is not checked (errcheck)
                                os.Unsetenv(k)

}
})
}
Expand Down
4 changes: 2 additions & 2 deletions licensecheck/licensecheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func EnsureCorrectName(filePath string) (string, error) {
fmt.Printf("Found improperly named file \"%s\". Renaming to \"%s\"", filePath, desiredPath)
err := os.Rename(filePath, filepath.Join(dir, "LICENSE"))
if err != nil {
return "", fmt.Errorf("Unable to rename file \"%s\". Full error context: %s", filePath, err)
return "", fmt.Errorf("unable to rename file \"%s\". Full error context: %s", filePath, err)

Choose a reason for hiding this comment

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

Fixes:

licensecheck/licensecheck.go:26:15: ST1005: error strings should not be capitalized (staticcheck)
                        return "", fmt.Errorf("Unable to rename file \"%s\". Full error context: %s", filePath, err)
                                   

}
} else {
fmt.Printf("Validated file: %s\n", filePath)
Expand Down Expand Up @@ -53,7 +53,7 @@ func AddLicenseFile(dirPath string, spdxID string) (string, error) {
template, exists := licenseTemplate[spdxID]
if !exists {
validOptions := strings.Join(lo.Keys(licenseTemplate), ", ")
return "", fmt.Errorf("Failed to add license file, unknown SPDX license ID: %s. The following options are supported at this time: %s", spdxID, validOptions)
return "", fmt.Errorf("failed to add license file, unknown SPDX license ID: %s. The following options are supported at this time: %s", spdxID, validOptions)

Choose a reason for hiding this comment

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

Fixes:

licensecheck/licensecheck.go:56:14: ST1005: error strings should not be capitalized (staticcheck)
                return "", fmt.Errorf("Failed to add license file, unknown SPDX license ID: %s. The following options are supported at this time: %s", spdxID, validOptions)

}

destinationPath, err := filepath.Abs(filepath.Join(dirPath, "LICENSE"))
Expand Down