The Workflows in this repository named go-lint*.yml are for linting and code analysis for Go-based back-end projects.
A set of important linting facilities are configured by default. The project can also configure additional relevant facilities as explained in the following Configuration and other sections.
The project can decide and enforce how strict to be with Go code formatting.
Refer to example workflows and configuration at https://github.com/folio-org/mod-reporting
(Refer to the main README-go for the build and deployment facilities.)
Create a .github/workflows directory in the root of the module repository, and add a file named go-lint.yml with the following content.
The filename is not important -- it can be anything.
name: Go lint central workflow
on:
push:
branches: ['*']
paths:
- '**.go'
- 'go.*'
- 'src/.errcheck-exclude'
- '**/.golangci.yml'
- '**/staticcheck.conf'
- '.github/workflows/go-lint.yml'
workflow_dispatch:
jobs:
go-lint:
uses: folio-org/.github/.github/workflows/go-lint.yml@v1
with:
errcheck-excludes-file: 'src/.errcheck-exclude'
golangci-config-file: 'src/.golangci.yml'The Workflow will operate on any branch. It is only triggered on changes to one of the listed "paths".
There are two configuration variables, both optional.
errcheck-excludes-file -- The path to a file containing a list of functions to be excluded with the "errcheck" facility. See notes in the following errcheck section.
golangci-config-file -- The path to a configuration file for the "golangci-lint" facility. The default path is a top-level .golangci.yml file (which is automatically discovered). This variable enables specification of an alternative path. See notes in the following golangci-lint section.
The centralised go-lint.yml Workflow has separate jobs, each described in the following sections.
Each job will report a summary of detected issues to the "Annotations" section of the Workflow run Summary output, and more information in the output of its respective "Run" step.
Reports unchecked errors.
The Workflow go-lint-errcheck.yml
Documentation:
As noted in the previous Configuration section, an optional "excludes" file can be provided.
Reports unreachable functions.
The Workflow go-lint-deadcode.yml
Documentation:
Vulnerability management.
The Workflow go-lint-govulncheck.yml
Documentation:
This tool utilises the Go language version specified in the project's ./go.mod file. If the project uses an older version of Go then this tool will be reporting vulnerabilities in the standard libraries, which have probably been fixed in the current Go language version.
It also reports vulnerabilities in functions of dependencies that are utilised by the project code.
The Workflow go-lint-staticcheck.yml
Documentation:
The default staticcheck.conf configuration files can be utilised to specify various checks to be excluded or non-default ones to also be included, etc.
Refer to the staticcheck documentation for Configuration files.
Runs various linters in parallel.
The Workflow go-lint-golangci.yml
Documentation:
The linters Enabled by default are
gosimple and
govet and
ineffassign and
unused and
gosec.
(The other normal defaults errcheck and staticcheck are disabled here because our 'go-lint' runs them as separate jobs.)
As noted in the previous Configuration section, a default optional configuration file is automatically discovered at the top-level path to .golangci.yml file. An optional variable can be used to specify an alternative path to a "configuration" file.
If the project wants to also use golangci as part of local linting, then there might be a need to utilise a different configuration file, e.g. a .golangci-local.yml file.
If needed then the configuration file can be used to provide various configuration parameters for the enabled linters. Refer to the golangci-lint Configuration documentation.
Refer to the list of all available linters and their configuration options.
As a basic example, the additional linter "whitespace" can be enabled (and if needed then additional configuration linters-settings):
linters:
enable:
- whitespace
The output from golangci-lint is verbose by default. This additional detail can be silenced via the project configuration file:
output:
print-issued-lines: false
The project can decide and enforce how strict to be with Go code formatting.
Use a local Makefile rule to do: go fmt ./...
Enable gofmt via the configuration file for golangci-lint.
Or be more stict by enabling gofumpt.
The top-level go.mod file is consulted for the Go version to be used.