Skip to content

Commit

Permalink
Merge pull request #40 from minamijoyo/use-golangci-instead-of-golint
Browse files Browse the repository at this point in the history
Use golangci-lint instead of golint
  • Loading branch information
minamijoyo authored Jan 6, 2022
2 parents 210a6a5 + 3190b51 commit 3dcce57
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 42 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: lint
permissions:
contents: read
on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.43.0
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
restore-keys: |
${{ runner.os }}-go-
- name: test
run: make check
run: make test
12 changes: 12 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# https://golangci-lint.run/usage/configuration/
linters:
disable-all: true
enable:
- errcheck
- goimports
- gosec
- gosimple
- govet
- ineffassign
- revive
- staticcheck
20 changes: 4 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
NAME := hcledit

ifndef GOBIN
GOBIN := $(shell echo "$${GOPATH%%:*}/bin")
endif

GOLINT := $(GOBIN)/golint

$(GOLINT): ; @go install golang.org/x/lint/golint

.DEFAULT_GOAL := build

.PHONY: deps
Expand All @@ -23,16 +15,12 @@ install: deps
go install

.PHONY: lint
lint: $(GOLINT)
golint $$(go list ./... | grep -v /vendor/)

.PHONY: vet
vet:
go vet ./...
lint:
golangci-lint run ./...

.PHONY: test
test: deps
test: build
go test ./...

.PHONY: check
check: lint vet test build
check: lint test
4 changes: 2 additions & 2 deletions cmd/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func newAttributeCmd() *cobra.Command {
Use: "attribute",
Short: "Edit attribute",
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
cmd.Help() // nolint: errcheck
},
}

Expand Down Expand Up @@ -147,7 +147,7 @@ Arguments:

flags := cmd.Flags()
flags.Bool("newline", false, "Append a new line before a new attribute")
viper.BindPFlag("attribute.append.newline", flags.Lookup("newline"))
viper.BindPFlag("attribute.append.newline", flags.Lookup("newline")) // nolint: errcheck

return cmd
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func newBlockCmd() *cobra.Command {
Use: "block",
Short: "Edit block",
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
cmd.Help() // nolint: errcheck
},
}

Expand Down Expand Up @@ -163,7 +163,7 @@ Arguments:

flags := cmd.Flags()
flags.Bool("newline", false, "Append a new line before a new child block")
viper.BindPFlag("block.append.newline", flags.Lookup("newline"))
viper.BindPFlag("block.append.newline", flags.Lookup("newline")) // nolint: errcheck

return cmd
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/body.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func newBodyCmd() *cobra.Command {
Use: "body",
Short: "Edit body",
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
cmd.Help() // nolint: errcheck
},
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ func init() {
flags := RootCmd.PersistentFlags()
flags.StringP("file", "f", "-", "A path of input file")
flags.BoolP("update", "u", false, "Update files in-place")
viper.BindPFlag("file", flags.Lookup("file"))
viper.BindPFlag("update", flags.Lookup("update"))
viper.BindPFlag("file", flags.Lookup("file")) // nolint: errcheck
viper.BindPFlag("update", flags.Lookup("update")) // nolint: errcheck

setDefaultStream(RootCmd)
}
Expand Down
2 changes: 1 addition & 1 deletion editor/filter_vertical_formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func trimLeadingNewLine(tokens hclwrite.Tokens) hclwrite.Tokens {
}
}

return tokens[begin:len(tokens)]
return tokens[begin:len(tokens)] // nolint: gosimple
}

// removeDuplicatedNewLine removes duplicated newlines
Expand Down
1 change: 1 addition & 0 deletions editor/test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func setupTestFile(t *testing.T, contents string) string {
path := f.Name()
t.Cleanup(func() { os.Remove(path) })

// nolint: gosec
if err := os.WriteFile(path, []byte(contents), 0644); err != nil {
t.Fatalf("failed to write test file: %s", err)
}
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
github.com/hashicorp/logutils v1.0.0
github.com/spf13/cobra v0.0.5
github.com/spf13/viper v1.3.2
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f
)

require (
Expand All @@ -29,7 +28,6 @@ require (
github.com/zclconf/go-cty v1.8.0 // indirect
golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82 // indirect
golang.org/x/text v0.3.5 // indirect
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/yaml.v2 v2.2.7 // indirect
)
7 changes: 0 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,11 @@ github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRK
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f h1:J5lckAjkw6qYlOZNj90mLYNTEKDvWeuc1yieZ8qUzUE=
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs=
golang.org/x/net v0.0.0-20180811021610-c39426892332/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand All @@ -102,9 +98,6 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f h1:kDxGY2VmgABOe55qheT/TFqUMtcTHnomIPS1iv3G4Ms=
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
2 changes: 1 addition & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestHCLEditMain(t *testing.T) {
// So that the second run is able to run main() and this first run can verify the exit status returned by that.
//
// This technique originates from https://talks.golang.org/2014/testing.slide#23.
cmd := exec.Command(os.Args[0], "-test.run=TestHCLEditMain")
cmd := exec.Command(os.Args[0], "-test.run=TestHCLEditMain") // nolint: gosec
cmd.Env = append(
cmd.Env,
os.Environ()...,
Expand Down
7 changes: 0 additions & 7 deletions tools.go

This file was deleted.

0 comments on commit 3dcce57

Please sign in to comment.