Skip to content

Commit

Permalink
Merge pull request #34 from nspcc-dev/add-linter
Browse files Browse the repository at this point in the history
workflows: add common Go linter, fix #21
  • Loading branch information
roman-khimov authored Sep 9, 2024
2 parents d48bb4e + 730fc2d commit 36dae73
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/go-linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Go linter

on:
workflow_call:
inputs:
ref:
type: string
description: 'Ref to test [default: latest master; examples: 0a4ff9d3e4a9ab432fd5812eb18c98e03b5a7432'
required: false
default: ''
workdir:
type: string
description: 'Working directory'
required: false
default: '.'

jobs:
linter:
name: Lint
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}

- name: Checkout .github repository
uses: actions/checkout@v4
with:
repository: nspcc-dev/.github
path: nspcc-gh

- uses: actions/setup-go@v5
with:
go-version-file: ${{ inputs.workdir }}/go.mod
cache-dependency-path: ${{ inputs.workdir }}/go.sum

- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
working-directory: ${{ inputs.workdir }}
args: --config=${{ github.workspace }}/nspcc-gh/.golangci.yml
83 changes: 83 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# This file contains all available configuration options
# with their default values.

# options for analysis running
run:
# timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 5m

# include test files or not, default is true
tests: true

# output configuration options
output:
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
formats:
- format: tab

# all available settings of specific linters
linters-settings:
exhaustive:
# indicates that switch statements are to be considered exhaustive if a
# 'default' case is present, even if all enum members aren't listed in the
# switch
default-signifies-exhaustive: true
gofmt:
rewrite-rules:
- pattern: 'interface{}'
replacement: 'any'
gomodguard:
blocked:
modules:
- github.com/pkg/errors:
reason: "Obsolete after the 1.13 release; use the standard `errors` package"
revive:
rules:
- name: duplicated-imports

linters:
enable:
# mandatory linters
- govet
- revive

# some default golangci-lint linters
- errcheck
- gosimple
- godot
- ineffassign
- staticcheck
- typecheck
- unused

# extra linters
# - goconst
# - goerr113
# - gomnd
# - nonamedreturns
# - unparam
- bidichk
- bodyclose
- contextcheck
- copyloopvar
- decorder
- durationcheck
- errorlint
- exhaustive
- gofmt
- goimports
- gomodguard
- intrange
- misspell
- predeclared
- reassign
- whitespace
disable-all: true
fast: false

issues:
include:
- EXC0002 # should have a comment
- EXC0003 # test/Test ... consider calling this
- EXC0004 # govet
- EXC0005 # C-style breaks
5 changes: 5 additions & 0 deletions workflow-templates/go-linter.properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Go linter",
"description": "Run golangci-lint.",
"iconName": "octicon cpu"
}
18 changes: 18 additions & 0 deletions workflow-templates/go-linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Go linter

on:
push:
branches: [ $default-branch ]
paths-ignore:
- '**/*.sh'
- '**/*.md'
pull_request:
branches: [ $default-branch ]
types: [opened, synchronize]
paths-ignore:
- '**/*.sh'
- '**/*.md'

jobs:
lint:
uses: nspcc-dev/.github/.github/workflows/go-linter.yml@master

0 comments on commit 36dae73

Please sign in to comment.