From 8bd86f7b815c6e59d3e355ed10ee4fb29063a484 Mon Sep 17 00:00:00 2001 From: christopher-henderson Date: Sat, 16 Dec 2023 05:21:21 -0800 Subject: [PATCH 1/3] Code Linter Update --- .github/workflows/golangci-lint.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 3a6f64a92..bbf31c9f0 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -21,8 +21,8 @@ jobs: go-version: ^1.20 - name: Install golangci-lint run: | - wget https://github.com/golangci/golangci-lint/releases/download/v1.51.2/golangci-lint-1.51.2-linux-amd64.deb - sudo apt install -y ./golangci-lint-1.51.2-linux-amd64.deb\ + wget https://github.com/golangci/golangci-lint/releases/download/v1.55.2/golangci-lint-1.55.2-linux-amd64.deb + sudo apt install -y ./golangci-lint-1.55.2-linux-amd64.deb - name: Run golangci-lint run: | cd v3 From 78ee03e370c7656afb67e8cd6c80df57ad43afab Mon Sep 17 00:00:00 2001 From: christopher-henderson Date: Sat, 16 Dec 2023 05:30:22 -0800 Subject: [PATCH 2/3] linter suggestions --- v3/formattedoutput/formattedOutput.go | 4 ++-- v3/integration/lints/lint/lint.go | 2 +- v3/integration/lints/lints/not_committing_genTestCerts.go | 3 ++- v3/lint/configuration_test.go | 1 + v3/lints/rfc/lint_serial_number_longer_than_20_octets.go | 2 +- v3/test/configuration_test_framework_test.go | 2 +- 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/v3/formattedoutput/formattedOutput.go b/v3/formattedoutput/formattedOutput.go index c57e38824..8d5ca229d 100644 --- a/v3/formattedoutput/formattedOutput.go +++ b/v3/formattedoutput/formattedOutput.go @@ -75,8 +75,8 @@ func OutputSummary(zlintResult *zlint.ResultSet, longSummary bool) { " Details ", } lines := [][]string{} - lsl := "" - rescount := "" + var lsl string + var rescount string hlengths := printTableHeadings(headings) // Construct the table lines, but don't repeat diff --git a/v3/integration/lints/lint/lint.go b/v3/integration/lints/lint/lint.go index d9b39acf0..752a3ad1b 100644 --- a/v3/integration/lints/lint/lint.go +++ b/v3/integration/lints/lint/lint.go @@ -137,7 +137,7 @@ type File struct { // // The word "remember" begins at position 81 within this text, therefor LineOf(81) should return line 3. func (f *File) LineOf(pos token.Pos) int { - start := 0 + var start int end := 0 for lineno, line := range f.Lines { start = end diff --git a/v3/integration/lints/lints/not_committing_genTestCerts.go b/v3/integration/lints/lints/not_committing_genTestCerts.go index 2be507bb1..f3294254c 100644 --- a/v3/integration/lints/lints/not_committing_genTestCerts.go +++ b/v3/integration/lints/lints/not_committing_genTestCerts.go @@ -16,6 +16,7 @@ package lints import ( "crypto/sha256" + "encoding/hex" "fmt" "go/ast" "os" @@ -42,7 +43,7 @@ func (i *NotCommittingGenTestCerts) Lint(tree *ast.File, file *lint.File) *lint. if err != nil { return lint.NewResult(fmt.Sprintf("failed to hash the contents of %s", file.Name)) } - got := fmt.Sprintf("%x", hasher.Sum([]byte{})) + got := hex.EncodeToString(hasher.Sum([]byte{})) if got == want { return nil } diff --git a/v3/lint/configuration_test.go b/v3/lint/configuration_test.go index cf7fb8ba3..8d5e19a50 100644 --- a/v3/lint/configuration_test.go +++ b/v3/lint/configuration_test.go @@ -1080,6 +1080,7 @@ func TestStripGlobalsFromStructWithPrivates(t *testing.T) { B Global C int //nolint:unused + //nolint:structcheck d int } test := Test{} diff --git a/v3/lints/rfc/lint_serial_number_longer_than_20_octets.go b/v3/lints/rfc/lint_serial_number_longer_than_20_octets.go index 50fa4f07c..030d770df 100644 --- a/v3/lints/rfc/lint_serial_number_longer_than_20_octets.go +++ b/v3/lints/rfc/lint_serial_number_longer_than_20_octets.go @@ -75,7 +75,7 @@ func (l *serialNumberTooLong) Execute(c *x509.Certificate) *lint.LintResult { serial := new(asn1.RawValue) _, err = asn1.Unmarshal(encoding, serial) if err != nil { - return &lint.LintResult{Status: lint.Fatal, Details: fmt.Sprint(err)} + return &lint.LintResult{Status: lint.Fatal, Details: err.Error()} } length := len(serial.Bytes) if length > 20 { diff --git a/v3/test/configuration_test_framework_test.go b/v3/test/configuration_test_framework_test.go index 904f13ead..cd7042914 100644 --- a/v3/test/configuration_test_framework_test.go +++ b/v3/test/configuration_test_framework_test.go @@ -183,7 +183,7 @@ type LintEmbedsAConfiguration struct { } type embeddedConfiguration struct { - IsWebPKI bool `toml:"is_web_pki" comment:"Indicates that the certificate is intended for the Web PKI."` + IsWebPKI bool `comment:"Indicates that the certificate is intended for the Web PKI." toml:"is_web_pki"` } func init() { From 614c31e5e2e04aea701325c05b066d2ec2123e77 Mon Sep 17 00:00:00 2001 From: christopher-henderson Date: Sat, 16 Dec 2023 05:39:21 -0800 Subject: [PATCH 3/3] fixing code lints --- v3/lint/configuration_test.go | 3 +-- v3/lints/rfc/lint_serial_number_longer_than_20_octets.go | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/v3/lint/configuration_test.go b/v3/lint/configuration_test.go index 8d5e19a50..892ec8d94 100644 --- a/v3/lint/configuration_test.go +++ b/v3/lint/configuration_test.go @@ -1079,8 +1079,7 @@ func TestStripGlobalsFromStructWithPrivates(t *testing.T) { A string B Global C int - //nolint:unused - //nolint:structcheck + //nolint:unused,structcheck d int } test := Test{} diff --git a/v3/lints/rfc/lint_serial_number_longer_than_20_octets.go b/v3/lints/rfc/lint_serial_number_longer_than_20_octets.go index 030d770df..20114ae1f 100644 --- a/v3/lints/rfc/lint_serial_number_longer_than_20_octets.go +++ b/v3/lints/rfc/lint_serial_number_longer_than_20_octets.go @@ -70,7 +70,7 @@ func (l *serialNumberTooLong) Execute(c *x509.Certificate) *lint.LintResult { // DER encoded lengths are without having to guess. encoding, err := asn1.Marshal(c.SerialNumber) if err != nil { - return &lint.LintResult{Status: lint.Fatal, Details: fmt.Sprint(err)} + return &lint.LintResult{Status: lint.Fatal, Details: err.Error()} } serial := new(asn1.RawValue) _, err = asn1.Unmarshal(encoding, serial)