From 8694db5214616822ae199761c5f0259d5fbd034b Mon Sep 17 00:00:00 2001 From: Andrew Kroh Date: Thu, 24 Feb 2022 10:29:31 -0500 Subject: [PATCH] Add .go-version and .golangci.yml Enable golangci-lint and specify the Go version in a .go-version file. --- .ci/Jenkinsfile | 1 + .github/workflows/golangci-lint.yml | 33 +++++++++ .go-version | 1 + .golangci.yml | 105 ++++++++++++++++++++++++++++ 4 files changed, 140 insertions(+) create mode 100644 .github/workflows/golangci-lint.yml create mode 100644 .go-version create mode 100644 .golangci.yml diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index ba8851e..2e9bc59 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -32,6 +32,7 @@ pipeline { steps { deleteDir() gitCheckout(basedir: "${BASE_DIR}") + setEnvVar("GO_VERSION", readFile("${BASE_DIR}/.go-version").trim()) stash allowEmpty: true, name: 'source', useDefaultExcludes: false } } diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..8369634 --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,33 @@ +name: golangci-lint +on: + pull_request: + +permissions: + contents: read + +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Read .go-version file + id: goversion + run: echo "::set-output name=version::$(cat .go-version)" + + - uses: actions/setup-go@v2 + with: + go-version: "${{ steps.goversion.outputs.version }}" + + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + version: v1.44.2 + args: --timeout=5m + + # Ignore pre-existing issues. + only-new-issues: true + + # Use the Go version specified in .go-version for consistency. + skip-go-installation: true diff --git a/.go-version b/.go-version new file mode 100644 index 0000000..3661bc0 --- /dev/null +++ b/.go-version @@ -0,0 +1 @@ +1.17.7 diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..cc72a0e --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,105 @@ +--- + +run: + issues-exit-code: 1 + modules-download-mode: readonly + +linters: + disable-all: true + enable: + - deadcode + - errcheck + - gosimple + - govet + - ineffassign + - staticcheck + - structcheck + - stylecheck + - typecheck + - unused + - varcheck + - depguard + - errorlint + - gofumpt + - goimports + - godox + - goheader + - ifshort + - misspell + - prealloc + - unconvert + - revive + fast: false + +linters-settings: + goimports: + local-prefixes: github.com/elastic/go-libaudit + gofumpt: + extra-rules: true + goheader: + # Use https://github.com/elastic/go-licenser to automatically add headers. + template: |- + Licensed to Elasticsearch B.V. under one or more contributor + license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright + ownership. Elasticsearch B.V. licenses this file to you under + the Apache License, Version 2.0 (the "License"); you may + not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + revive: + enable-all-rules: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md + rules: + - name: bare-return + - name: call-to-gc + - name: confusing-results + - name: constant-logical-expr + - name: context-as-argument + - name: deep-exit + - name: defer + - name: duplicated-imports + - name: early-return + - name: empty-block + - name: error-strings + - name: errorf + - name: exported + arguments: + - checkPrivateReceivers + - name: imports-blacklist + arguments: + - github.com/pkg/errors + - name: increment-decrement + - name: range + - name: range-val-address + - name: range-val-in-closure + - name: receiver-naming + - name: struct-tag + - name: time-naming + - name: unconditional-recursion + - name: unexported-naming + - name: unexported-return + - name: unnecessary-stmt + - name: unreachable-code + - name: unused-parameter + - name: unused-receiver + - name: var-declaration + - name: waitgroup-by-value + stylecheck: + checks: + - all + +issues: + include: + # If you're going to write a comment follow the conventions. + # https://go.dev/doc/effective_go#commentary. + # comment on exported (.+) should be of the form "(.+)..." + - EXC0014