From 6080228e686e65eba8658090168abf7c52fc6e8b Mon Sep 17 00:00:00 2001 From: Chris Koch Date: Sun, 24 Dec 2023 12:43:09 -0800 Subject: [PATCH] Lint setup Signed-off-by: Chris Koch --- .github/workflows/golangci-lint.yml | 29 +++++++++++++ .golangci.yml | 66 +++++++++++++++++++++++++++++ .revive.toml | 28 ++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 .github/workflows/golangci-lint.yml create mode 100644 .golangci.yml create mode 100644 .revive.toml diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 00000000..8dd7c17f --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,29 @@ +name: golangci-lint +on: + push: + tags: + - v* + branches: + - main + pull_request: + branches: + - main + +permissions: + contents: read + # Optional: allow read access to pull request. Use with `only-new-issues` option. + pull-requests: read + +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/setup-go@v3 + with: + go-version: '1.20' + - uses: actions/checkout@v3 + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: latest diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..333e8fed --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,66 @@ +linters: + enable: + - containedctx + - gocritic + - godot + - nilerr + - revive + - unconvert + +issues: + include: + - EXC0012 + - EXC0013 + - EXC0014 + - EXC0015 + +linters-settings: + gocritic: + disabledChecks: + - ifElseChain + revive: + # Maximum number of open files at the same time. + # See https://github.com/mgechev/revive#command-line-flags + # Defaults to unlimited. + max-open-files: 2048 + # When set to false, ignores files with "GENERATED" header, similar to golint. + # See https://github.com/mgechev/revive#available-rules for details. + # Default: false + ignore-generated-header: true + # Sets the default severity. + # See https://github.com/mgechev/revive#configuration + # Default: warning + severity: error + # Default: false + # Sets the default failure confidence. + # This means that linting errors with less than 0.8 confidence will be ignored. + # Default: 0.8 + confidence: 0.8 + rules: + - name: blank-imports + - name: context-as-argument + arguments: + - allowTypesBefore: "*testing.T,*github.com/user/repo/testing.Harness" + - name: context-keys-type + - name: error-return + - name: error-strings + - name: error-naming + - name: exported + arguments: + - "checkPrivateReceivers" + - "sayRepetitiveInsteadOfStutters" + - name: if-return + - name: increment-decrement + - name: var-naming + - name: var-declaration + - name: package-comments + - name: range + - name: receiver-naming + - name: time-naming + - name: unexported-return + - name: indent-error-flow + - name: errorf + - name: early-return + - name: file-header + arguments: + - "Copyright 20[1-2][0-9](-20[1-2][0-9])? the u-root Authors. All rights reserved Use of this source code is governed by a BSD-style license that can be found in the LICENSE file." diff --git a/.revive.toml b/.revive.toml new file mode 100644 index 00000000..c403b4d7 --- /dev/null +++ b/.revive.toml @@ -0,0 +1,28 @@ +ignoreGeneratedHeader = false +severity = "warning" +confidence = 0.8 +errorCode = 0 +warningCode = 0 + +[rule.blank-imports] +[rule.context-as-argument] +[rule.context-keys-type] +[rule.dot-imports] +[rule.error-return] +[rule.error-strings] +[rule.error-naming] +[rule.exported] +[rule.if-return] +[rule.increment-decrement] +[rule.var-naming] +[rule.var-declaration] +[rule.package-comments] +[rule.range] +[rule.receiver-naming] +[rule.time-naming] +[rule.unexported-return] +[rule.indent-error-flow] +[rule.errorf] +[rule.early-return] +[rule.file-header] + arguments=["Copyright 20[1-2][0-9](-20[1-2][0-9])? the u-root Authors. All rights reserved Use of this source code is governed by a BSD-style license that can be found in the LICENSE file."]