Skip to content

Commit

Permalink
feat: adding flake support
Browse files Browse the repository at this point in the history
  • Loading branch information
benjivesterby committed Oct 19, 2024
1 parent 0157ca7 commit e88e3ac
Show file tree
Hide file tree
Showing 7 changed files with 355 additions and 93 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
20 changes: 15 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
void
config.yaml

.direnv/
*cweb.log
*.tmp
.venv
external/

# outputs
output.txt
dist/

*.hosts
# build folders
bin/
ui/public/
ui/build/
ui/node_modules/

# Removing Vendor
vendor/
testdata/remote

.vscode/

Expand All @@ -24,6 +32,8 @@ testdata/remote
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
coverage.html
coverage
coverage.txt

# ignore keyfiles
*.crt
Expand Down
76 changes: 20 additions & 56 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
# Copyright (c) 2024 by SPYDER.
#
# This software is proprietary information of SPYDER.
# Unauthorized use, copying, modification, distribution, and/or
# disclosure is strictly prohibited, except as provided under the terms
# of the commercial license agreement you have entered into with
# SPYDER.
#
# For more details, see the LICENSE file in the root directory of this
# source code repository or contact SPYDER at [email protected].

run:
# Timeout for analysis, e.g. 30s, 5m.
# Default: 1m
timeout: 3m
skip-dirs:
- testdata


# This file contains only configs which differ from defaults.
Expand All @@ -23,6 +32,7 @@ linters-settings:
# Such cases aren't reported by default.
# Default: false
check-type-assertions: true
exclude-functions: []

exhaustive:
# Program elements to check for exhaustiveness.
Expand Down Expand Up @@ -60,7 +70,7 @@ linters-settings:
# Default: true
skipRecvDeref: false

gomnd:
mnd:
# List of function patterns to exclude from analysis.
# Values always ignored: `time.Date`,
# `strconv.FormatInt`, `strconv.FormatUint`, `strconv.FormatFloat`,
Expand Down Expand Up @@ -153,15 +163,13 @@ linters-settings:
linters:
disable-all: true
enable:
## enabled by default
- errcheck # checking for unchecked errors, these unchecked errors can be critical bugs in some cases
- gosimple # specializes in simplifying a code
- 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
- 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
Expand All @@ -170,8 +178,6 @@ linters:
- 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
- exportloopref # checks for pointers to enclosing loop variables
- forbidigo # forbids identifiers
Expand All @@ -184,7 +190,7 @@ linters:
- 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
- mnd # 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
Expand All @@ -209,66 +215,24 @@ linters:
- 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)
- testpackage # makes you use a separate _test package
#- 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
- usestdlibvars # detects the possibility to use variables/constants from the Go standard library
- wastedassign # finds wasted assignment statements
- whitespace # detects leading and trailing whitespace

## you may want to enable
#- decorder # checks declaration order and count of types, constants, variables and functions
#- exhaustruct # checks if all structure fields are initialized
#- gci # controls golang package import order and makes it always deterministic
#- godox # detects FIXME, TODO and other comment keywords
#- goheader # checks is file header matches to pattern
#- interfacebloat # checks the number of methods inside an interface
#- ireturn # accept interfaces, return concrete types
#- prealloc # [premature optimization, but can be used in some cases] finds slice declarations that could potentially be preallocated
#- varnamelen # [great idea, but too many false positives] checks that the length of a variable's name matches its scope
#- wrapcheck # checks that errors returned from external packages are wrapped

## disabled
#- containedctx # detects struct contained context.Context field
#- contextcheck # [too many false positives] checks the function whether use a non-inherited context
#- 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
#- 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
#- forcetypeassert # [replaced by errcheck] finds forced type assertions
#- 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
#- grouper # analyzes expression groups
#- importas # enforces consistent import aliases
#- maintidx # measures the maintainability index of each function
#- misspell # [useless] finds commonly misspelled English words in comments
#- 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
#- 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.
# Set to 0 to disable.
# Default: 3
max-same-issues: 50

exclude-dirs:
- testdata


exclude-rules:
- source: "^//\\s*go:generate\\s"
linters: [ lll ]
Expand All @@ -287,7 +251,7 @@ issues:
- gosec
- noctx
- wrapcheck
- gomnd
- mnd
- exportloopref
- gocyclo
- errcheck
Expand Down
66 changes: 34 additions & 32 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
# Copyright (c) 2024 by SPYDER.
#
# This software is proprietary information of SPYDER.
# Unauthorized use, copying, modification, distribution, and/or
# disclosure is strictly prohibited, except as provided under the terms
# of the commercial license agreement you have entered into with
# SPYDER.
#
# For more details, see the LICENSE file in the root directory of this
# source code repository or contact SPYDER at [email protected].

exclude: '^$'
fail_fast: true
repos:
#- repo: https://github.com/Yelp/detect-secrets
# rev: v1.2.0
# hooks:
# - id: detect-secrets
# name: Detect secrets
# language: python
# entry: detect-secrets-hook
# args: ['--baseline', '.secrets.baseline']
- repo: https://github.com/golangci/golangci-lint
rev: v1.52.2
hooks:
- id: golangci-lint
- repo: https://github.com/Bahjat/pre-commit-golang
rev: v1.0.3 # pragma: allowlist secret
hooks:
- id: go-unit-tests
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-json
- id: check-added-large-files
- id: pretty-format-json
- id: check-merge-conflict
- id: check-yaml
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.34.0
hooks:
- id: markdownlint-fix
- repo: https://github.com/koalaman/shellcheck-precommit
rev: v0.9.0
hooks:
- id: shellcheck
- repo: https://github.com/Yelp/detect-secrets
rev: v1.5.0
hooks:
- id: detect-secrets
name: Detect secrets
language: python
entry: detect-secrets-hook
args: [
'--baseline',
'.secrets.baseline',
]
- repo: https://github.com/sqlfluff/sqlfluff
rev: 3.2.3
hooks:
- id: sqlfluff-fix
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-json
- id: check-merge-conflict
- id: check-yaml
86 changes: 86 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
all: build tidy lint fmt test

#-------------------------------------------------------------------------
# Variables
# ------------------------------------------------------------------------
env=CGO_ENABLED=1

test: lint
CGO_ENABLED=1 go test -cover -failfast -race ./...

fuzz:
@fuzzTime=$${FUZZ_TIME:-10}; \
files=$$(grep -r --include='**_test.go' --files-with-matches 'func Fuzz' .); \
for file in $$files; do \
funcs=$$(grep -o 'func Fuzz\w*' $$file | sed 's/func //'); \
for func in $$funcs; do \
echo "Fuzzing $$func in $$file"; \
parentDir=$$(dirname $$file); \
go test $$parentDir -run=$$func -fuzz=$$func -fuzztime=$${fuzzTime}s; \
if [ $$? -ne 0 ]; then \
echo "Fuzzing $$func in $$file failed"; \
exit 1; \
fi; \
done; \
done

bench:
go test -bench=. -benchmem ./...

lint: tidy
golangci-lint run
pre-commit run --all-files

build: update tidy
$(env) go build ./...

release-dev: build-ci

upgrade:
pre-commit autoupdate
go get -u ./...

update:
git submodule update --recursive

fmt:
gofmt -s -w .

tidy: fmt
go mod tidy

clean:
rm -rf dist
rm -rf coverage

#-------------------------------------------------------------------------
# CI targets
#-------------------------------------------------------------------------
test-ci: tidy lint
CGO_ENABLED=1 go test \
-cover \
-covermode=atomic \
-coverprofile=coverage.txt \
-failfast \
-race ./...
make fuzz FUZZ_TIME=10

build-ci: test-ci
$(env) go build ./...

bench-ci: test-ci
go test -bench=. ./... | tee output.txt

release-ci: build-ci

#-------------------------------------------------------------------------
# Force targets
#-------------------------------------------------------------------------

FORCE:

#-------------------------------------------------------------------------
# Phony targets
#-------------------------------------------------------------------------

.PHONY: build test lint fuzz
Loading

0 comments on commit e88e3ac

Please sign in to comment.