Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Golangci-lint #224

Merged
merged 9 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,27 @@ jobs:
fail-fast: false
matrix:
include:
- language: go
build-mode: autobuild
- language: go
build-mode: autobuild

steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Checkout repository
uses: actions/checkout@v4
- uses: ./.github/actions/setup-go
with:
go-version: 1.22
- run: rustup update
- uses: stellar/actions/rust-cache@main
- run: make build-libpreflight

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
name: Linters
name: Go
on:
push:
branches:
- main
branches: [ main, release/** ]
pull_request:

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
pull-requests: read
# Optional: allow write access to checks to allow the action to annotate code in the PR.
checks: write

jobs:
golangci:
golangci-lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # version v3.0.2
with:
fetch-depth: 0 # required for new-from-rev option in .golangci.yml

- name: Setup GO
uses: actions/setup-go@268d8c0ca0432bb2cf416faae41297df9d262d7f # version v3.3.0
with:
go-version: '>=1.22.1'

- uses: stellar/actions/rust-cache@main
- name: Build libpreflight
run: |
rustup update
Expand All @@ -31,8 +34,7 @@ jobs:
- name: Run golangci-lint
uses: golangci/golangci-lint-action@a4f60bb28d35aeee14e6880718e0c85ff1882e64 # version v6.0.1
with:
version: v1.52.2 # this is the golangci-lint version
args: --issues-exit-code=0 # exit without errors for now - won't fail the build
version: v1.59.1 # this is the golangci-lint version
github-token: ${{ secrets.GITHUB_TOKEN }}
2opremio marked this conversation as resolved.
Show resolved Hide resolved
only-new-issues: true

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/required_status_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ jobs:
with:
filter-workflow-names: |
Dependency sanity checker*
Linters*
Go*
Rust*
Soroban RPC*
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: stellar/actions/rust-cache@main
- run: rustup update
- uses: stellar/actions/rust-cache@main
- run: make rust-check
- run: make rust-test
14 changes: 5 additions & 9 deletions .github/workflows/soroban-rpc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
with:
go-version: ${{ matrix.go }}
- run: rustup update
- uses: stellar/actions/rust-cache@main
- run: make build-libpreflight
- run: go test -race -cover -timeout 25m -v ./cmd/soroban-rpc/...

Expand Down Expand Up @@ -81,9 +82,8 @@ jobs:
- run: |
rustup target add ${{ matrix.rust_target }}
rustup update

- name: Build libpreflight
run: make build-libpreflight
- uses: stellar/actions/rust-cache@main
- run: make build-libpreflight
env:
CARGO_BUILD_TARGET: ${{ matrix.rust_target }}

Expand Down Expand Up @@ -132,8 +132,6 @@ jobs:
docker pull "$PROTOCOL_${{ matrix.protocol-version }}_CORE_DOCKER_IMG"
echo SOROBAN_RPC_INTEGRATION_TESTS_DOCKER_IMG="$PROTOCOL_${{ matrix.protocol-version }}_CORE_DOCKER_IMG" >> $GITHUB_ENV

- uses: stellar/actions/rust-cache@main

- name: Install Captive Core
shell: bash
run: |
Expand Down Expand Up @@ -176,10 +174,8 @@ jobs:
docker-compose version

- run: rustup update

- name: Build libpreflight
shell: bash
run: make build-libpreflight
- uses: stellar/actions/rust-cache@main
- run: make build-libpreflight

- name: Run Soroban RPC Integration Tests
run: |
Expand Down
205 changes: 103 additions & 102 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,122 +1,123 @@
linters-settings:
depguard:
dupl:
threshold: 100

funlen:
lines: 100
statements: 50
goconst:
min-len: 2
min-occurrences: 3
gocritic:
2opremio marked this conversation as resolved.
Show resolved Hide resolved
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- whyNoLint
gocyclo:
min-complexity: 15
goimports:
local-prefixes: github.com/golangci/golangci-lint
gomnd:
# don't include the "operation" and "assign"
checks:
- argument
- case
- condition
- return
ignored-numbers:
- '0'
- '1'
- '2'
- '3'
ignored-functions:
- strings.SplitN

govet:
check-shadowing: true
settings:
printf:
funcs:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
lll:
line-length: 140
misspell:
locale: US
nolintlint:
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped

gci:
# Section configuration to compare against.
# Section names are case-insensitive and may contain parameters in ().
# The default order of sections is `standard > default > custom > blank > dot > alias > localmodule`,
# If `custom-order` is `true`, it follows the order of `sections` option.
# Default: ["standard", "default"]
sections:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- prefix(github.com/stellar/) # Custom section: groups all imports with the specified Prefix.
- localmodule # Local module section: contains all local packages. This section is not present unless explicitly enabled.
skip-generated: false
# Enable custom order of sections.
# If `true`, make the section order the same as the order of `sections`.
# Default: false
custom-order: true

dogsled:
# Checks assignments with too many blank identifiers.
# Default: 2
max-blank-identifiers: 3

cyclop:
# The maximal code complexity to report.
# Default: 10
max-complexity: 15

wrapcheck:
# An array of strings that specify substrings of signatures to ignore.
# If this set, it will override the default set of ignored signatures.
# See https://github.com/tomarrell/wrapcheck#configuration for more information.
# Default: [".Errorf(", "errors.New(", "errors.Unwrap(", "errors.Join(", ".Wrap(", ".Wrapf(", ".WithMessage(", ".WithMessagef(", ".WithStack("]
ignoreSigs:
- .Errorf(
- errors.New(
- errors.Unwrap(
- errors.Join(
- .Wrap(
- .Wrapf(
- .WithMessage(
- .WithMessagef(
- .WithStack(
# An array of strings that specify regular expressions of signatures to ignore.
# Default: []
ignoreSigRegexps:
- \.New.*Error\(
# An array of strings that specify globs of packages to ignore.
# Default: []
ignorePackageGlobs:
- encoding/*
- github.com/pkg/*
- github.com/stellar/*
# An array of strings that specify regular expressions of interfaces to ignore.
# Default: []
ignoreInterfaceRegexps:
- ^(?i)c(?-i)ach(ing|e)

testifylint:
enable-all: true
disable:
# TODO: try to enable it
- go-require

forbidigo:
# Forbid the following identifiers (list of regexp).
# Default: ["^(fmt\\.Print(|f|ln)|print|println)$"]
forbid:
- p: "^(fmt\\.Print(|f|ln)|print|println)$"
msg: Do not commit debug print statements (in tests use t.Log()).
- p: "^.*$"
pkg: "^github.com/stellar/go/support/errors$"
msg: Do not use stellar/go/support/errors, use the standard 'errors' package and fmt.Errorf().
exclude-godoc-examples: false
analyze-types: true

linters:
disable-all: true
enable:
- bodyclose
enable-all: true
disable:
- gomnd
- execinquery
- depguard
- dogsled
- dupl
- errcheck
- exportloopref
#- funlen
- gochecknoinits
- goconst
#- gocritic
#- gocyclo
- gofmt
- goimports
#- gomnd
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
#- lll
- misspell
- nakedret
- noctx
- nolintlint
- staticcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- whitespace

# don't enable:
# - asciicheck
# - scopelint
# - gochecknoglobals
# - gocognit
# - godot
# - godox
# - goerr113
# - interfacer
# - maligned
# - nestif
# - prealloc
# - testpackage
# - revive
# - wsl
- nlreturn
- godox
# exhaustruct: enforcing exhaustive fields is useful in some cases, but there are
# too many legitimate default field values in Go
- exhaustruct
# err113: Enforcing errors.Is() is useful but cannot be enabled in isolation
- err113
- thelper
- wsl
- wrapcheck
- testpackage
# TODO: I didn't manage to make it accept short parameter names
- varnamelen
# TODO: consider enabling it later on
- ireturn
- godot
presets: [ ]
fast: false

issues:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
- path: _test\.go
linters:
- govet
- gosec
- path: cmd/soroban-rpc/internal/integrationtest/infrastructure/
linters:
- gosec

run:
timeout: 5m
skip-dirs:
- docs
- vendor
timeout: 10m
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ clean:
build-soroban-rpc: build-libpreflight
go build -ldflags="${GOLDFLAGS}" ${MACOS_MIN_VER} -o soroban-rpc -trimpath -v ./cmd/soroban-rpc

go-check-changes:
golangci-lint run ./... --new-from-rev $$(git rev-parse HEAD)
go-check-branch:
golangci-lint run ./... --new-from-rev $$(git rev-parse origin/main)

go-check:
golangci-lint run ./...
Expand Down
Loading
Loading