Repository: google/certificate-transparency-go
Pull request #940 (2022-05-27 11:22:51)

Update linter, fix errors, delete travis config
This brings the linter and rules consistent with trillian and trillian-examples. Fixed a bunch of deprecated method lint errors.



Patch:
diff --git a/.golangci.yaml b/.golangci.yaml
index 31cd4853..34c803a8 100644
--- a/.golangci.yaml
+++ b/.golangci.yaml
@@ -2,6 +2,7 @@ run:
   deadline: 90s
   skip-dirs:
     - (^|/)x509($|/)
+    - (^|/)x509util($|/)
     - (^|/)asn1($|/)
 
 linters-settings:
@@ -18,16 +19,16 @@ linters-settings:
 linters:
   disable-all: true
   enable:
+    - deadcode
+    - depguard
     - gocyclo
     - gofmt
     - goimports
-    - revive
-    - megacheck
-    - misspell
     - govet
-    - depguard
-    - deadcode
     - ineffassign
+    - megacheck
+    - misspell
+    - revive
     - varcheck
     # TODO(gbelvin): write license linter and commit to upstream.
     # ./scripts/check_license.sh is run by ./scripts/presubmit.sh
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index a296b9f7..00000000
--- a/.travis.yml
+++ /dev/null
@@ -1,114 +0,0 @@
-version: ~> 1.0
-os: linux
-dist: xenial
-language: go
-go: "1.14.x"
-go_import_path: github.com/google/certificate-transparency-go
-
-env:
-  global:
-  - GO111MODULE=on
-  - GOPROXY=https://proxy.golang.org
-
-jobs:
-  fast_finish: true
-  include:
-    - name: "go mod tidy"
-      before_install: skip
-      install: skip
-      before_script: go mod tidy -v
-      script: git diff --exit-code -- go.mod go.sum
-    - name: "default build"
-      env:
-      - GOFLAGS=""
-    - name: "build with race detection"
-      env:
-      - GOFLAGS="-race"
-      - PRESUBMIT_OPTS="--no-linters"
-    - name: "build with etcd and coverage report"
-      env:
-      - WITH_ETCD=true
-      - PRESUBMIT_OPTS="--no-linters --coverage"
-      after_success:
-      - cp /tmp/coverage.txt .
-      - bash <(curl -s https://codecov.io/bash)
-    - name: "build with etcd and race detection"
-      env:
-      - WITH_ETCD=true
-      - GOFLAGS="-race"
-      - PRESUBMIT_OPTS="--no-linters"
-    # The CT integration tests do not currently use a pkcs11 key. This only tests the build.
-    - name: "build with PKCS#11 support and race detection"
-      env:
-      - WITH_PKCS11=true
-      - GOFLAGS="-race --tags=pkcs11"
-      - PRESUBMIT_OPTS="--no-linters"
-  allow_failures:
-    - name: "go mod tidy"
-
-
-cache:
-  directories:
-    - "$HOME/gopath/pkg/mod"
-
-services:
-  - docker
-  - mysql
-
-install:
-  - mkdir ../protoc
-  - |
-    (
-      cd ../protoc
-      PROTOC_VERSION=3.11.4
-      wget "https://github.com/google/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-${TRAVIS_OS_NAME}-x86_64.zip"
-      unzip "protoc-${PROTOC_VERSION}-${TRAVIS_OS_NAME}-x86_64.zip"
-    )
-  - export PATH=$(pwd)/../protoc/bin:$PATH
-  - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.21.0
-  - GOPROXY=direct go install
-     github.com/golang/protobuf/proto
-     github.com/golang/protobuf/protoc-gen-go
-     github.com/golang/mock/mockgen
-     go.etcd.io/etcd
-     go.etcd.io/etcd/etcdctl
-     github.com/fullstorydev/grpcurl/cmd/grpcurl
-
-before_script:
-  - |
-      # Use latest versions of Trillian docker images built by the Trillian CI cloudbuilders.
-      export PROJECT_ID=trillian-opensource-ci
-      docker pull gcr.io/$PROJECT_ID/log_server:latest
-      docker tag gcr.io/$PROJECT_ID/log_server:latest deployment_trillian-log-server
-      docker pull gcr.io/$PROJECT_ID/log_signer:latest
-      docker tag gcr.io/$PROJECT_ID/log_signer:latest deployment_trillian-log-signer
-
-      # Bring up an ephemeral trillian instance using the docker-compose config in the Trillian repo:
-      export TRILLIAN_LOCATION="$(go list -f '{{.Dir}}' github.com/google/trillian)"
-      docker-compose -f ${TRILLIAN_LOCATION}/examples/deployment/docker-compose.yml pull mysql trillian-log-server trillian-log-signer
-      docker-compose -f ${TRILLIAN_LOCATION}/examples/deployment/docker-compose.yml up -d mysql trillian-log-server trillian-log-signer
-
-      export TRILLIAN_LOG_SERVER_1="localhost:8090"
-      export TRILLIAN_LOG_SERVERS="${TRILLIAN_LOG_SERVER_1}"
-
-script:
-  - set -e
-  - cd $HOME/gopath/src/github.com/google/certificate-transparency-go
-  - ./scripts/presubmit.sh ${PRESUBMIT_OPTS}
-  - |
-      # Check re-generation didn't change anything
-      status=$(git status --porcelain | grep -v coverage) || :
-      if [[ -n ${status} ]]; then
-        echo "Regenerated files differ from checked-in versions: ${status}"
-        git status
-        git diff
-        exit 1
-      fi
-  - |
-      if [[ "${WITH_ETCD}" == "true" ]]; then
-        export ETCD_DIR="${GOPATH}/bin"
-      fi
-  - ./trillian/integration/integration_test.sh
-  - HAMMER_OPTS="--operations=1500" ./trillian/integration/ct_hammer_test.sh
-  - set +e
-
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 03991f61..866e2fa8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,7 @@
 
 ### Misc
 
+ * updated golangci-lint to v1.46.1 (developers should update to this version)
  * update `google.golang.org/grpc` to v1.46.0
  * `ctclient` tool now uses Cobra for better CLI experience (#901).
  * #800: Remove dependency from `ratelimit`.
diff --git a/README.md b/README.md
index 67c2e7bc..ad9c320f 100644
--- a/README.md
+++ b/README.md
@@ -91,10 +91,7 @@ pull requests for review.
 
 ```bash
 # Install golangci-lint
-go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
-cd $GOPATH/src/github.com/golangci/golangci-lint/cmd/golangci-lint
-go install -ldflags "-X 'main.version=$(git describe --tags)' -X 'main.commit=$(git rev-parse --short HEAD)' -X 'main.date=$(date)'"
-cd -
+go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.1
 
 # Run code generation, build, test and linters
 ./scripts/presubmit.sh
diff --git a/fixchain/ratelimiter/limiter.go b/fixchain/ratelimiter/limiter.go
index 9865e7a4..2477920e 100644
--- a/fixchain/ratelimiter/limiter.go
+++ b/fixchain/ratelimiter/limiter.go
@@ -17,6 +17,7 @@ package ratelimiter
 
 import (
 	"context"
+
 	"golang.org/x/time/rate"
 )
 
diff --git a/integration/Dockerfile b/integration/Dockerfile
index 8ddf49b5..d63002b8 100644
--- a/integration/Dockerfile
+++ b/integration/Dockerfile
@@ -11,7 +11,7 @@ ENV GO111MODULE=on
 RUN apt-get update && apt-get -y install build-essential curl docker-compose lsof netcat unzip wget xxd
 
 RUN cd /usr/bin && curl -L -O https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 && mv jq-linux64 /usr/bin/jq && chmod +x /usr/bin/jq
-RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.18.0
+RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.46.1
 RUN mkdir protoc && \
     (cd protoc && \
     PROTOC_VERSION=3.20.1 && \
diff --git a/internal/witness/client/http/witness_client.go b/internal/witness/client/http/witness_client.go
index 303ae582..707e4ea5 100644
--- a/internal/witness/client/http/witness_client.go
+++ b/internal/witness/client/http/witness_client.go
@@ -30,7 +30,7 @@ import (
 )
 
 // ErrSTHTooOld is returned if the STH passed to Update needs to be updated.
-var ErrSTHTooOld error = errors.New("STH too old")
+var ErrSTHTooOld = errors.New("STH too old")
 
 // Witness consists of the witness' URL and signature verifier.
 type Witness struct {
diff --git a/scanner/scanner.go b/scanner/scanner.go
index 3b7d671d..fac44fdc 100644
--- a/scanner/scanner.go
+++ b/scanner/scanner.go
@@ -28,7 +28,7 @@ import (
 )
 
 // ScannerOptions holds configuration options for the Scanner.
-type ScannerOptions struct { // nolint:golint
+type ScannerOptions struct { // nolint:revive
 	FetcherOptions
 
 	// Custom matcher for x509 Certificates, functor will be called for each
diff --git a/tls/signature.go b/tls/signature.go
index 287dab12..c02b2982 100644
--- a/tls/signature.go
+++ b/tls/signature.go
@@ -16,7 +16,7 @@ package tls
 
 import (
 	"crypto"
-	"crypto/dsa"
+	"crypto/dsa" //nolint:staticcheck
 	"crypto/ecdsa"
 	_ "crypto/md5" // For registration side-effect
 	"crypto/rand"
diff --git a/tls/types.go b/tls/types.go
index 1189c1bf..b8eaf24b 100644
--- a/tls/types.go
+++ b/tls/types.go
@@ -16,7 +16,7 @@ package tls
 
 import (
 	"crypto"
-	"crypto/dsa"
+	"crypto/dsa" //nolint:staticcheck
 	"crypto/ecdsa"
 	"crypto/rsa"
 	"fmt"
diff --git a/trillian/integration/ct_integration.go b/trillian/integration/ct_integration.go
index c1d629cf..2630c950 100644
--- a/trillian/integration/ct_integration.go
+++ b/trillian/integration/ct_integration.go
@@ -50,6 +50,7 @@ import (
 	"github.com/transparency-dev/merkle/rfc6962"
 	"golang.org/x/net/context/ctxhttp"
 	"google.golang.org/grpc"
+	"google.golang.org/grpc/credentials/insecure"
 	"google.golang.org/protobuf/types/known/fieldmaskpb"
 
 	ct "github.com/google/certificate-transparency-go"
@@ -978,7 +979,7 @@ func setTreeState(ctx context.Context, adminServer string, logID int64, state tr
 		UpdateMask: treeStateMask,
 	}
 
-	conn, err := grpc.Dial(adminServer, grpc.WithInsecure())
+	conn, err := grpc.Dial(adminServer, grpc.WithTransportCredentials(insecure.NewCredentials()))
 	if err != nil {
 		return err
 	}
diff --git a/trillian/integration/logenv.go b/trillian/integration/logenv.go
index 81b5c4dc..75f0eedf 100644
--- a/trillian/integration/logenv.go
+++ b/trillian/integration/logenv.go
@@ -49,7 +49,7 @@ type CTLogEnv struct {
 // Created logIDs will be set to cfgs.
 func NewCTLogEnv(ctx context.Context, cfgs []*configpb.LogConfig, numSequencers int, testID string) (*CTLogEnv, error) {
 	// Start log server and signer.
-	logEnv, err := integration.NewLogEnv(ctx, numSequencers, testID)
+	logEnv, err := integration.NewLogEnvWithGRPCOptions(ctx, numSequencers, nil, nil)
 	if err != nil {
 		return nil, fmt.Errorf("failed to create LogEnv: %v", err)
 	}
diff --git a/trillian/migrillian/main.go b/trillian/migrillian/main.go
index 47496f13..7476e618 100644
--- a/trillian/migrillian/main.go
+++ b/trillian/migrillian/main.go
@@ -29,6 +29,7 @@ import (
 	"github.com/golang/glog"
 	clientv3 "go.etcd.io/etcd/client/v3"
 	"google.golang.org/grpc"
+	"google.golang.org/grpc/credentials/insecure"
 
 	"github.com/google/certificate-transparency-go/client"
 	"github.com/google/certificate-transparency-go/jsonclient"
@@ -75,7 +76,7 @@ func main() {
 	}
 
 	glog.Infof("Dialling Trillian backend: %v", *backend)
-	conn, err := grpc.Dial(*backend, grpc.WithInsecure(), grpc.WithBlock())
+	conn, err := grpc.Dial(*backend, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())
 	if err != nil {
 		glog.Exitf("Could not dial Trillian server: %v: %v", *backend, err)
 	}
diff --git a/types.go b/types.go
index a965f034..3ea2111c 100644
--- a/types.go
+++ b/types.go
@@ -132,7 +132,7 @@ type PreCert struct {
 
 // CTExtensions is a representation of the raw bytes of any CtExtension
 // structure (see section 3.2).
-// nolint: golint
+// nolint: revive
 type CTExtensions []byte // tls:"minlen:0,maxlen:65535"`
 
 // MerkleTreeNode represents an internal node in the CT tree.


Test patch:
diff --git a/signatures_test.go b/signatures_test.go
index 09b7b4d3..94293377 100644
--- a/signatures_test.go
+++ b/signatures_test.go
@@ -16,7 +16,7 @@ package ct
 
 import (
 	"crypto"
-	"crypto/dsa"
+	"crypto/dsa" //nolint:staticcheck
 	"crypto/ecdsa"
 	"crypto/elliptic"
 	"crypto/rand"
diff --git a/tls/types_test.go b/tls/types_test.go
index 6b6f8aed..4b4cbb05 100644
--- a/tls/types_test.go
+++ b/tls/types_test.go
@@ -16,7 +16,7 @@ package tls
 
 import (
 	"crypto"
-	"crypto/dsa"
+	"crypto/dsa" //nolint:staticcheck
 	"crypto/ecdsa"
 	"crypto/rsa"
 	"testing"