Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #113 from invopop/gobl-0.81
Browse files Browse the repository at this point in the history
Upgrading to GOBL 0.81
  • Loading branch information
cavalle authored Jul 18, 2024
2 parents c1064c9 + e5ed1ef commit 8b02d9a
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 16 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ jobs:

steps:
- name: Check out code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: "go.mod"
id: go

- name: Lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.55
version: v1.58
30 changes: 30 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
run:
timeout: "120s"

output:
formats:
- format: "colored-line-number"

linters:
enable:
- "gocyclo"
- "unconvert"
- "goimports"
- "govet"
#- "misspell" # doesn't handle multilanguage well
- "nakedret"
- "revive"
- "goconst"
- "unparam"
- "gofmt"
- "errname"
- "zerologlint"

linters-settings:
staticcheck:
# SAxxxx checks in https://staticcheck.io/docs/configuration/options/#checks
# Default: ["*"]
checks: ["all"]

issues:
exclude-use-default: false
2 changes: 1 addition & 1 deletion cmd/gobl/keygen.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func homedir() (string, error) {
return user.HomeDir, nil
}

func defaultKeyfile() (string,error) {
func defaultKeyfile() (string, error) {
return expandHome(defaultKeyFilename)
}

Expand Down
3 changes: 1 addition & 2 deletions cmd/gobl/main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// The gobl command provides a command-line interface to the GOBL library.

// Package main provides a command-line interface to the GOBL library.
package main

import (
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22
require (
github.com/google/go-cmp v0.6.0
github.com/imdario/mergo v0.3.16 // maintain this version, repo was moved to vanity URL which broke things
github.com/invopop/gobl v0.80.1
github.com/invopop/gobl v0.81.0
github.com/invopop/yaml v0.3.1
github.com/labstack/echo/v4 v4.12.0
github.com/magefile/mage v1.13.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/invopop/gobl v0.80.1 h1:f4ZGN/wcj8C4mM2etDGyMy4Axof3MojjVQkSp0UWdlQ=
github.com/invopop/gobl v0.80.1/go.mod h1:3ixShxX1jlOKo5Rw22HVQh3jXnK9AZa7Twcw7L92qn0=
github.com/invopop/gobl v0.80.2-0.20240717130326-6f551acf496e h1:uz7iSPjO714qsaRW3hszLblRhaHas7E/i3HZ2EnDyx0=
github.com/invopop/gobl v0.80.2-0.20240717130326-6f551acf496e/go.mod h1:3ixShxX1jlOKo5Rw22HVQh3jXnK9AZa7Twcw7L92qn0=
github.com/invopop/gobl v0.81.0 h1:bFzXkiNCdjXZcTrggsM8bzeddPDwAk/sUxinK7jaSlQ=
github.com/invopop/gobl v0.81.0/go.mod h1:3ixShxX1jlOKo5Rw22HVQh3jXnK9AZa7Twcw7L92qn0=
github.com/invopop/jsonschema v0.12.0 h1:6ovsNSuvn9wEQVOyc72aycBMVQFKz7cPdMJn10CvzRI=
github.com/invopop/jsonschema v0.12.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
github.com/invopop/validation v0.3.0 h1:o260kbjXzoBO/ypXDSSrCLL7SxEFUXBsX09YTE9AxZw=
Expand Down
2 changes: 2 additions & 0 deletions internal/build.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package internal contains all the base functionality for the GOBL CLI
package internal

import (
Expand All @@ -7,6 +8,7 @@ import (
"github.com/invopop/gobl/schema"
)

// BuildOptions are the options used for building and validating GOBL data.
type BuildOptions struct {
*ParseOptions
}
Expand Down
4 changes: 3 additions & 1 deletion internal/bulk.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type SignRequest struct {
Envelop bool `json:"envelop"`
}

// ValidateRequest is the payload for a validate request.
type ValidateRequest struct {
Data []byte `json:"data"`
}
Expand Down Expand Up @@ -116,6 +117,7 @@ type SchemaRequest struct {
Path string `json:"path"`
}

// RegimeRequest defines a body used to request the definition of a Tax Regime.
type RegimeRequest struct {
Code string `json:"code"`
}
Expand Down Expand Up @@ -155,7 +157,7 @@ func Bulk(ctx context.Context, opts *BulkOptions) <-chan *BulkResponse {
return resCh
}

func processRequest(ctx context.Context, req BulkRequest, seq int64, bulkOpts *BulkOptions) *BulkResponse {
func processRequest(ctx context.Context, req BulkRequest, seq int64, bulkOpts *BulkOptions) *BulkResponse { //nolint:gocyclo
marshal := json.Marshal
if req.Indent {
marshal = func(i interface{}) ([]byte, error) {
Expand Down
8 changes: 4 additions & 4 deletions internal/bulk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"gitlab.com/flimzy/testy"
)

func TestBulk(t *testing.T) {
func TestBulk(t *testing.T) { //nolint:gocyclo
type tt struct {
opts *BulkOptions
want []*BulkResponse
Expand Down Expand Up @@ -86,7 +86,7 @@ func TestBulk(t *testing.T) {
},
}
})
tests.Add("two verifications", func(t *testing.T) interface{} {
tests.Add("two verifications", func(_ *testing.T) interface{} {
req1, _ := json.Marshal(map[string]interface{}{
"action": "sleep",
"req_id": "abc",
Expand Down Expand Up @@ -656,7 +656,7 @@ func TestBulk(t *testing.T) {
{SeqID: 2, IsFinal: true},
},
})
tests.Add("schema", func(t *testing.T) interface{} {
tests.Add("schema", func(_ *testing.T) interface{} {
return tt{
opts: &BulkOptions{
In: strings.NewReader(`{"action":"schema","payload":{"path":"head/stamp"}}`),
Expand Down Expand Up @@ -698,7 +698,7 @@ func TestBulk(t *testing.T) {
},
}
})
tests.Add("regime", func(t *testing.T) interface{} {
tests.Add("regime", func(_ *testing.T) interface{} {
return tt{
opts: &BulkOptions{
In: strings.NewReader(`{"action":"regime","payload":{"code":"es"}}`),
Expand Down
1 change: 1 addition & 0 deletions internal/iotools/iotools.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package iotools adds some helps for reading data
package iotools

import (
Expand Down
2 changes: 1 addition & 1 deletion internal/sign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestSign(t *testing.T) {
},
}
})
tests.Add("invalid document", func(t *testing.T) interface{} {
tests.Add("invalid document", func(_ *testing.T) interface{} {
return tt{
opts: &SignOptions{
ParseOptions: &ParseOptions{
Expand Down
9 changes: 5 additions & 4 deletions internal/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/invopop/gobl/schema"
)

// FindType can be used to match a partial schema name with a complete schema ID.
func FindType(term string) schema.ID {
return findType(schema.Types(), term)
}
Expand All @@ -32,7 +33,7 @@ func findType(types map[reflect.Type]schema.ID, term string) schema.ID {
return ""
}

var cap = regexp.MustCompile("([A-Z])")
var singleCap = regexp.MustCompile("([A-Z])")
var allCaps = regexp.MustCompile("[A-Z]{2,}")

func toSchema(term string) string {
Expand All @@ -48,9 +49,9 @@ func toSchema(term string) string {
}
for _, match := range allCaps.FindAllString(term, -1) {
match = match[:len(match)-1]
new := strings.ToLower(match)
term = strings.Replace(term, match, new, 1)
n := strings.ToLower(match)
term = strings.Replace(term, match, n, 1)
}
term = cap.ReplaceAllString(term, "-${1}")
term = singleCap.ReplaceAllString(term, "-${1}")
return strings.ToLower(term)
}
1 change: 1 addition & 0 deletions wasm/serve/serve.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main is used to launch a demo site for the wasm.
package main

import (
Expand Down
1 change: 1 addition & 0 deletions wasm/wasm.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//go:build js

// Package main provides a WASM interface to GOBL.
package main

import (
Expand Down

0 comments on commit 8b02d9a

Please sign in to comment.