Skip to content

Commit

Permalink
Merge pull request #7 from na4ma4/force-method
Browse files Browse the repository at this point in the history
add Force method
  • Loading branch information
na4ma4 authored May 30, 2024
2 parents 684cefe + a99f6ba commit e568759
Show file tree
Hide file tree
Showing 14 changed files with 367 additions and 66 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ jobs:
unit-test:
name: "Unit Test"
uses: na4ma4/actions/.github/workflows/unit-test.yml@main
secrets: inherit

goreleaser:
name: "Goreleaser"
if: startsWith(github.ref, 'refs/tags/v')
needs:
- unit-test
uses: na4ma4/actions/.github/workflows/goreleaser.yml@main
secrets:
token: ${{ secrets.GO_RELEASER_GITHUB_TOKEN }}
secrets: inherit
145 changes: 107 additions & 38 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# This code is licensed under the terms of the MIT license.
# 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.53.3
## Golden config for golangci-lint v1.58.2
#
# This is the best config for golangci-lint based on my experience and opinion.
# It is very strict, but not extremely strict.
# Feel free to adopt and change it for your needs.
# Feel free to adapt and change it for your needs.
#
# Imported from https://gist.github.com/maratori/47a4d00457a92aa426dbd48a18776322
# Modified for na4ma4 repositories.
#

run:
Expand All @@ -32,6 +34,10 @@ linters-settings:
# Such cases aren't reported by default.
# Default: false
check-type-assertions: true
# List of functions to exclude from checking, where each entry is a single function to exclude.
# See https://github.com/kisielk/errcheck#excluding-functions for details.
exclude-functions:
- (*go.uber.org/zap.Logger).Sync

exhaustive:
# Program elements to check for exhaustiveness.
Expand All @@ -41,7 +47,8 @@ linters-settings:
- map

exhaustruct:
# List of regular expressions to exclude struct packages and names from check.
# List of regular expressions to exclude struct packages and their names from checks.
# Regular expressions must match complete canonical struct package/name/structname.
# Default: []
exclude:
# std libs
Expand Down Expand Up @@ -77,6 +84,9 @@ linters-settings:
# If lower than 0, disable the check.
# Default: 40
statements: 50
# Ignore comments when counting lines.
# Default false
ignore-comments: true

gocognit:
# Minimal code complexity to report.
Expand All @@ -97,21 +107,9 @@ 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:
- os.Chmod
- os.Mkdir
- os.MkdirAll
- os.OpenFile
- os.WriteFile
- prometheus.ExponentialBuckets
- prometheus.ExponentialBucketsRange
- prometheus.LinearBuckets
gomoddirectives:
replace-allow-list:
- k8s.io/kube-openapi

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

govet:
# Enable all analyzers.
Expand All @@ -147,6 +145,36 @@ 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
- tabwriter.NewWriter
- cobra.MinimumNArgs
- cobra.MaximumNArgs
- cobra.ExactArgs
- cobra.RangeArgs

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

perfsprint:
# Optimizes into strings concatenation.
# Default: true
strconcat: 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
# 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
# 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 @@ -192,34 +241,38 @@ linters:
- 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
- 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
- exportloopref # checks for pointers to enclosing loop variables
- fatcontext # detects nested contexts in loops
- 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
- 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
- mnd # detects magic numbers
- 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
Expand All @@ -229,15 +282,20 @@ linters:
- 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
- predeclared # finds code that shadows one of Go's predeclared identifiers
- promlinter # checks Prometheus metrics naming via promlint
- protogetter # reports direct reads from proto message fields when getters should be used
- reassign # checks that package variables are not reassigned
- 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
Expand All @@ -253,6 +311,7 @@ linters:
#- ginkgolinter # [if you use ginkgo/gomega] enforces standards of using ginkgo and gomega
#- godox # detects FIXME, TODO and other comment keywords
#- goheader # checks is file header matches to pattern
#- inamedparam # [great idea, but too strict, need to ignore a lot of cases by default] reports interfaces with unnamed method parameters
#- 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
Expand All @@ -267,9 +326,10 @@ 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
#- 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
#- gosmopolitan # reports certain i18n/l10n anti-patterns in your Go codebase
Expand All @@ -283,18 +343,6 @@ linters:
#- 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 @@ -316,5 +364,26 @@ issues:
- gosec
- noctx
- wrapcheck
- source: "^\\s+if _, ok := err\\.\\([^.]+\\.InternalError\\); ok {"
linters: [ errorlint ]
- linters: [ staticcheck ]
text: "options.AndFrom is deprecated"
- linters: [ staticcheck ]
text: "The component config package has been deprecated and will be removed in a future release."
- path: "cmd/"
linters:
- gochecknoinits
- gochecknoglobals
# Exclude `lll` issues for long lines with `go:generate`.
- linters:
- lll
source: '^//\s*\+kubebuilder:'
- linters:
- godot
source: '^//\s*\+optional'
- path: "api/v1/"
linters:
- gochecknoinits
# Allow dot imports for ginkgo and gomega
- source: ginkgo|gomega
linters:
- revive
text: "should not use dot imports"
File renamed without changes.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/na4ma4/go-permbits

go 1.20
go 1.22.3
6 changes: 6 additions & 0 deletions go.work
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
go 1.22.3

use (
.
./magefiles
)
1 change: 1 addition & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github.com/cheggaaa/pb v2.0.7+incompatible h1:gLKifR1UkZ/kLkda5gC0K6c8g+jU2sINPtBeOiNlMhU=
24 changes: 24 additions & 0 deletions magefiles/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module github.com/na4ma4/go-permbits/magefiles

go 1.22.3

require (
github.com/dosquad/mage v0.1.3
github.com/magefile/mage v1.15.0
)

require (
github.com/VividCortex/ewma v1.1.1 // indirect
github.com/cheggaaa/pb/v3 v3.0.4 // indirect
github.com/dosquad/go-giturl v0.0.0-20240529044908-80f368d13ad5 // indirect
github.com/fatih/color v1.9.0 // indirect
github.com/go-resty/resty/v2 v2.13.1 // indirect
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/mattn/go-runewidth v0.0.7 // indirect
github.com/na4ma4/go-permbits v0.4.0 // indirect
github.com/princjef/mageutil v1.0.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
)
Loading

0 comments on commit e568759

Please sign in to comment.