Skip to content

Commit 0fa069c

Browse files
authored
Enable errcheck and staticcheck for golangci-lint v2 and resolve all issues (#4924)
* enable errcheck and staticcheck for golangci-lint v2 and resolve all issues * skip lint on intentional reference of deprecated DetectorType values
1 parent 3a022f9 commit 0fa069c

801 files changed

Lines changed: 1827 additions & 1537 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
with:
2525
# NOTE: Version and args must match scripts/lint.sh
2626
version: v2.11.4
27-
args: --disable errcheck,staticcheck --enable bodyclose,copyloopvar,misspell --timeout 10m
27+
args: --enable bodyclose,copyloopvar,misspell --timeout 10m
2828
man-page-staleness:
2929
name: man-page-staleness
3030
runs-on: ubuntu-latest

hack/checksecretparts/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ func main() {
3333
flag.BoolVar(&failOnFindings, "fail", false, "exit 1 if any findings are reported (default: warning-only)")
3434
flag.BoolVar(&quiet, "quiet", false, "suppress the summary line when no findings are reported")
3535
flag.Usage = func() {
36-
fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [flags] [dir ...]\n", os.Args[0])
37-
fmt.Fprintln(flag.CommandLine.Output(), "\nFinds detector packages that construct detectors.Result without setting SecretParts.")
38-
fmt.Fprintln(flag.CommandLine.Output(), "\nFlags:")
36+
_, _ = fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [flags] [dir ...]\n", os.Args[0])
37+
_, _ = fmt.Fprintln(flag.CommandLine.Output(), "\nFinds detector packages that construct detectors.Result without setting SecretParts.")
38+
_, _ = fmt.Fprintln(flag.CommandLine.Output(), "\nFlags:")
3939
flag.PrintDefaults()
4040
}
4141
flag.Parse()

hack/snifftest/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func main() {
219219
logFatal(err, "error scanning repo")
220220
}
221221
logger.Info("scanned repo", "repo", r)
222-
defer os.RemoveAll(path)
222+
defer func() { _ = os.RemoveAll(path) }()
223223
}(repo)
224224
}
225225

main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ func run(state overseer.State, logSync func() error) {
465465
if *githubScanToken != "" {
466466
// NOTE: this kludge is here to do an authenticated shallow commit
467467
// TODO: refactor to better pass credentials
468-
os.Setenv("GITHUB_TOKEN", *githubScanToken)
468+
_ = os.Setenv("GITHUB_TOKEN", *githubScanToken)
469469
}
470470

471471
if *concurrency <= 0 {
@@ -725,7 +725,7 @@ func runSingleScan(ctx context.Context, cmd string, cfg engine.Config) (metrics,
725725
handleFinishedMetrics := func(ctx context.Context, finishedMetrics <-chan sources.UnitMetrics, jobReportWriter io.WriteCloser) {
726726
go func() {
727727
defer func() {
728-
jobReportWriter.Close()
728+
_ = jobReportWriter.Close()
729729
if namer, ok := jobReportWriter.(interface{ Name() string }); ok {
730730
ctx.Logger().Info("report written", "path", namer.Name())
731731
} else {

pkg/analyzer/analyzers/airbrake/airbrake.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ func (Analyzer) Type() analyzers.AnalyzerType { return analyzers.AnalyzerTypeAir
2525
func (a Analyzer) Analyze(_ context.Context, credInfo map[string]string) (*analyzers.AnalyzerResult, error) {
2626
info, err := AnalyzePermissions(a.Cfg, credInfo["key"])
2727
if err != nil {
28-
return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationAnalyzePermissions, analyzers.ServiceAPI, "", err,
29-
)
28+
return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationAnalyzePermissions, analyzers.ServiceAPI, "", err)
3029
}
3130
return secretInfoToAnalyzerResult(info), nil
3231
}
@@ -109,7 +108,7 @@ func validateKey(cfg *config.Config, key string) (bool, []Project, error) {
109108
}
110109

111110
// read response
112-
defer resp.Body.Close()
111+
defer func() { _ = resp.Body.Close() }()
113112

114113
// if status code is 200, decode response
115114
if resp.StatusCode == 200 {
@@ -150,7 +149,7 @@ func AnalyzePermissions(cfg *config.Config, key string) (*SecretInfo, error) {
150149
return nil, err
151150
}
152151
if !valid {
153-
return nil, fmt.Errorf("Invalid Airbrake User API Key")
152+
return nil, fmt.Errorf("invalid Airbrake User API Key")
154153
}
155154

156155
info := &SecretInfo{

pkg/analyzer/analyzers/airtable/airtablepat/airtable.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func determineScope(token string, perm common.Permission, requiredIDs map[string
119119
if requiredIDs != nil {
120120
for _, key := range endpoint.RequiredIDs {
121121
if value, ok := requiredIDs[key]; ok {
122-
url = strings.Replace(url, fmt.Sprintf("{%s}", key), value, -1)
122+
url = strings.ReplaceAll(url, fmt.Sprintf("{%s}", key), value)
123123
}
124124
}
125125
}
@@ -128,7 +128,7 @@ func determineScope(token string, perm common.Permission, requiredIDs map[string
128128
if err != nil {
129129
return false, err
130130
}
131-
defer resp.Body.Close()
131+
defer func() { _ = resp.Body.Close() }()
132132

133133
if resp.StatusCode == endpoint.ExpectedSuccessStatus {
134134
scopeStatusMap[scopeString] = true

pkg/analyzer/analyzers/airtable/airtablepat/requests.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ func fetchAirtableRecords(token string, baseID string, tableID string) ([]common
1818
if !exists {
1919
return nil, fmt.Errorf("endpoint for ListRecordsEndpoint does not exist")
2020
}
21-
url := strings.Replace(strings.Replace(endpoint.URL, "{baseID}", baseID, -1), "{tableID}", tableID, -1)
21+
url := strings.ReplaceAll(strings.ReplaceAll(endpoint.URL, "{baseID}", baseID), "{tableID}", tableID)
2222
resp, err := common.CallAirtableAPI(token, "GET", url)
2323
if err != nil {
2424
return nil, err
2525
}
26-
defer resp.Body.Close()
26+
defer func() { _ = resp.Body.Close() }()
2727

2828
if resp.StatusCode != http.StatusOK {
2929
return nil, fmt.Errorf("failed to fetch Airtable records, status: %d", resp.StatusCode)

pkg/analyzer/analyzers/airtable/common/common.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func FetchAirtableUserInfo(token string) (*AirtableUserInfo, error) {
3939
if err != nil {
4040
return nil, err
4141
}
42-
defer resp.Body.Close()
42+
defer func() { _ = resp.Body.Close() }()
4343

4444
if resp.StatusCode != http.StatusOK {
4545
return nil, fmt.Errorf("failed to fetch Airtable user info, status: %d", resp.StatusCode)
@@ -62,7 +62,7 @@ func FetchAirtableBases(token string) (*AirtableBases, error) {
6262
if err != nil {
6363
return nil, err
6464
}
65-
defer resp.Body.Close()
65+
defer func() { _ = resp.Body.Close() }()
6666

6767
if resp.StatusCode != http.StatusOK {
6868
return nil, fmt.Errorf("failed to fetch Airtable bases, status: %d", resp.StatusCode)
@@ -96,7 +96,7 @@ func fetchBaseSchema(token string, baseID string) (*Schema, error) {
9696
if err != nil {
9797
return nil, err
9898
}
99-
defer resp.Body.Close()
99+
defer func() { _ = resp.Body.Close() }()
100100

101101
if resp.StatusCode != http.StatusOK {
102102
return nil, fmt.Errorf("failed to fetch schema for base %s, status: %d", baseID, resp.StatusCode)

pkg/analyzer/analyzers/analyzers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func (h *HttpStatusTest) RunTest(headers map[string]string) error {
227227
if err != nil {
228228
return err
229229
}
230-
defer resp.Body.Close()
230+
defer func() { _ = resp.Body.Close() }()
231231

232232
// Check response status code
233233
switch {

pkg/analyzer/analyzers/asana/asana.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,18 +116,18 @@ func AnalyzePermissions(cfg *config.Config, key string) (*SecretInfo, error) {
116116
}
117117

118118
if resp.StatusCode != 200 {
119-
return nil, fmt.Errorf("Invalid Asana API Key")
119+
return nil, fmt.Errorf("invalid Asana API Key")
120120
}
121121

122-
defer resp.Body.Close()
122+
defer func() { _ = resp.Body.Close() }()
123123

124124
err = json.NewDecoder(resp.Body).Decode(&me)
125125
if err != nil {
126126
return nil, err
127127
}
128128

129129
if me.Data.Email == "" {
130-
return nil, fmt.Errorf("Invalid Asana API Key")
130+
return nil, fmt.Errorf("invalid Asana API Key")
131131
}
132132
return &me, nil
133133
}

0 commit comments

Comments
 (0)