Skip to content

Commit

Permalink
Ground-up rework of a linter (#41)
Browse files Browse the repository at this point in the history
Add support of generics
Add support of nested structures
Rework regexp matching
Rework error message
  • Loading branch information
xobotyi authored Mar 23, 2023
1 parent 66e3548 commit 113a15f
Show file tree
Hide file tree
Showing 21 changed files with 1,079 additions and 655 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ jobs:
go-version: "1.20"
check-latest: true
- uses: actions/checkout@v3
- uses: golangci/golangci-lint-action@v3
- name: "Lint"
uses: golangci/golangci-lint-action@v3
with:
only-new-issues: true


test:
name: "Test"
Expand All @@ -33,12 +37,7 @@ jobs:
go-version: "1.20"
check-latest: true
- uses: actions/checkout@v3
- name: "Run tests"
run: go test -json ./... > test.json
- name: "Annotate tests"
uses: guyarb/golang-test-annotations@v0.6.0
with:
test-results: test.json
- uses: n8maninger/action-golang-test@v1

dependabot-merge:
name: "Dependabot auto-merge"
Expand Down
83 changes: 79 additions & 4 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,95 @@
run:
timeout: 10s
allow-parallel-runners: true

linters:
enable-all: true
disable:
- varnamelen
- nonamedreturns
- gofumpt
- depguard
- gci
- godox
- gofmt
- gofumpt
- goheader
- goimports
- varnamelen
- exhaustivestruct # deprecated
- scopelint # deprecated
- nonamedreturns # we're using named returns quite often
- errname # naming is too strict and is not observed in many places
- golint # deprecated
- importas # may be useful later, requires configuration
- interfacer # deprecated
- maligned # deprecated
- misspell # we have IDE speller
- scopelint # obsoleted, replaced by other linters
- govet # invoked by the goland internally
- tagliatelle # it isn't very handy to have such linter in a monorepo with a lot of different coding standards
- nlreturn # there is wsl linter what implements the same checks
- ifshort # deprecated in 1.48
- structcheck # deprecated 1.49
- varcheck # deprecated 1.49
- nosnakecase # deprecated 1.48
- deadcode # deprecated 1.49
- lll # disabled in favor of revive
- funlen # disabled in favor of revive
- gocognit # disabled in favor of revive
- cyclop # disabled in favor of revive
- gocyclo # disabled in favor of revive

linters-settings:
wsl:
force-case-trailing-whitespace: 1

revive:
enable-all-rules: true
confidence: 0.8
rules:
- name: comment-spacings
severity: warning
disabled: false
arguments: [ "nolint" ]
- name: function-length
severity: warning
disabled: false
arguments: [ 50, 0 ]
- name: function-result-limit
severity: warning
disabled: false
arguments: [ 3 ]
- name: cognitive-complexity
severity: warning
disabled: false
arguments: [ 20 ]
- name: cyclomatic
severity: warning
disabled: false
arguments: [ 10 ]
- name: line-length-limit
severity: warning
disabled: false
arguments: [ 110 ]
- name: argument-limit
severity: warning
disabled: false
arguments: [ 6 ]
# disabled rules
- name: max-public-structs # quite annoying rule
disabled: true
- name: banned-characters # we don't have banned chars
disabled: true
- name: file-header # we don't have a file headers
disabled: true
- name: flag-parameter # extremely annoying linter, it is absolutely okay to have boolean args
disabled: true
- name: struct-tag # false-positive on tags implemented by other linters
disabled: true
- name: unhandled-error # dont have proper exclusions list ToDo: make a PR
disabled: true
- name: add-constant # dont have exclusions list ToDo: make a PR
disabled: true
- name: empty-lines # it false-positives on one-liners ToDo: make a PR
disabled: true


issues:
max-issues-per-linter: 0
Expand Down
21 changes: 3 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,10 @@

`exhaustruct` is a golang analyzer that finds structures with uninitialized fields

#### The "why?"

There is a similar linter [exhaustivestruct](https://github.com/mbilski/exhaustivestruct), but it is abandoned
and not
optimal.

This linter can be called a successor of `exhaustivestruct`, and:

- it is at least **2.5+ times faster**, due to better algorithm;
- can receive `include` and/or `exclude` patterns;
- allows to mark fields as optional (not required to be filled on struct init), via field
tag `exhaustruct:"optional"`;
- expects received patterns to be RegExp, therefore this package is not api-compatible
with `exhaustivestruct`.

### Installation

```shell
go get -u github.com/GaijinEntertainment/go-exhaustruct/cmd/exhaustruct
go get -u github.com/GaijinEntertainment/go-exhaustruct/v3/cmd/exhaustruct
```

### Usage
Expand All @@ -42,9 +27,9 @@ exhaustruct [-flag] [package]
Flags:
-i value
Regular expression to match struct packages and names, can receive multiple flags
Regular expression to match structures, can receive multiple flags
-e value
Regular expression to exclude struct packages and names, can receive multiple flags
Regular expression to exclude structures, can receive multiple flags
```

### Example
Expand Down
Loading

0 comments on commit 113a15f

Please sign in to comment.