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

chore: Switch to GitHub Actions #117

Merged
merged 2 commits into from
Feb 5, 2023
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
75 changes: 75 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
name: CI
on:
push:
pull_request:

jobs:
golangci-lint:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: '1.20'
- uses: actions/checkout@v3
- uses: golangci/golangci-lint-action@v3

tests:
# run after golangci-lint action to not produce duplicated errors
name: tests
needs: golangci-lint
strategy:
matrix:
go:
- '1.20'
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

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

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

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

- name: Checkout code
uses: actions/checkout@v3

- name: Calc coverage
run: |
export PATH=$PATH:$(go env GOPATH)/bin
go test -v -covermode=count -coverprofile=coverage.out

- name: Convert coverage to lcov
uses: jandelgado/[email protected]
with:
infile: coverage.out
outfile: coverage.lcov

- name: Coveralls
uses: coverallsapp/[email protected]
with:
github-token: ${{ secrets.github_token }}
path-to-lcov: coverage.lcov
78 changes: 78 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
run:
deadline: 1m
issues-exit-code: 1
tests: true
skip-dirs:
- vendor$

output:
format: colored-line-number
print-issued-lines: false

linters-settings:
gocognit:
min-complexity: 10

depguard:
list-type: blacklist
include-go-root: false
packages:
- github.com/davecgh/go-spew/spew

misspell:
locale: US

gocritic:
# Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run`
# to see all tags and checks. Empty list by default. See
# https://github.com/go-critic/go-critic#usage -> section "Tags".
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style

linters:
enable-all: true
disable:
- cyclop
- deadcode
- dupl
- dupword
- exhaustivestruct
- exhaustruct
- forbidigo
- funlen
- gci
- gocognit
- gocyclo
- godox
- golint
- gomnd
- ifshort
- interfacer
- lll
- maintidx
- maligned
- nakedret
- nestif
- nlreturn
- nosnakecase
- paralleltest
- prealloc
- scopelint
- structcheck
- testpackage
- varcheck
- varnamelen
fast: false


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

# vim: set sw=2 ts=2 et:
25 changes: 0 additions & 25 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![forthebadge](https://forthebadge.com/images/badges/made-with-go.svg)](https://forthebadge.com)
[![forthebadge](https://forthebadge.com/images/badges/built-with-love.svg)](https://forthebadge.com)

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

WSL is a linter that enforces a very **non scientific** vision of how to make
Expand Down
1 change: 0 additions & 1 deletion cmd/wsl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/bombsimon/wsl/v3"
)

// nolint: gocognit
func main() {
var (
args []string
Expand Down
9 changes: 6 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
module github.com/bombsimon/wsl/v3

go 1.12
go 1.19

require github.com/stretchr/testify v1.8.1

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/stretchr/testify v1.5.1
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLA
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
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/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
Expand All @@ -23,3 +29,8 @@ gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
22 changes: 11 additions & 11 deletions wsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"go/ast"
"go/parser"
"go/token"
"io/ioutil"
"os"
"reflect"
"strings"
)

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

// Warning strings
// Warning strings.
const (
warnTypeNotImplement = "type not implemented"
warnStmtNotImplemented = "stmt type not implemented"
Expand Down Expand Up @@ -176,7 +176,7 @@ type Configuration struct {
ForceExclusiveShortDeclarations bool
}

// DefaultConfig returns default configuration
// DefaultConfig returns default configuration.
func DefaultConfig() Configuration {
return Configuration{
StrictAppend: true,
Expand Down Expand Up @@ -216,6 +216,8 @@ type Processor struct {
}

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

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

// parseBlockStatements will parse all the statements found in the body of a
// node. A list of Result is returned.
// nolint: gocognit
func (p *Processor) parseBlockStatements(statements []ast.Stmt) {
for i, stmt := range statements {
// Start by checking if this statement is another block (other than if,
Expand Down Expand Up @@ -396,8 +398,7 @@ func (p *Processor) parseBlockStatements(statements []ast.Stmt) {
// t.X = true
// return t
// }
// nolint: gocritic
if i == len(statements)-1 && i == 1 {
if len(statements) == 2 && i == 1 {
if p.nodeEnd(stmt)-p.nodeStart(previousStatement) <= 2 {
return true
}
Expand Down Expand Up @@ -1019,7 +1020,6 @@ func atLeastOneInListsMatch(listOne, listTwo []string) bool {
// findLeadingAndTrailingWhitespaces will find leading and trailing whitespaces
// in a node. The method takes comments in consideration which will make the
// parser more gentle.
// nolint: gocognit
func (p *Processor) findLeadingAndTrailingWhitespaces(ident *ast.Ident, stmt, nextStatement ast.Node) {
var (
allowedLinesBeforeFirstStatement = 1
Expand Down Expand Up @@ -1111,7 +1111,7 @@ func (p *Processor) findLeadingAndTrailingWhitespaces(ident *ast.Ident, stmt, ne
if seenCommentGroups > 1 {
allowedLinesBeforeFirstStatement += seenCommentGroups - 1
} else if seenCommentGroups == 1 {
allowedLinesBeforeFirstStatement += 1
allowedLinesBeforeFirstStatement++
}
}

Expand Down