Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to github.com/zeebo/xxh3 to fix Go Plugin build #60

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: '1.22'
go-version: '1.20.14'

- uses: golangci/golangci-lint-action@v6
with:
version: v1.61.0
args: --timeout=5m
version: v1.55.2
args: --timeout=5m -v

- name: Test
run: make test
Expand Down
138 changes: 57 additions & 81 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This code is licensed under the terms of the MIT license https://opensource.org/license/mit
# Copyright (c) 2021 Marat Reymers

## Golden config for golangci-lint v1.61.0
## Golden config for golangci-lint v1.55.2
#
# This is the best config for golangci-lint based on my experience and opinion.
# It is very strict, but not extremely strict.
Expand All @@ -11,6 +11,9 @@ run:
# Timeout for analysis, e.g. 30s, 5m.
# Default: 1m
timeout: 3m
tests: false
skip-dirs:
- rdt # skip generated code


# This file contains only configs which differ from defaults.
Expand Down Expand Up @@ -39,8 +42,7 @@ linters-settings:
- map

exhaustruct:
# List of regular expressions to exclude struct packages and their names from checks.
# Regular expressions must match complete canonical struct package/name/structname.
# List of regular expressions to exclude struct packages and names from check.
# Default: []
exclude:
# std libs
Expand Down Expand Up @@ -99,6 +101,25 @@ linters-settings:
# Default: true
skipRecvDeref: false

gomnd:
# List of function patterns to exclude from analysis.
# Values always ignored: `time.Date`,
# `strconv.FormatInt`, `strconv.FormatUint`, `strconv.FormatFloat`,
# `strconv.ParseInt`, `strconv.ParseUint`, `strconv.ParseFloat`.
# Default: []
ignored-functions:
- flag.Arg
- flag.Duration.*
- flag.Float.*
- flag.Int.*
- flag.Uint.*
- os.Chmod
- os.Mkdir.*
- os.OpenFile
- os.WriteFile
- prometheus.ExponentialBuckets.*
- prometheus.LinearBuckets

gomodguard:
blocked:
# List of blocked modules.
Expand All @@ -114,8 +135,8 @@ linters-settings:
reason: "satori's package is not maintained"
- github.com/gofrs/uuid:
recommendations:
- github.com/gofrs/uuid/v5
reason: "gofrs' package was not go module before v5"
- github.com/google/uuid
reason: "gofrs' package is not go module"

govet:
# Enable all analyzers.
Expand All @@ -133,31 +154,6 @@ linters-settings:
# Default: false
strict: true

inamedparam:
# Skips check for interface methods with only a single parameter.
# Default: false
skip-single-param: true

mnd:
# List of function patterns to exclude from analysis.
# Values always ignored: `time.Date`,
# `strconv.FormatInt`, `strconv.FormatUint`, `strconv.FormatFloat`,
# `strconv.ParseInt`, `strconv.ParseUint`, `strconv.ParseFloat`.
# Default: []
ignored-functions:
- args.Error
- flag.Arg
- flag.Duration.*
- flag.Float.*
- flag.Int.*
- flag.Uint.*
- os.Chmod
- os.Mkdir.*
- os.OpenFile
- os.WriteFile
- prometheus.ExponentialBuckets.*
- prometheus.LinearBuckets

nakedret:
# Make an issue if func has more lines of code than this setting, and it has naked returns.
# Default: 30
Expand All @@ -174,36 +170,12 @@ linters-settings:
# Default: false
require-specific: true

perfsprint:
# Optimizes into strings concatenation.
# Default: true
strconcat: false
errorf: false

rowserrcheck:
# database/sql is always checked
# Default: []
packages:
- github.com/jmoiron/sqlx

sloglint:
# Enforce not using global loggers.
# Values:
# - "": disabled
# - "all": report all global loggers
# - "default": report only the default slog logger
# https://github.com/go-simpler/sloglint?tab=readme-ov-file#no-global
# Default: ""
#no-global: "all"
# Enforce using methods that accept a context.
# Values:
# - "": disabled
# - "all": report all contextless calls
# - "scope": report only if a context exists in the scope of the outermost function
# https://github.com/go-simpler/sloglint?tab=readme-ov-file#context-only
# Default: ""
context: "scope"

tenv:
# The option `all` will run against whole test files (`_test.go`) regardless of method/function signatures.
# Otherwise, only methods that take `*testing.T`, `*testing.B`, and `testing.TB` as arguments are checked.
Expand All @@ -219,46 +191,49 @@ linters:
- govet # reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
- ineffassign # detects when assignments to existing variables are not used
- staticcheck # is a go vet on steroids, applying a ton of static analysis checks
- typecheck # like the front-end of a Go compiler, parses and type-checks Go code
#- typecheck # like the front-end of a Go compiler, parses and type-checks Go code
- unused # checks for unused constants, variables, functions and types
## disabled by default
- asasalint # checks for pass []any as any in variadic func(...any)
- asciicheck # checks that your code does not contain non-ASCII identifiers
- bidichk # checks for dangerous unicode character sequences
- bodyclose # checks whether HTTP response body is closed successfully
- canonicalheader # checks whether net/http.Header uses canonical header
- copyloopvar # detects places where loop variables are copied (Go 1.22+)
- cyclop # checks function and package cyclomatic complexity
- dupl # tool for code clone detection
- durationcheck # checks for two durations multiplied together
- errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error
- errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13
- execinquery # checks query string in Query function which reads your Go src files and warning it finds
- exhaustive # checks exhaustiveness of enum switch statements
- fatcontext # detects nested contexts in loops
- exportloopref # checks for pointers to enclosing loop variables
- forbidigo # forbids identifiers
- funlen # tool for detection of long functions
- gocheckcompilerdirectives # validates go compiler directive comments (//go:)
#- gochecknoglobals # checks that no global variables exist
- gochecknoinits # checks that no init functions are present in Go code
- gochecksumtype # checks exhaustiveness on Go "sum types"
- gocognit # computes and checks the cognitive complexity of functions
- goconst # finds repeated strings that could be replaced by a constant
- gocritic # provides diagnostics that check for bugs, performance and style issues
- gocyclo # computes and checks the cyclomatic complexity of functions
#- godot # checks if comments end in a period
- goimports # in addition to fixing imports, goimports also formats your code in the same style as gofmt
#- gomnd # detects magic numbers
- gomoddirectives # manages the use of 'replace', 'retract', and 'excludes' directives in go.mod
- gomodguard # allow and block lists linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations
- goprintffuncname # checks that printf-like functions are named with f at the end
- gosec # inspects source code for security problems
- intrange # finds places where for loops could make use of an integer range
- lll # reports long lines
#- lll # reports long lines
- loggercheck # checks key value pairs for common logger libraries (kitlog,klog,logr,zap)
- makezero # finds slice declarations with non-zero initial length
- mirror # reports wrong mirror patterns of bytes/strings usage
- musttag # enforces field tags in (un)marshaled structs
#- musttag # enforces field tags in (un)marshaled structs
- nakedret # finds naked returns in functions greater than a specified function length
- nestif # reports deeply nested if statements
- nilerr # finds the code that returns nil even if it checks that the error is not nil
- nilnil # checks that there is no simultaneous return of nil error and an invalid value
- noctx # finds sending http request without context.Context
- nolintlint # reports ill-formed or insufficient nolint directives
- nonamedreturns # reports all named returns
- nosprintfhostport # checks for misuse of Sprintf to construct a host with port in a URL
- perfsprint # checks that fmt.Sprintf can be replaced with a faster alternative
Expand All @@ -269,12 +244,12 @@ linters:
- revive # fast, configurable, extensible, flexible, and beautiful linter for Go, drop-in replacement of golint
- rowserrcheck # checks whether Err of rows is checked successfully
- sloglint # ensure consistent code style when using log/slog
- spancheck # checks for mistakes with OpenTelemetry/Census spans
- sqlclosecheck # checks that sql.Rows and sql.Stmt are closed
- stylecheck # is a replacement for golint
- tenv # detects using os.Setenv instead of t.Setenv since Go1.17
- testableexamples # checks if examples are testable (have an expected output)
- testifylint # checks usage of github.com/stretchr/testify
#- testpackage # makes you use a separate _test package
- tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes
- unconvert # removes unnecessary type conversions
- unparam # reports unused function parameters
Expand Down Expand Up @@ -304,30 +279,34 @@ linters:
#- depguard # [replaced by gomodguard] checks if package imports are in a list of acceptable packages
#- dogsled # checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
#- dupword # [useless without config] checks for duplicate words in the source code
#- err113 # [too strict] checks the errors handling expressions
#- errchkjson # [don't see profit + I'm against of omitting errors like in the first example https://github.com/breml/errchkjson] checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted
#- execinquery # [deprecated] checks query string in Query function which reads your Go src files and warning it finds
#- exportloopref # [not necessary from Go 1.22] checks for pointers to enclosing loop variables
#- forbidigo # forbids identifiers
#- forcetypeassert # [replaced by errcheck] finds forced type assertions
#- gochecknoglobals # checks that no global variables exist
#- godot # checks if comments end in a period
#- goerr113 # [too strict] checks the errors handling expressions
#- gofmt # [replaced by goimports] checks whether code was gofmt-ed
#- gofumpt # [replaced by goimports, gofumports is not available yet] checks whether code was gofumpt-ed
#- gosmopolitan # reports certain i18n/l10n anti-patterns in your Go codebase
#- grouper # analyzes expression groups
#- importas # enforces consistent import aliases
#- nolintlint # reports ill-formed or insufficient nolint directives, disable because breaks the rules of gofmt
#- maintidx # measures the maintainability index of each function
#- misspell # [useless] finds commonly misspelled English words in comments
#- mnd # detects magic numbers
#- nlreturn # [too strict and mostly code is not more readable] checks for a new line before return and branch statements to increase code clarity
#- paralleltest # [too many false positives] detects missing usage of t.Parallel() method in your Go test
#- tagliatelle # checks the struct tags
#- testpackage # makes you use a separate _test package
#- thelper # detects golang test helpers without t.Helper() call and checks the consistency of test helpers
#- wsl # [too strict and mostly code is not more readable] whitespace linter forces you to use empty lines

## deprecated
#- deadcode # [deprecated, replaced by unused] finds unused code
#- exhaustivestruct # [deprecated, replaced by exhaustruct] checks if all struct's fields are initialized
#- golint # [deprecated, replaced by revive] golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes
#- ifshort # [deprecated] checks that your code uses short syntax for if-statements whenever possible
#- interfacer # [deprecated] suggests narrower interface types
#- maligned # [deprecated, replaced by govet fieldalignment] detects Go structs that would take less memory if their fields were sorted
#- nosnakecase # [deprecated, replaced by revive var-naming] detects snake case of variable naming and function name
#- scopelint # [deprecated, replaced by exportloopref] checks for unpinned variables in go programs
#- structcheck # [deprecated, replaced by unused] finds unused struct fields
#- varcheck # [deprecated, replaced by unused] finds unused global variables and constants


issues:
# Maximum count of issues with the same text.
Expand All @@ -336,6 +315,12 @@ issues:
max-same-issues: 50

exclude-rules:
- path: resolve.go
linters:
- typecheck
- path: rdt_visitor.go
linters:
- typecheck
- source: "(noinspection|TODO)"
linters: [ godot ]
- source: "//noinspection"
Expand All @@ -348,13 +333,4 @@ issues:
- goconst
- gosec
- noctx
- wrapcheck
- gocognit
- lll
- revive
- staticcheck
- asasalint
- gocyclo
- errcheck
- cyclop
- nonamedreturns
- wrapcheck
15 changes: 8 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Directory containing the Makefile.
export PATH := $(GOBIN):$(PATH)

GO_VERISON = 1.20.14
GOLANGCI_LINT_VERSION = 1.55.2

.PHONY: all
all: lint cover

.PHONY: lint
lint:
@golangci-lint run ./...
@go$(GO_VERISON) run github.com/golangci/golangci-lint/cmd/golangci-lint@v$(GOLANGCI_LINT_VERSION) run ./...

.PHONY: test
test-unit:
Expand All @@ -15,7 +18,8 @@ test-unit:
# the coverage should be at least 80% for now, but it should be increased in the future to 90% and more
.PHONY: cover
test-cover:
@go test -coverprofile=cover.out.tmp -coverpkg=./... ./... \
@pkgs=$$(go list ./... | grep -v /Store/) \
go test -coverprofile=cover.out.tmp $${pkgs} -coverpkg=$${pkgs} \
&& cat cover.out.tmp | grep -v "rdtparser_base_visitor.go" > cover.out \
&& rm cover.out.tmp \
&& go tool cover -func=cover.out | grep total | awk '{print substr($$3, 1, length($$3)-1)}' | \
Expand All @@ -32,11 +36,8 @@ build: go-build
go-build:
@cd cmd/raml && go build -o ../../.build/raml

.PHONY: install
install: go-install

.PHONY: go-install
go-install:
@cd cmd/raml && \
go install -v ./... \
&& echo $$(go list -f '{{.Module.Path}}') has been installed to $$(go list -f '{{.Target}}') && true
go install golang.org/dl/go$(GO_VERISON)@latest
go$(GO_VERISON) download
2 changes: 1 addition & 1 deletion cmd/raml/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/acronis/go-raml/cmd/raml

go 1.23.0
go 1.22.6

require (
github.com/acronis/go-raml v0.14.0
Expand Down
4 changes: 2 additions & 2 deletions complex.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"regexp"
"strconv"

"github.com/cespare/xxhash"
orderedmap "github.com/wk8/go-ordered-map/v2"
"github.com/zeebo/xxh3"
"gopkg.in/yaml.v3"

"github.com/acronis/go-stacktrace"
Expand Down Expand Up @@ -77,7 +77,7 @@ func hashInterfaceFast(v interface{}) (uint64, error) {
}

// Use xxhash for fast hashing.
return xxhash.Sum64(data), nil
return xxh3.Hash(data), nil
}

func (s *ArrayShape) validate(v interface{}, ctxPath string) error {
Expand Down
13 changes: 9 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
module github.com/acronis/go-raml

go 1.20.6
go 1.20

require (
github.com/acronis/go-stacktrace v0.4.0
github.com/antlr4-go/antlr/v4 v4.13.0
github.com/cespare/xxhash v1.1.0
github.com/stretchr/testify v1.9.0
github.com/wk8/go-ordered-map/v2 v2.1.8
github.com/zeebo/xxh3 v1.0.2
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc // indirect
golang.org/x/sys v0.28.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
)
Loading
Loading