From 05ed4eb281b2caee69324b674db85d0709e6b955 Mon Sep 17 00:00:00 2001 From: andrey Date: Wed, 24 Dec 2025 00:12:33 +0300 Subject: [PATCH] add workflow --- .gitea/workflows/goaction.yml | 26 +++++++++++++ .golangci.yml | 70 +++++++++++++++++++++-------------- README.md | 4 ++ size.go | 3 +- size_text_test.go | 2 +- 5 files changed, 75 insertions(+), 30 deletions(-) create mode 100644 .gitea/workflows/goaction.yml diff --git a/.gitea/workflows/goaction.yml b/.gitea/workflows/goaction.yml new file mode 100644 index 0000000..7f7abe9 --- /dev/null +++ b/.gitea/workflows/goaction.yml @@ -0,0 +1,26 @@ +name: Go Action + +on: [push, pull_request] + +jobs: + goaction: + runs-on: ubuntu-latest # Use a Gitea Actions runner label + steps: + - name: Check out repository code + uses: actions/checkout@v4 # Action to clone the repo + + - name: Set up Go + uses: actions/setup-go@v5 # Action to install a specific Go version + with: + go-version: '1.25.5' # Specify your required Go version + + - name: Run golangci-lint + uses: golangci/golangci-lint-action@v8 # Use the golangci-lint action + with: + version: v2.7.2 # Specify the linter version + # Optional: additional arguments + args: --verbose + + - name: Run go test + run: go test ./... + diff --git a/.golangci.yml b/.golangci.yml index fe51531..8a97458 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,4 +1,14 @@ -linters-settings: +version: "2" +linters: + default: all + disable: + - wsl + - recvcheck + - gochecknoglobals + - ireturn + - mnd + - nolintlint + settings: dupl: threshold: 100 funlen: @@ -9,14 +19,10 @@ linters-settings: min-occurrences: 2 gocyclo: min-complexity: 15 - golint: - min-confidence: 0 lll: line-length: 140 - maligned: - suggest-new: true misspell: - locale: US + locale: US varnamelen: min-name-length: 2 ignore-decls: @@ -26,25 +32,33 @@ linters-settings: - i int - b bytes.Buffer - h Handle - -linters: - enable-all: true - disable: - - gochecknoglobals - - ireturn - - mnd - - nolintlint - # deprecated - - gomnd - - exportloopref - - execinquery - -issues: - # Excluding configuration per-path, per-linter, per-text and per-source - exclude-rules: - - path: _test\.go - linters: - - gochecknoglobals - - depguard - - gosec - - errchkjson + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + rules: + - linters: + - depguard + - errchkjson + - gochecknoglobals + - gosec + path: _test\.go + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gci + - gofmt + - gofumpt + - goimports + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/README.md b/README.md index eb25085..7b62ce7 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,6 @@ # bytesize +![Build Status](https://gitoa.ru/go-4devs/bytesize/actions/workflows/goaction.yml/badge.svg) +[![Go Report Card](https://goreportcard.com/badge/gitoa.ru/go-4devs/bytesize)](https://goreportcard.com/report/gitoa.ru/go-4devs/bytesize) +[![GoDoc](https://godoc.org/gitoa.ru/go-4devs/bytesize?status.svg)](http://godoc.org/gitoa.ru/go-4devs/bytesize) + diff --git a/size.go b/size.go index 48c8834..fa7351a 100644 --- a/size.go +++ b/size.go @@ -86,7 +86,7 @@ func Parse(in string) (Size, error) { var err error // The next character must be [0-9.] - if !(in[0] == '.' || '0' <= in[0] && in[0] <= '9') { + if in[0] != '.' && ('0' > in[0] || in[0] > '9') { return 0, fmt.Errorf("%w %q", ErrInvalidSize, orig) } @@ -245,6 +245,7 @@ func leadingInt[bytes []byte | string](in bytes) (uint64, bytes, error) { func (s Size) String() string { var arr [32]byte + n := s.format(&arr) return string(arr[n:]) diff --git a/size_text_test.go b/size_text_test.go index 176e170..2ec2265 100644 --- a/size_text_test.go +++ b/size_text_test.go @@ -44,8 +44,8 @@ func TestUnmarshalText(t *testing.T) { for _, tc := range marshalTextTests { var data bytesize.Size - err := json.Unmarshal([]byte(tc.expect), &data) + err := json.Unmarshal([]byte(tc.expect), &data) if err != nil { t.Errorf("json.Unmarshal(%q) = _, err:%q", tc.in, err) } else if data != tc.in { -- 2.49.1