From 19023e4981ac561807cbae8c74752d46cf2355ae Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Sun, 14 Apr 2024 23:07:36 +0200 Subject: [PATCH 1/6] parcer rules break go's understanding on the right usage --- pkg/operations/parse.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/operations/parse.go b/pkg/operations/parse.go index 3a73d33..fad236a 100644 --- a/pkg/operations/parse.go +++ b/pkg/operations/parse.go @@ -33,12 +33,14 @@ var operations = map[string]Operation{ "del": Delete, } +//nolint:govet type Call struct { Name string `@Ident` Path []PathElement `"(" (@Ident | @String ) ( "." (@Ident | @String) )*` Arguments []Argument `( "," @@ )* ")"` } +//nolint:govet type Argument struct { Float *float64 ` @Float` Int *int `| @Int` From 9a3a99472537366a75904e3a6ba507134d083731 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Sun, 14 Apr 2024 23:08:18 +0200 Subject: [PATCH 2/6] go build in ci demands no patch number in the version --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 07df89f..4aa9f48 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/can3p/sackmesser -go 1.22.0 +go 1.22 require ( github.com/alecthomas/assert/v2 v2.8.1 From b7a4f211a8175d5360a506d4ea386e2b905a2a97 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Sun, 14 Apr 2024 23:14:37 +0200 Subject: [PATCH 3/6] go build - deps require 1.21 at least, let's make it 1.22 --- .github/workflows/go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 0065213..7768af8 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -19,7 +19,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: '1.20' + go-version: '1.22' - name: Build run: go build -v ./... From 2fa1528d83fb2f4238449ec8e086486fc40139fd Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Sun, 14 Apr 2024 23:15:23 +0200 Subject: [PATCH 4/6] golang-ci lint action --- .github/workflows/go.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 7768af8..77dc851 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -26,3 +26,18 @@ jobs: - name: Test run: go test -v ./... + + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: '1.22' + cache: false + - name: golangci-lint + uses: golangci/golangci-lint-action@v4 + with: + # from: https://github.com/marketplace/actions/run-golangci-lint + version: latest From d0eb9d7504e2af4029cbd828889f6f4e288b8cc7 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Sun, 14 Apr 2024 23:27:26 +0200 Subject: [PATCH 5/6] add golangci config with basic rules --- .golangci.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .golangci.yml diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..3cec408 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,20 @@ +linters: + enable: + - errcheck + - gosimple + - govet + - ineffassign + - staticcheck + - unused + - forbidigo + +linters-settings: + forbidigo: + # Forbid the following identifiers (list of regexp). + # Default: ["^(fmt\\.Print(|f|ln)|print|println)$"] + forbid: + # Builtin function: + - ^print.*$ + # Optional message that gets included in error reports. + - p: ^fmt\.Print.*$ + msg: Do not commit print statements. From e09ce32ad39ebe1c51cea27a99bce28923795b41 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Sun, 14 Apr 2024 23:30:19 +0200 Subject: [PATCH 6/6] cleanup or whitelist printlns --- cmd/mod.go | 1 + pkg/traverse/simpleyaml/simpleyaml.go | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/mod.go b/cmd/mod.go index f681bd9..3a5009a 100644 --- a/cmd/mod.go +++ b/cmd/mod.go @@ -86,6 +86,7 @@ func ModCommand() *cobra.Command { return err } + // nolint:forbidigo fmt.Print(string(out)) return nil diff --git a/pkg/traverse/simpleyaml/simpleyaml.go b/pkg/traverse/simpleyaml/simpleyaml.go index c0bea73..ad64313 100644 --- a/pkg/traverse/simpleyaml/simpleyaml.go +++ b/pkg/traverse/simpleyaml/simpleyaml.go @@ -2,10 +2,11 @@ package simpleyaml import ( "fmt" - "gopkg.in/yaml.v3" "reflect" "strconv" + "gopkg.in/yaml.v3" + "github.com/can3p/sackmesser/pkg/traverse/types" ) @@ -165,8 +166,6 @@ func (n *jnode) NodeType() types.NodeType { return types.NodeTypeNull } - fmt.Println(n.vType.Kind()) - switch n.vType.Kind() { case reflect.Bool: return types.NodeTypeBool