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

Add golangci-lint #134

Merged
merged 6 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ jobs:
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- name: Lint
uses: golangci/golangci-lint-action@v3
with:
skip-cache: true
- name: test
uses: n8maninger/action-golang-test@v1
with:
Expand Down
163 changes: 163 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
# Based off of the example file at https://github.com/golangci/golangci-lint

# options for analysis running
run:
# default concurrency is a available CPU number
concurrency: 4

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

# exit code when at least one issue was found, default is 1
issues-exit-code: 1

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

# list of build tags, all linters use it. Default is empty list.
build-tags: []

# which dirs to skip: issues from them won't be reported;
# can use regexp here: generated.*, regexp is applied on full path;
# default value is empty list, but default dirs are skipped independently
# from this option's value (see skip-dirs-use-default).
skip-dirs:
- cover

# default is true. Enables skipping of directories:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs-use-default: true

# which files to skip: they will be analyzed, but issues from them
# won't be reported. Default value is empty list, but there is
# no need to include all autogenerated files, we confidently recognize
# autogenerated files. If it's not please let us know.
skip-files: []

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

# print lines of code with issue, default is true
print-issued-lines: true

# print linter name in the end of issue text, default is true
print-linter-name: true

# all available settings of specific linters
linters-settings:
## Enabled linters:
govet:
# report about shadowed variables
check-shadowing: false
disable-all: false

tagliatelle:
case:
rules:
json: goCamel
yaml: goCamel


gocritic:
# Which checks should be enabled; can't be combined with 'disabled-checks';
# See https://go-critic.github.io/overview#checks-overview
# To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run`
# By default list of stable checks is used.
enabled-checks:
- argOrder # Diagnostic options
- badCond
- caseOrder
- dupArg
- dupBranchBody
- dupCase
- dupSubExpr
- nilValReturn
- offBy1
- weakCond
- boolExprSimplify # Style options here and below.
- builtinShadow
- emptyFallthrough
- hexLiteral
- underef
- equalFold
revive:
ignore-generated-header: true
rules:
- name: blank-imports
disabled: false
- name: bool-literal-in-expr
disabled: false
- name: confusing-naming
disabled: false
- name: confusing-results
disabled: false
- name: constant-logical-expr
disabled: false
- name: context-as-argument
disabled: false
- name: exported
disabled: false
- name: errorf
disabled: false
- name: if-return
disabled: false
- name: indent-error-flow
disabled: false
- name: increment-decrement
disabled: false
- name: modifies-value-receiver
disabled: false
- name: optimize-operands-order
disabled: false
- name: range-val-in-closure
disabled: false
- name: struct-tag
disabled: false
- name: superfluous-else
disabled: false
- name: time-equal
disabled: false
- name: unexported-naming
disabled: false
- name: unexported-return
disabled: false
- name: unnecessary-stmt
disabled: false
- name: unreachable-code
disabled: false
- name: package-comments
disabled: true

linters:
disable-all: true
fast: false
enable:
- tagliatelle
- gocritic
- gofmt
- revive
- govet
- misspell
- typecheck
- whitespace

issues:
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-issues-per-linter: 0

# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 0

# List of regexps of issue texts to exclude, empty list by default.
# But independently from this option we use default exclude patterns,
# it can be disabled by `exclude-use-default: false`. To list all
# excluded by default patterns execute `golangci-lint run --help`
exclude: []

# Independently from option `exclude` we use default exclude patterns,
# it can be disabled by this option. To list all
# excluded by default patterns execute `golangci-lint run --help`.
# Default value for this option is true.
exclude-use-default: false
1 change: 0 additions & 1 deletion chain/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
func (vs versionedState) EncodeTo(e *types.Encoder) {
e.WriteUint8(2)
vs.State.EncodeTo(e)

}

func (vs *versionedState) DecodeFrom(d *types.Decoder) {
Expand Down Expand Up @@ -678,7 +677,7 @@
return nil, consensus.State{}, errors.New("cannot use Zen testnet database on mainnet")
} else if genesisBlock.ID() == zenGenesis.ID() && dbGenesis.ID == mainnetGenesis.ID() {
return nil, consensus.State{}, errors.New("cannot use mainnet database on Zen testnet")
} else {

Check warning on line 680 in chain/db.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.20)

indent-error-flow: if block ends with a return statement, so drop this else and outdent its block (revive)

Check warning on line 680 in chain/db.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.21)

indent-error-flow: if block ends with a return statement, so drop this else and outdent its block (revive)
return nil, consensus.State{}, errors.New("database previously initialized with different genesis block")
}
}
Expand Down
2 changes: 1 addition & 1 deletion chain/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ func (m *Manager) RecommendedFee() types.Currency {
Mul64(estPoolWeight).Div64(targetWeight).Mul64(estPoolWeight).
Div64(targetWeight).Mul64(estPoolWeight).Div64(targetWeight)

// finally, an absolute minumum fee: 1 SC / 100 KB
// finally, an absolute minimum fee: 1 SC / 100 KB
minFee := types.Siacoins(1).Div64(100e3)

// use the largest of all calculated fees
Expand Down
2 changes: 1 addition & 1 deletion consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type Network struct {
Height uint64 `json:"height"`
OakTime time.Duration `json:"oakTime"`
OakTarget types.BlockID `json:"oakTarget"`
} `json:"hardforkASIC"`
} `json:"hardforkAsic"`
chris124567 marked this conversation as resolved.
Show resolved Hide resolved
HardforkFoundation struct {
Height uint64 `json:"height"`
PrimaryAddress types.Address `json:"primaryAddress"`
Expand Down
2 changes: 1 addition & 1 deletion consensus/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ func TestValidateV2Block(t *testing.T) {
func(b *types.Block) {
txn := &b.V2.Transactions[0]
rev := testFces[0].V2FileContract
rev.RevisionNumber += 1
rev.RevisionNumber++
txn.FileContractRevisions = []types.V2FileContractRevision{{
Parent: testFces[0],
Revision: rev,
Expand Down
2 changes: 1 addition & 1 deletion types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ type TransactionID Hash256
// A ChainIndex pairs a block's height with its ID.
type ChainIndex struct {
Height uint64 `json:"height"`
ID BlockID `json:"ID"`
ID BlockID `json:"id"`
}

// A SiacoinOutput is the recipient of some of the siacoins spent in a
Expand Down
Loading