Skip to content

Commit

Permalink
Switch to golangci-lint for code linting (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdk committed Sep 11, 2019
1 parent ad7e11a commit 5f08d2f
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 21 deletions.
29 changes: 19 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
version: 2.1
jobs:
lint:
docker:
- image: circleci/golang:1.11.5
working_directory: /go/src/github.com/joshdk/go-junit
steps:
- checkout
- run:
name: Install tools
command: go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
- run:
name: Lint Go code
command: golangci-lint run

test:
docker:
- image: circleci/golang:1.11.5
working_directory: /go/src/github.com/joshdk/go-junit
steps:
- checkout
- run:
name: Install build tools
command: |
go get -u github.com/alecthomas/gometalinter
go get -u github.com/jstemmer/go-junit-report
gometalinter --install
mkdir test-results
- run:
name: Lint Go code
command: gometalinter --vendor
name: Install tools
command: go get -u github.com/jstemmer/go-junit-report
- run:
name: Test Go code
command: go test -v 2>&1 | tee test-results/report.log
command: |
mkdir -p test-results
go test -v 2>&1 | tee test-results/report.log
- run:
name: Generate test report
command: cat test-results/report.log | go-junit-report -go-version $GOLANG_VERSION > test-results/report.xml
Expand All @@ -30,4 +38,5 @@ workflows:
version: 2
build:
jobs:
- lint
- test
12 changes: 12 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
linters:
enable-all: true
disable:
- lll

issues:
exclude:
# Triggered by table tests calling t.Run. See
# https://github.com/kyoh86/scopelint/issues/4 for more information.
- Using the variable on range scope `test` in function literal
# Triggered by long table tests.
- Function 'Test\w+' is too long
3 changes: 1 addition & 2 deletions ingest.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ func ingestProperties(root xmlNode) map[string]string {
props := make(map[string]string, len(root.Nodes))

for _, node := range root.Nodes {
switch node.XMLName.Local {
case "property":
if node.XMLName.Local == "property" {
name := node.Attr("name")
value := node.Attr("value")
props[name] = value
Expand Down
4 changes: 2 additions & 2 deletions ingesters.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func IngestDir(directory string) ([]Suite, error) {
// IngestFiles will parse the given XML files and return a slice of all
// contained JUnit test suite definitions.
func IngestFiles(filenames []string) ([]Suite, error) {
var all []Suite
var all = make([]Suite, 0)

for _, filename := range filenames {
suites, err := IngestFile(filename)
Expand Down Expand Up @@ -68,7 +68,7 @@ func IngestFile(filename string) ([]Suite, error) {
func Ingest(data []byte) ([]Suite, error) {
var (
suiteChan = make(chan Suite)
suites []Suite
suites = make([]Suite, 0)
)

nodes, err := parse(data)
Expand Down
4 changes: 1 addition & 3 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

package junit

import (
"encoding/xml"
)
import "encoding/xml"

type xmlNode struct {
XMLName xml.Name
Expand Down
1 change: 0 additions & 1 deletion parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ func extractContent(data []byte) ([]byte, error) {
data = data[3:]
mode = 0
}

}

return output, nil
Expand Down
4 changes: 1 addition & 3 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

package junit

import (
"time"
)
import "time"

// Status represents the result of a single a JUnit testcase. Indicates if a
// testcase was run, and if it was successful.
Expand Down

0 comments on commit 5f08d2f

Please sign in to comment.