From 2daa55b7c64c7f5652a3eae260efd95e768089c7 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Thu, 18 Apr 2024 11:36:36 -0400 Subject: [PATCH] Update deps --- .github/workflows/test.yml | 101 ++++++------------- .golangci.yml | 202 ++++++++++++++++++++----------------- Makefile | 45 --------- go.sum | 0 password/generate.go | 15 +-- password/generate_test.go | 21 ++-- 6 files changed, 163 insertions(+), 221 deletions(-) delete mode 100644 Makefile delete mode 100644 go.sum diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 115f57b..c1efb7a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,93 +3,54 @@ name: Test on: push: branches: - - main + - main tags: - - '*' + - '*' pull_request: branches: - - main + - main jobs: lint: runs-on: 'ubuntu-latest' steps: - - uses: 'actions/checkout@v3' + - uses: 'actions/checkout@v4' - - uses: 'actions/setup-go@v3' - with: - go-version: '1.14' + - uses: 'actions/setup-go@v5' + with: + go-version: '1.14' - - uses: 'golangci/golangci-lint-action@v3' - with: - version: 'v1.50.1' - only-new-issues: true - skip-cache: true - skip-pkg-cache: true - skip-build-cache: true - args: >- - --enable=${{ join(fromJson('[ - "asciicheck", - "bidichk", - "bodyclose", - "containedctx", - "depguard", - "dogsled", - "errcheck", - "errchkjson", - "errname", - "errorlint", - "exhaustive", - "exportloopref", - "forcetypeassert", - "godot", - "gofumpt", - "goheader", - "goimports", - "gomodguard", - "goprintffuncname", - "gosec", - "gosimple", - "govet", - "ifshort", - "ineffassign", - "makezero", - "noctx", - "nolintlint", - "prealloc", - "predeclared", - "revive", - "sqlclosecheck", - "staticcheck", - "stylecheck", - "tenv", - "thelper", - "tparallel", - "typecheck", - "unconvert", - "unused", - "whitespace", - ]'), ',') }} - --max-issues-per-linter=0 - --max-same-issues=0 - --timeout=5m + - uses: 'golangci/golangci-lint-action@v4' + with: + version: 'v1.57.2' + only-new-issues: true + skip-cache: true test: strategy: matrix: platform: - - 'macos-latest' - - 'ubuntu-latest' - - 'windows-latest' + - 'macos-latest' + - 'ubuntu-latest' + - 'windows-latest' runs-on: '${{ matrix.platform }}' steps: - - uses: 'actions/checkout@v3' - - - uses: 'actions/setup-go@v3' - with: - go-version: '1.14' - - - run: 'make test-acc' + - uses: 'actions/checkout@v4' + + - uses: 'actions/setup-go@v5' + with: + go-version: '1.14' + + - run: |- + ls -alh + + go test \ + -count=1 \ + -race \ + -shuffle=on \ + -timeout=5m \ + -vet=all \ + ./... diff --git a/.golangci.yml b/.golangci.yml index 299b39a..55d7e55 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,9 +1,31 @@ +# Copyright 2023 The Authors (see AUTHORS file) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + run: # default: '1m' timeout: '5m' # default: [] - build-tags: [] + build-tags: + - 'all' + + # default: [] + exclude-dirs: + - 'third_party' + + # default: true + skip-dirs-use-default: false # default: '' modules-download-mode: 'readonly' @@ -13,100 +35,72 @@ run: linters: enable: - - 'asasalint' - - 'asciicheck' - - 'bidichk' - - 'bodyclose' - - 'containedctx' - - 'contextcheck' - - 'cyclop' - - 'decorder' - - 'depguard' - - 'dogsled' - - 'dupl' - - 'dupword' - - 'durationcheck' - - 'errcheck' - - 'errchkjson' - - 'errname' - - 'errorlint' - - 'execinquery' - - 'exhaustive' - - 'exhaustruct' - - 'exportloopref' - - 'forbidigo' - - 'forcetypeassert' - - 'funlen' - - 'gci' - - 'gochecknoglobals' - - 'gochecknoinits' - - 'gocognit' - - 'goconst' - - 'gocritic' - - 'gocyclo' - - 'godot' - - 'godox' - - 'goerr113' - - 'gofumpt' - - 'goheader' - - 'goimports' - - 'gomnd' - - 'gomoddirectives' - - 'gomodguard' - - 'goprintffuncname' - - 'gosec' - - 'gosimple' - - 'govet' - - 'grouper' - - 'importas' - - 'ineffassign' - - 'interfacebloat' - - 'ireturn' - - 'lll' - - 'loggercheck' - - 'maintidx' - - 'makezero' - - 'misspell' - - 'nakedret' - - 'nestif' - - 'nilerr' - - 'nilnil' - - 'nlreturn' - - 'noctx' - - 'nolintlint' - - 'nonamedreturns' - - 'nosprintfhostport' - - 'paralleltest' - - 'prealloc' - - 'predeclared' - - 'promlinter' - - 'reassign' - - 'revive' - - 'rowserrcheck' - - 'sqlclosecheck' - - 'staticcheck' - - 'stylecheck' - - 'tagliatelle' - - 'tenv' - - 'testableexamples' - - 'testpackage' - - 'thelper' - - 'tparallel' - - 'typecheck' - - 'unconvert' - - 'unparam' - - 'unused' - - 'usestdlibvars' - - 'varnamelen' - - 'wastedassign' - - 'whitespace' - - 'wrapcheck' - - 'wsl' + - 'asasalint' + - 'asciicheck' + - 'bidichk' + - 'bodyclose' + - 'containedctx' + - 'dupword' + - 'durationcheck' + - 'errcheck' + - 'errchkjson' + - 'errname' + - 'errorlint' + - 'execinquery' + - 'exhaustive' + - 'exportloopref' + - 'forcetypeassert' + - 'gci' + - 'gocheckcompilerdirectives' + - 'godot' + - 'gofmt' + - 'gofumpt' + - 'goheader' + - 'goimports' + - 'goprintffuncname' + - 'gosec' + - 'gosimple' + - 'govet' + - 'importas' + - 'ineffassign' + - 'loggercheck' + - 'makezero' + - 'mirror' + - 'misspell' + - 'nilerr' + - 'noctx' + - 'nolintlint' + - 'nosprintfhostport' + - 'paralleltest' + - 'prealloc' + - 'predeclared' + - 'protogetter' + - 'rowserrcheck' + - 'sloglint' + - 'spancheck' + - 'sqlclosecheck' + - 'staticcheck' + - 'stylecheck' + - 'tenv' + - 'thelper' + - 'typecheck' + - 'unconvert' + - 'unused' + - 'wastedassign' + - 'whitespace' + - 'wrapcheck' issues: # default: [] exclude: - - '^SA3000:' # staticcheck: not required in Go 11.4+ + - '^G102:' # gosec: we have to bind to all ifaces in Cloud Run services + + # default: [] + exclude-rules: + # Exclude test files from certain linters + - path: '_test.go' + linters: + - 'wrapcheck' # default: 50 max-issues-per-linter: 0 @@ -114,6 +108,30 @@ issues: # default: 3 max-same-issues: 0 + gci: + sections: + - 'standard' + - 'default' + - 'blank' + - 'dot' + + skip-generated: true + custom-order: true + + gofumpt: + # default: false + extra-rules: true + + sloglint: + # default: false + context-only: true + # default: false + static-msg: false + # default: '' (snake, kebab, camel, pascal) + key-naming-case: 'snake' + # default: false + args-on-sep-lines: true + severity: # default: '' - default-severity: error + default-severity: 'error' diff --git a/Makefile b/Makefile deleted file mode 100644 index 9533c5c..0000000 --- a/Makefile +++ /dev/null @@ -1,45 +0,0 @@ -VETTERS = "asmdecl,assign,atomic,bools,buildtag,cgocall,composites,copylocks,errorsas,httpresponse,loopclosure,lostcancel,nilfunc,printf,shift,stdmethods,structtag,tests,unmarshal,unreachable,unsafeptr,unusedresult" -GOFMT_FILES = $(shell go list -f '{{.Dir}}' ./... | grep -v '/pb') - -fmtcheck: - @command -v goimports > /dev/null 2>&1 || go get golang.org/x/tools/cmd/goimports - @CHANGES="$$(goimports -d $(GOFMT_FILES))"; \ - if [ -n "$${CHANGES}" ]; then \ - echo "Unformatted (run goimports -w .):\n\n$${CHANGES}\n\n"; \ - exit 1; \ - fi - @# Annoyingly, goimports does not support the simplify flag. - @CHANGES="$$(gofmt -s -d $(GOFMT_FILES))"; \ - if [ -n "$${CHANGES}" ]; then \ - echo "Unformatted (run gofmt -s -w .):\n\n$${CHANGES}\n\n"; \ - exit 1; \ - fi -.PHONY: fmtcheck - -spellcheck: - @command -v misspell > /dev/null 2>&1 || go get github.com/client9/misspell/cmd/misspell - @misspell -locale="US" -error -source="text" **/* -.PHONY: spellcheck - -staticcheck: - @command -v staticcheck > /dev/null 2>&1 || go get honnef.co/go/tools/cmd/staticcheck - @staticcheck -checks="all" -tests $(GOFMT_FILES) -.PHONY: staticcheck - -test: - @go test \ - -count=1 \ - -short \ - -timeout=5m \ - -vet="${VETTERS}" \ - ./... -.PHONY: test - -test-acc: - @go test \ - -count=1 \ - -race \ - -timeout=10m \ - -vet="${VETTERS}" \ - ./... -.PHONY: test-acc diff --git a/go.sum b/go.sum deleted file mode 100644 index e69de29..0000000 diff --git a/password/generate.go b/password/generate.go index 9956fbd..45c2247 100644 --- a/password/generate.go +++ b/password/generate.go @@ -1,11 +1,11 @@ // Package password provides a library for generating high-entropy random // password strings via the crypto/rand package. // -// res, err := Generate(64, 10, 10, false, false) -// if err != nil { -// log.Fatal(err) -// } -// log.Printf(res) +// res, err := Generate(64, 10, 10, false, false) +// if err != nil { +// log.Fatal(err) +// } +// log.Printf(res) // // Most functions are safe for concurrent use. package password @@ -13,6 +13,7 @@ package password import ( "crypto/rand" "errors" + "fmt" "io" "math/big" "strings" @@ -245,7 +246,7 @@ func randomInsert(reader io.Reader, s, val string) (string, error) { n, err := rand.Int(reader, big.NewInt(int64(len(s)+1))) if err != nil { - return "", err + return "", fmt.Errorf("failed to generate random integer: %w", err) } i := n.Int64() return s[0:i] + val + s[i:], nil @@ -255,7 +256,7 @@ func randomInsert(reader io.Reader, s, val string) (string, error) { func randomElement(reader io.Reader, s string) (string, error) { n, err := rand.Int(reader, big.NewInt(int64(len(s)))) if err != nil { - return "", err + return "", fmt.Errorf("failed to generate random integer: %w", err) } return string(s[n.Int64()]), nil } diff --git a/password/generate_test.go b/password/generate_test.go index a3d9338..0ea2519 100644 --- a/password/generate_test.go +++ b/password/generate_test.go @@ -1,6 +1,7 @@ package password import ( + "errors" "io" "strings" "sync/atomic" @@ -25,6 +26,8 @@ func (mr *MockReader) Read(data []byte) (int, error) { } func testHasDuplicates(tb testing.TB, s string) bool { + tb.Helper() + found := make(map[rune]struct{}, len(s)) for _, ch := range s { if _, ok := found[ch]; ok { @@ -36,7 +39,7 @@ func testHasDuplicates(tb testing.TB, s string) bool { } func testGeneratorGenerate(t *testing.T, reader io.Reader) { - t.Parallel() + t.Helper() gen, err := NewGenerator(nil) if reader != nil { @@ -49,11 +52,11 @@ func testGeneratorGenerate(t *testing.T, reader io.Reader) { t.Run("exceeds_length", func(t *testing.T) { t.Parallel() - if _, err := gen.Generate(0, 1, 0, false, false); err != ErrExceedsTotalLength { + if _, err := gen.Generate(0, 1, 0, false, false); !errors.Is(err, ErrExceedsTotalLength) { t.Errorf("expected %q to be %q", err, ErrExceedsTotalLength) } - if _, err := gen.Generate(0, 0, 1, false, false); err != ErrExceedsTotalLength { + if _, err := gen.Generate(0, 0, 1, false, false); !errors.Is(err, ErrExceedsTotalLength) { t.Errorf("expected %q to be %q", err, ErrExceedsTotalLength) } }) @@ -61,7 +64,7 @@ func testGeneratorGenerate(t *testing.T, reader io.Reader) { t.Run("exceeds_letters_available", func(t *testing.T) { t.Parallel() - if _, err := gen.Generate(1000, 0, 0, false, false); err != ErrLettersExceedsAvailable { + if _, err := gen.Generate(1000, 0, 0, false, false); !errors.Is(err, ErrLettersExceedsAvailable) { t.Errorf("expected %q to be %q", err, ErrLettersExceedsAvailable) } }) @@ -69,7 +72,7 @@ func testGeneratorGenerate(t *testing.T, reader io.Reader) { t.Run("exceeds_digits_available", func(t *testing.T) { t.Parallel() - if _, err := gen.Generate(52, 11, 0, false, false); err != ErrDigitsExceedsAvailable { + if _, err := gen.Generate(52, 11, 0, false, false); !errors.Is(err, ErrDigitsExceedsAvailable) { t.Errorf("expected %q to be %q", err, ErrDigitsExceedsAvailable) } }) @@ -77,7 +80,7 @@ func testGeneratorGenerate(t *testing.T, reader io.Reader) { t.Run("exceeds_symbols_available", func(t *testing.T) { t.Parallel() - if _, err := gen.Generate(52, 0, 31, false, false); err != ErrSymbolsExceedsAvailable { + if _, err := gen.Generate(52, 0, 31, false, false); !errors.Is(err, ErrSymbolsExceedsAvailable) { t.Errorf("expected %q to be %q", err, ErrSymbolsExceedsAvailable) } }) @@ -127,15 +130,17 @@ func testGeneratorGenerate(t *testing.T, reader io.Reader) { } func TestGeneratorGenerate(t *testing.T) { + t.Parallel() testGeneratorGenerate(t, nil) } func TestGenerator_Reader_Generate(t *testing.T) { + t.Parallel() testGeneratorGenerate(t, &MockReader{}) } func testGeneratorGenerateCustom(t *testing.T, reader io.Reader) { - t.Parallel() + t.Helper() gen, err := NewGenerator(&GeneratorInput{ LowerLetters: "abcde", @@ -173,9 +178,11 @@ func testGeneratorGenerateCustom(t *testing.T, reader io.Reader) { } func TestGeneratorGenerateCustom(t *testing.T) { + t.Parallel() testGeneratorGenerateCustom(t, nil) } func TestGenerator_Reader_Generate_Custom(t *testing.T) { + t.Parallel() testGeneratorGenerateCustom(t, &MockReader{}) }