Skip to content

Commit

Permalink
refactor: adds linting rules
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-primrose committed May 13, 2024
1 parent 01db4ae commit b3cc42f
Show file tree
Hide file tree
Showing 288 changed files with 6,132 additions and 4,462 deletions.
107 changes: 48 additions & 59 deletions .github/.golangci.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
linters-settings:
gci:
local-prefixes: github.com/open-amt-cloud-toolkit/console
dupl:
threshold: 300
local-prefixes: github.com/open-amt-cloud-toolkit/go-wsman-messages
errorlint:
errorf: true
errcheck:
check-type-assertions: true
check-blank: true
check-blank: false
exhaustive:
check-generated: false
default-signifies-exhaustive: false
funlen:
lines: 65
statements: 40
lines: 100
statements: 45
gocognit:
min-complexity: 15
gocyclo:
Expand All @@ -35,14 +33,12 @@ linters-settings:
gofumpt:
extra-rules: true
gomnd:
settings:
mnd:
checks:
- argument
- case
- condition
- operation
- return
checks:
- argument
- case
- condition
- operation
- return
govet:
check-shadowing: true
misspell:
Expand All @@ -56,69 +52,64 @@ linters-settings:
linters:
disable-all: true
enable:
# - errcheck
- gosimple
# - govet
- ineffassign
- unused
# - asciicheck
- asciicheck
# - bodyclose
# - cyclop
# - deadcode
# # - depguard
# - dogsled
# - depguard
- dogsled
# - dupl
# - durationcheck
# - errcheck
# - errorlint
# - exhaustive
# - exportloopref
# - forbidigo
- durationcheck
- errcheck
- errorlint
- exhaustive
- exportloopref
- forbidigo
# - funlen
# - gci
# # - gochecknoglobals
# - gochecknoinits
- gci
# - gochecknoglobals
- gochecknoinits
# - gocognit
# - goconst
- goconst
# - gocritic
# - gocyclo
# - godot
- godot
# - godox
# - goerr113
# - gofmt
# - gofumpt
# - goimports
- gofmt
- gofumpt
- goimports
# - gomnd
# - gomodguard
# - goprintffuncname
- gomodguard
- goprintffuncname
# - gosec
# - gosimple
- gosimple
# - govet
# - ineffassign
# - makezero
- ineffassign
- makezero
# - misspell
# - nakedret
- nakedret
# - nestif
# - nlreturn
- nlreturn
# - noctx
# - nolintlint
- nolintlint
# - paralleltest
# - predeclared
- predeclared
# - revive
# - rowserrcheck
# - sqlclosecheck
# - staticcheck
- rowserrcheck
- sqlclosecheck
- staticcheck
# - structcheck
# - stylecheck
# - tparallel
# - thelper
# - typecheck
# - unconvert
- tparallel
- thelper
- typecheck
- unconvert
# - unparam
# - unused
- unused
# - varcheck
# - wsl
# - whitespace
- wsl
- whitespace

# disable:
# - exhaustivestruct
Expand All @@ -141,7 +132,5 @@ issues:
linters:
- funlen
- goerr113

run:
skip-dirs:
- docs
exclude-dirs:
- docs
103 changes: 103 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: CI
on:
push:
branches: [ main ]
pull_request:
permissions:
contents: read # for actions/checkout to fetch code

jobs:
formatting:
name: runner / formatting
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b
- name: Format
run: if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then exit 1; fi
- name: Run go vet
run: go vet ./...

golangci-lint:
name: runner / golangci-lint
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b
- name: golangci-lint
uses: reviewdog/action-golangci-lint@v2
with:
fail_on_error: true
golangci_lint_flags: "--config=.github/.golangci.yml ./..."

yamllint:
name: runner / yamllint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b
- uses: reviewdog/action-yamllint@v1
with:
fail_on_error: true
reporter: github-pr-review
yamllint_flags: '-d "{extends: default, rules: {truthy: disable}}" .'

dotenv-linter:
name: runner / dotenv-linter
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b
- uses: dotenv-linter/action-dotenv-linter@v2
with:
reporter: github-pr-review

check-dependencies:
name: runner / check-dependencies
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b
- uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7
- name: WriteGoList
run: go list -json -m all > go.list
- name: Nancy
uses: sonatype-nexus-community/nancy-github-action@main
continue-on-error: true
- name: "Dependency Review"
uses: actions/dependency-review-action@0c155c5e8556a497adf53f2c18edabf945ed8e70 # v4.3.2

tests:
name: runner / build and tests
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [1.20.x, 1.21.x, 1.22.x]
os: [windows-2019, windows-2022, ubuntu-22.04, ubuntu-20.04]
steps:
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b
- uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
- name: Install Test Converter and run tests
run: |
export GOPATH="$HOME/go/"
export PATH=$PATH:$GOPATH/bin
go install github.com/jstemmer/go-junit-report/v2@latest
go test -covermode=atomic -coverprofile=coverage.out -race -v ./... > test_output.txt 2>&1 || true
cat test_output.txt
cat test_output.txt | go-junit-report -set-exit-code > junit-${{matrix.os}}-${{matrix.go-version}}-${{github.run_attempt}}.xml
if grep -q "FAIL" test_output.txt; then exit 1; fi
- name: Upload Coverage Results
uses: codecov/codecov-action@5ecb98a3c6b747ed38dc09f787459979aebb39be # v4.3.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: GitHub Upload Release Artifacts
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
with:
name: JUnit Results ${{matrix.os}}-${{matrix.go-version}}-${{github.run_attempt}}
path: junit-${{matrix.os}}-${{matrix.go-version}}-${{github.run_attempt}}.xml
# - name: Integration tests
# run: "docker-compose up \
# --build \
# --abort-on-container-exit \
# --exit-code-from integration"
10 changes: 5 additions & 5 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ on:
types:
- created
push:
branches: [ main, v2.0 ]
branches: [ main ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main, v2.0 ]
branches: [ main ]
schedule:
- cron: '26 23 * * 0'

Expand Down Expand Up @@ -55,7 +55,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@d39d31e687223d841ef683f52467bd88e9b21c14 # v3.25.3
uses: github/codeql-action/init@ccf74c947955fd1cf117aef6a0e4e66191ef6f61 # v3.25.4
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -66,7 +66,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@d39d31e687223d841ef683f52467bd88e9b21c14 # v3.25.3
uses: github/codeql-action/autobuild@ccf74c947955fd1cf117aef6a0e4e66191ef6f61 # v3.25.4

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -80,7 +80,7 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@d39d31e687223d841ef683f52467bd88e9b21c14 # v3.25.3
uses: github/codeql-action/analyze@ccf74c947955fd1cf117aef6a0e4e66191ef6f61 # v3.25.4
- name: Generate Security Report
uses: rsdmike/github-security-report-action@a149b24539044c92786ec39af8ba38c93496495d # v3.0.4
continue-on-error: true
Expand Down
66 changes: 0 additions & 66 deletions .github/workflows/go.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ jobs:

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@d39d31e687223d841ef683f52467bd88e9b21c14 # v3.25.3
uses: github/codeql-action/upload-sarif@ccf74c947955fd1cf117aef6a0e4e66191ef6f61 # v3.25.4
with:
sarif_file: results.sarif
Loading

0 comments on commit b3cc42f

Please sign in to comment.