Skip to content

Commit c4aa242

Browse files
committed
chore: Switch to GitHub Actions
* Switch to GitHub Actions * Add golangci-lint and fix issues * Bump version * Bump dependencies
1 parent 5974059 commit c4aa242

File tree

8 files changed

+153
-41
lines changed

8 files changed

+153
-41
lines changed

.github/workflows/go.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
name: CI
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
golangci-lint:
9+
name: golangci-lint
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/setup-go@v3
13+
with:
14+
go-version: '1.20'
15+
- uses: actions/checkout@v3
16+
- uses: golangci/golangci-lint-action@v3
17+
18+
tests:
19+
# run after golangci-lint action to not produce duplicated errors
20+
name: tests
21+
needs: golangci-lint
22+
strategy:
23+
matrix:
24+
go:
25+
- '1.20'
26+
os:
27+
- ubuntu-latest
28+
runs-on: ${{ matrix.os }}
29+
steps:
30+
- name: Install Go
31+
uses: actions/setup-go@v3
32+
with:
33+
go-version: ${{ matrix.go }}
34+
35+
- name: Checkout code
36+
uses: actions/checkout@v2
37+
38+
- name: Setup cache
39+
uses: actions/cache@v3
40+
with:
41+
path: ~/go/pkg/mod
42+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
43+
restore-keys: ${{ runner.os }}-go-
44+
45+
- name: Test code
46+
run: go test -race -v ./...

.golangci.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
run:
3+
deadline: 1m
4+
issues-exit-code: 1
5+
tests: true
6+
skip-dirs:
7+
- vendor$
8+
9+
output:
10+
format: colored-line-number
11+
print-issued-lines: false
12+
13+
linters-settings:
14+
gocognit:
15+
min-complexity: 10
16+
17+
depguard:
18+
list-type: blacklist
19+
include-go-root: false
20+
packages:
21+
- github.com/davecgh/go-spew/spew
22+
23+
misspell:
24+
locale: US
25+
26+
gocritic:
27+
# Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run`
28+
# to see all tags and checks. Empty list by default. See
29+
# https://github.com/go-critic/go-critic#usage -> section "Tags".
30+
enabled-tags:
31+
- diagnostic
32+
- experimental
33+
- opinionated
34+
- performance
35+
- style
36+
37+
linters:
38+
enable-all: true
39+
disable:
40+
- cyclop
41+
- deadcode
42+
- dupl
43+
- dupword
44+
- exhaustivestruct
45+
- exhaustruct
46+
- forbidigo
47+
- funlen
48+
- gci
49+
- gocognit
50+
- gocyclo
51+
- godox
52+
- golint
53+
- gomnd
54+
- ifshort
55+
- interfacer
56+
- lll
57+
- maintidx
58+
- maligned
59+
- nakedret
60+
- nestif
61+
- nlreturn
62+
- nosnakecase
63+
- paralleltest
64+
- prealloc
65+
- scopelint
66+
- structcheck
67+
- testpackage
68+
- varcheck
69+
- varnamelen
70+
fast: false
71+
72+
73+
issues:
74+
exclude-use-default: true
75+
max-issues-per-linter: 0
76+
max-same-issues: 0
77+
78+
# vim: set sw=2 ts=2 et:

.travis.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![forthebadge](https://forthebadge.com/images/badges/made-with-go.svg)](https://forthebadge.com)
44
[![forthebadge](https://forthebadge.com/images/badges/built-with-love.svg)](https://forthebadge.com)
55

6-
[![Build Status](https://travis-ci.org/bombsimon/wsl.svg?branch=master)](https://travis-ci.org/bombsimon/wsl)
6+
[![GitHub Actions](https://github.com/bombsimon/wsl/actions/workflows/go.yml/badge.svg)](https://github.com/bombsimon/wsl/actions/workflows/go.yml)
77
[![Coverage Status](https://coveralls.io/repos/github/bombsimon/wsl/badge.svg?branch=master)](https://coveralls.io/github/bombsimon/wsl?branch=master)
88

99
WSL is a linter that enforces a very **non scientific** vision of how to make

cmd/wsl/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/bombsimon/wsl/v3"
1111
)
1212

13-
// nolint: gocognit
1413
func main() {
1514
var (
1615
args []string

go.mod

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
module github.com/bombsimon/wsl/v3
22

3-
go 1.12
3+
go 1.19
4+
5+
require github.com/stretchr/testify v1.8.1
46

57
require (
68
github.com/davecgh/go-spew v1.1.1 // indirect
79
github.com/kr/text v0.2.0 // indirect
810
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
9-
github.com/stretchr/testify v1.5.1
11+
github.com/pmezard/go-difflib v1.0.0 // indirect
1012
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
11-
gopkg.in/yaml.v2 v2.2.8 // indirect
13+
gopkg.in/yaml.v2 v2.4.0 // indirect
14+
gopkg.in/yaml.v3 v3.0.1 // indirect
1215
)

go.sum

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLA
1313
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1414
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
1515
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
16+
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
17+
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
1618
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
1719
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
20+
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
21+
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
22+
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
23+
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
1824
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
1925
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2026
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
@@ -23,3 +29,8 @@ gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
2329
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
2430
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
2531
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
32+
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
33+
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
34+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
35+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
36+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

wsl.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import (
55
"go/ast"
66
"go/parser"
77
"go/token"
8-
"io/ioutil"
8+
"os"
99
"reflect"
1010
"strings"
1111
)
1212

13-
// Error reason strings
13+
// Error reason strings.
1414
const (
1515
reasonMustCuddleErrCheck = "if statements that check an error must be cuddled with the statement that assigned the error"
1616
reasonOnlyCuddleIfWithAssign = "if statements should only be cuddled with assignments"
@@ -44,7 +44,7 @@ const (
4444
reasonShortDeclNotExclusive = "short declaration should cuddle only with other short declarations"
4545
)
4646

47-
// Warning strings
47+
// Warning strings.
4848
const (
4949
warnTypeNotImplement = "type not implemented"
5050
warnStmtNotImplemented = "stmt type not implemented"
@@ -176,7 +176,7 @@ type Configuration struct {
176176
ForceExclusiveShortDeclarations bool
177177
}
178178

179-
// DefaultConfig returns default configuration
179+
// DefaultConfig returns default configuration.
180180
func DefaultConfig() Configuration {
181181
return Configuration{
182182
StrictAppend: true,
@@ -216,6 +216,8 @@ type Processor struct {
216216
}
217217

218218
// NewProcessor will create a Processor.
219+
//
220+
//nolint:gocritic // It's fine to copy config struct
219221
func NewProcessorWithConfig(cfg Configuration) *Processor {
220222
return &Processor{
221223
result: []Result{},
@@ -230,10 +232,11 @@ func NewProcessor() *Processor {
230232

231233
// ProcessFiles takes a string slice with file names (full paths) and lints
232234
// them.
233-
// nolint: gocritic
235+
//
236+
//nolint:gocritic // Don't want named returns
234237
func (p *Processor) ProcessFiles(filenames []string) ([]Result, []string) {
235238
for _, filename := range filenames {
236-
data, err := ioutil.ReadFile(filename)
239+
data, err := os.ReadFile(filename)
237240
if err != nil {
238241
panic(err)
239242
}
@@ -291,7 +294,6 @@ func (p *Processor) parseBlockBody(ident *ast.Ident, block *ast.BlockStmt) {
291294

292295
// parseBlockStatements will parse all the statements found in the body of a
293296
// node. A list of Result is returned.
294-
// nolint: gocognit
295297
func (p *Processor) parseBlockStatements(statements []ast.Stmt) {
296298
for i, stmt := range statements {
297299
// Start by checking if this statement is another block (other than if,
@@ -396,8 +398,7 @@ func (p *Processor) parseBlockStatements(statements []ast.Stmt) {
396398
// t.X = true
397399
// return t
398400
// }
399-
// nolint: gocritic
400-
if i == len(statements)-1 && i == 1 {
401+
if len(statements) == 2 && i == 1 {
401402
if p.nodeEnd(stmt)-p.nodeStart(previousStatement) <= 2 {
402403
return true
403404
}
@@ -1019,7 +1020,6 @@ func atLeastOneInListsMatch(listOne, listTwo []string) bool {
10191020
// findLeadingAndTrailingWhitespaces will find leading and trailing whitespaces
10201021
// in a node. The method takes comments in consideration which will make the
10211022
// parser more gentle.
1022-
// nolint: gocognit
10231023
func (p *Processor) findLeadingAndTrailingWhitespaces(ident *ast.Ident, stmt, nextStatement ast.Node) {
10241024
var (
10251025
allowedLinesBeforeFirstStatement = 1
@@ -1111,7 +1111,7 @@ func (p *Processor) findLeadingAndTrailingWhitespaces(ident *ast.Ident, stmt, ne
11111111
if seenCommentGroups > 1 {
11121112
allowedLinesBeforeFirstStatement += seenCommentGroups - 1
11131113
} else if seenCommentGroups == 1 {
1114-
allowedLinesBeforeFirstStatement += 1
1114+
allowedLinesBeforeFirstStatement++
11151115
}
11161116
}
11171117

0 commit comments

Comments
 (0)