Skip to content

Commit

Permalink
Linting and versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
bombsimon committed Jan 16, 2025
1 parent 4110971 commit 33486f2
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 69 deletions.
43 changes: 21 additions & 22 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ jobs:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.20'
- uses: actions/checkout@v3
- uses: golangci/golangci-lint-action@v3
go-version: stable
- uses: golangci/golangci-lint-action@v6
with:
version: v1.62.2

tests:
# run after golangci-lint action to not produce duplicated errors
Expand All @@ -22,40 +24,37 @@ jobs:
strategy:
matrix:
go:
- '1.20'
- oldstable
- stable
os:
- ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}

- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup cache
uses: actions/cache@v3
- name: Install Go
uses: actions/setup-go@v5
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-
go-version: ${{ matrix.go }}

- name: Test code
run: go test -race -v ./...

- name: Run
run: go run ./cmd/wsl/ ./...

coverage:
runs-on: ubuntu-latest
steps:
- name: Install Go
- name: Checkout code
if: success()
uses: actions/setup-go@v3
with:
go-version: '1.20'
uses: actions/checkout@v4

- name: Checkout code
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: stable

- name: Calc coverage
run: |
Expand Down
35 changes: 13 additions & 22 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
---
run:
deadline: 1m
timeout: 1m
issues-exit-code: 1
tests: true
skip-dirs:
- vendor$

output:
format: colored-line-number
print-issued-lines: false
sort-results: true
formats:
- format: colored-line-number

linters-settings:
gocognit:
min-complexity: 10

depguard:
list-type: blacklist
include-go-root: false
packages:
- github.com/davecgh/go-spew/spew
rules:
main:
deny:
- pkg: "github.com/davecgh/go-spew/spew"
desc: not allowed

misspell:
locale: US
Expand All @@ -38,44 +39,34 @@ linters:
enable-all: true
disable:
- cyclop
- deadcode
- depguard
- dupl
- dupword
- exhaustivestruct
- err113
- exhaustruct
- exportloopref
- forbidigo
- funlen
- gci
- gocognit
- gocyclo
- godox
- golint
- gomnd
- ifshort
- interfacer
- mnd
- lll
- maintidx
- maligned
- nakedret
- nestif
- nlreturn
- nosnakecase
- paralleltest
- prealloc
- rowserrcheck
- scopelint
- structcheck
- testpackage
- varcheck
- tparallel
- varnamelen
- wastedassign
fast: false


issues:
exclude-use-default: true
max-issues-per-linter: 0
max-same-issues: 0

# vim: set sw=2 ts=2 et:
3 changes: 2 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package wsl

import (
"errors"
"fmt"
"strings"
)
Expand Down Expand Up @@ -80,7 +81,7 @@ func (c *Configuration) Update(
disable []string,
) error {
if enableAll && disableAll {
return fmt.Errorf("can't use both `enable-all` and `disable-all`")
return errors.New("can't use both `enable-all` and `disable-all`")
}

if enableAll {
Expand Down
6 changes: 2 additions & 4 deletions cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var ErrCursourOutObFounds = errors.New("out of bounds")
// }
//
// idents will be a map containing [a, b, c, d] and first identifiers will be
// [[a, b], [c]]
// [[a, b], [c]].
type Cursor struct {
currentIdx int
statements []ast.Stmt
Expand Down Expand Up @@ -65,9 +65,7 @@ func (c *Cursor) Merge(otherCursor *Cursor) {
if len(c.firstIdents) == 0 {
c.firstIdents = append(c.firstIdents, otherFirstIdents)
} else {
for _, v := range otherFirstIdents {
c.firstIdents[0] = append(c.firstIdents[0], v)
}
c.firstIdents[0] = append(c.firstIdents[0], otherFirstIdents...)
}
}

Expand Down
11 changes: 6 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
module github.com/bombsimon/wsl/v4

go 1.19
go 1.23

require golang.org/x/tools v0.19.0
require (
github.com/davecgh/go-spew v1.1.1
github.com/stretchr/testify v1.9.0
golang.org/x/tools v0.19.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.9.0 // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/sys v0.18.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
12 changes: 3 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic=
golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/tools v0.19.0 h1:tfGCXNR1OsFG+sVdLAitlpjAvD/I6dHDKnYrpEZUHkw=
golang.org/x/tools v0.19.0/go.mod h1:qoJWxmGSIBmAeriMx19ogtrEPrGtDbPK634QFIcLAhc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
12 changes: 6 additions & 6 deletions wsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ func (w *WSL) Run() {
}
}

func (w *WSL) CheckCuddling(stmt ast.Node, cursor *Cursor, blockCursor *Cursor, maxAllowedStatements int) {
func (w *WSL) CheckCuddling(stmt ast.Node, cursor, blockCursor *Cursor, maxAllowedStatements int) {
w.checkCuddlingWithDecl(stmt, cursor, blockCursor, maxAllowedStatements, true)
}

func (w *WSL) CheckCuddlingNoDecl(stmt ast.Node, cursor *Cursor, blockCursor *Cursor, maxAllowedStatements int) {
func (w *WSL) CheckCuddlingNoDecl(stmt ast.Node, cursor, blockCursor *Cursor, maxAllowedStatements int) {
w.checkCuddlingWithDecl(stmt, cursor, blockCursor, maxAllowedStatements, false)
}

Expand Down Expand Up @@ -127,7 +127,7 @@ func (w *WSL) checkCuddlingWithDecl(
// FEATURE: Allow identifiers used first in block. Configurable to allow
// multiple levels.
if !w.Config.AllowWholeBlock && w.Config.AllowFirstInBlock {
for i := 0; i < w.Config.FirstInBlockMaxDepth; i++ {
for i := range w.Config.FirstInBlockMaxDepth {
if i < len(blockCursor.firstIdents) {
firstIntersect := identIntersection(
previousIdents,
Expand Down Expand Up @@ -682,9 +682,9 @@ func (w *WSL) CheckBlockLeadingNewline(body *ast.BlockStmt) {
w.CheckLeadingNewline(body.Lbrace, body.List, comments)
}

func (w *WSL) CheckCaseLeadingNewline(case_ *ast.CaseClause) {
comments := ast.NewCommentMap(w.Fset, case_, w.File.Comments)
w.CheckLeadingNewline(case_.Colon, case_.Body, comments)
func (w *WSL) CheckCaseLeadingNewline(caseClause *ast.CaseClause) {
comments := ast.NewCommentMap(w.Fset, caseClause, w.File.Comments)
w.CheckLeadingNewline(caseClause.Colon, caseClause.Body, comments)
}

func (w *WSL) CheckLeadingNewline(startPos token.Pos, body []ast.Stmt, comments ast.CommentMap) {
Expand Down

0 comments on commit 33486f2

Please sign in to comment.