Skip to content

Commit

Permalink
Add .go-version and .golangci.yml
Browse files Browse the repository at this point in the history
Enable golangci-lint and specify the Go version in a .go-version file.
  • Loading branch information
andrewkroh committed Feb 24, 2022
1 parent 5b1e227 commit 8694db5
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 0 deletions.
1 change: 1 addition & 0 deletions .ci/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .go-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.17.7
105 changes: 105 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8694db5

Please sign in to comment.