From 63cc295af54c8eedf00405937c601079e02da1ee Mon Sep 17 00:00:00 2001 From: Dmitrii Petrov Date: Sun, 14 Apr 2024 23:31:16 +0200 Subject: [PATCH] fix builds (#2) * parcer rules break go's understanding on the right usage * go build in ci demands no patch number in the version * go build - deps require 1.21 at least, let's make it 1.22 * golang-ci lint action * add golangci config with basic rules * cleanup or whitelist printlns --- .github/workflows/go.yml | 17 ++++++++++++++++- .golangci.yml | 20 ++++++++++++++++++++ cmd/mod.go | 1 + go.mod | 2 +- pkg/operations/parse.go | 2 ++ pkg/traverse/simpleyaml/simpleyaml.go | 5 ++--- 6 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 .golangci.yml diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 0065213..77dc851 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -19,10 +19,25 @@ 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 ./... - 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 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. 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/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 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` 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