diff --git a/.golangci.bck.yaml b/.golangci.bck.yaml new file mode 100644 index 0000000000..1cae359605 --- /dev/null +++ b/.golangci.bck.yaml @@ -0,0 +1,308 @@ +issues: + new-from-rev: main + # Set to 0 to disable. + max-issues-per-linter: 0 + # Set to 0 to disable. + max-same-issues: 0 + exclude-dirs: + - .artifacts + - .backups + - .codecov + - .github + - .keys + - .vscode + - build + - console + - deploy + - docs + - guides + - internal/api/ui/login/static + - openapi + - proto + - tools + +run: + concurrency: 4 + timeout: 10m + go: '1.22' +linters: + enable: + # Simple linter to check that your code does not contain non-ASCII identifiers [fast: true, auto-fix: false] + - asciicheck + # checks whether HTTP response body is closed successfully [fast: false, auto-fix: false] + - bodyclose + # check the function whether use a non-inherited context [fast: false, auto-fix: false] + - contextcheck + # Computes and checks the cognitive complexity of functions [fast: true, auto-fix: false] + - gocognit + # Checks Go code for unused constants, variables, functions and types [fast: false, auto-fix: false] + - unused + # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases [fast: false, auto-fix: false] + - errcheck + # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`. [fast: false, auto-fix: false] + - errname + # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. [fast: false, auto-fix: false] + - errorlint + # check exhaustiveness of enum switch statements [fast: false, auto-fix: false] + - exhaustive + # Gci controls golang package import order and makes it always deterministic. [fast: true, auto-fix: false] + - gci + # Provides diagnostics that check for bugs, performance and style issues. [fast: false, auto-fix: false] + - gocritic + # Linter for Go source code that specializes in simplifying a code [fast: false, auto-fix: false] + - gosimple + # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string [fast: false, auto-fix: false] + - govet + # Detects when assignments to existing variables are not used [fast: true, auto-fix: false] + - ineffassign + # Finds commonly misspelled English words in comments [fast: true, auto-fix: true] + - misspell + # Finds naked returns in functions greater than a specified function length [fast: true, auto-fix: false] + - nakedret + # Staticcheck is a go vet on steroids, applying a ton of static analysis checks [fast: false, auto-fix: false] + - staticcheck + # Like the front-end of a Go compiler, parses and type-checks Go code [fast: false, auto-fix: false] + - typecheck + # Reports ill-formed or insufficient nolint directives [fast: true, auto-fix: false] + - nolintlint + # Checks for misuse of Sprintf to construct a host with port in a URL. + - nosprintfhostport + # checks whether Err of rows is checked successfully in `sql.Rows` [fast: false, auto-fix: false] + - rowserrcheck + # Checks that sql.Rows and sql.Stmt are closed. [fast: false, auto-fix: false] + - sqlclosecheck + # Remove unnecessary type conversions [fast: false, auto-fix: false] + - unconvert + disable: + # Checks for dangerous unicode character sequences [fast: true, auto-fix: false] + # not needed because github does that out of the box + - bidichk + # containedctx is a linter that detects struct contained context.Context field [fast: true, auto-fix: false] + # using contextcheck which looks more active + - containedctx + # checks function and package cyclomatic complexity [fast: false, auto-fix: false] + # not use because gocognit is used + - cyclop + # The owner seems to have abandoned the linter. Replaced by unused. + # deprecated, replaced by unused + - deadcode + # check declaration order and count of types, constants, variables and functions [fast: true, auto-fix: false] + # FUTURE: IMO it sometimes makes sense to declare consts or types after a func + - decorder + # Go linter that checks if package imports are in a list of acceptable packages [fast: false, auto-fix: false] + # not required because of dependabot + - depguard + # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f()) [fast: true, auto-fix: false] + # FUTURE: old code is not compatible + - dogsled + # Tool for code clone detection [fast: true, auto-fix: false] + # FUTURE: old code is not compatible + - dupl + # checks for duplicate words in the source code + # not sure if it makes sense + - dupword + # check for two durations multiplied together [fast: false, auto-fix: false] + # FUTURE: checks for accident `1 * time.Second * time.Second` + - durationcheck + # Checks types passed to the json encoding functions. Reports unsupported types and optionally reports occations, where the check for the returned error can be omitted. [fast: false, auto-fix: false] + # FUTURE: use asap, because we use json alot. nice feature is possiblity to check if err check is required + - errchkjson + # execinquery is a linter about query string checker in Query function which reads your Go src files and warning it finds + # FUTURE: might find some errors in sql queries + - execinquery + # Checks if all struct's fields are initialized [fast: false, auto-fix: false] + # deprecated + - exhaustivestruct + # Checks if all structure fields are initialized + # Not all fields have to be initialized + - exhaustruct + # checks for pointers to enclosing loop variables [fast: false, auto-fix: false] + # FUTURE: finds bugs hard to find, could occur much later + - exportloopref + # Forbids identifiers [fast: true, auto-fix: false] + # see no reason. allows to define regexp which are not allowed to use + - forbidigo + # finds forced type assertions [fast: true, auto-fix: false] + # not used because we mostly use `_, _ = a.(int)` + - forcetypeassert + # Tool for detection of long functions [fast: true, auto-fix: false] + # not used because it ignores complexity + - funlen + # check that no global variables exist [fast: true, auto-fix: false] + # We use some global variables which is ok IMO + - gochecknoglobals + # Checks that no init functions are present in Go code [fast: true, auto-fix: false] + # we use inits for the database abstraction + - gochecknoinits + # Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false] + # FUTURE: might be cool to check + - goconst + # Computes and checks the cyclomatic complexity of functions [fast: true, auto-fix: false] + # not used because cyclop also checks complexity of package + - gocyclo + # Check if comments end in a period [fast: true, auto-fix: true] + # FUTURE: checks if comments are written as specified + - godot + # Tool for detection of FIXME, TODO and other comment keywords [fast: true, auto-fix: false] + # FUTURE: maybe makes sense later. IMO some view todos are ok for later tasks. + - godox + # Golang linter to check the errors handling expressions [fast: false, auto-fix: false] + # Not used in favore of errorlint + - goerr113 + # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification [fast: true, auto-fix: true] + # ignored in favor of goimports + - gofmt + # Gofumpt checks whether code was gofumpt-ed. [fast: true, auto-fix: true] + # ignored in favor of goimports + - gofumpt + # Checks is file header matches to pattern [fast: true, auto-fix: false] + # ignored because we don't write licenses as headers + - goheader + # In addition to fixing imports, goimports also formats your code in the same style as gofmt. [fast: true, auto-fix: true] + # ignored in favor of gci + - goimports + #deprecated]: Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes [fast: false, auto-fix: false] + # ignored in favor of goimports + - golint + # An analyzer to detect magic numbers. [fast: true, auto-fix: false] + # FUTURE: not that critical at the moment + - gomnd + # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod. [fast: true, auto-fix: false] + # FUTURE: not a problem at the moment + - gomoddirectives + # Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations. [fast: true, auto-fix: false] + # FUTURE: maybe interesting because of licenses + - gomodguard + # Checks that printf-like functions are named with `f` at the end [fast: true, auto-fix: false] + # FUTURE: not a problem at the moment + - goprintffuncname + # Inspects source code for security problems [fast: false, auto-fix: false] + # TODO: I think it would be more interesting to integrate into gh code scanning: https://github.com/securego/gosec#integrating-with-code-scanning + - gosec + # An analyzer to analyze expression groups. [fast: true, auto-fix: false] + # I think the groups (vars, consts, imports, ...) we have atm are ok + - grouper + # Checks that your code uses short syntax for if-statements whenever possible [fast: true, auto-fix: false] + # Dont't use its deprecated + - ifshort + # Enforces consistent import aliases [fast: false, auto-fix: false] + # FUTURE: aliasing of imports is more or less consistent + - importas + # A linter that checks the number of methods inside an interface. + # No need at the moment, repository abstraction was removed + - interfacebloat + # A linter that suggests interface types + # Don't use it's archived + - interfacer + # Accept Interfaces, Return Concrete Types [fast: false, auto-fix: false] + # FUTURE: check if no interface is returned + - ireturn + # Reports long lines [fast: true, auto-fix: false] + # FUTURE: would make code more readable + - lll + # Checks key valur pairs for common logger libraries (kitlog,klog,logr,zap). + # FUTURE: useable as soon as we switch logger library + - loggercheck + # maintidx measures the maintainability index of each function. [fast: true, auto-fix: false] + # not used because volume of halstead complexity feels strange as measurement https://en.wikipedia.org/wiki/Halstead_complexity_measures + - maintidx + # Finds slice declarations with non-zero initial length [fast: false, auto-fix: false] + # I would prefer to use https://github.com/alexkohler/prealloc + - makezero + # Reports deeply nested if statements [fast: true, auto-fix: false] + # focus only on if's + - nestif + # Finds the code that returns nil even if it checks that the error is not nil. [fast: false, auto-fix: false] + # FUTURE: check if it is allowed to return nil partially in error catch + - nilerr + # Checks that there is no simultaneous return of `nil` error and an invalid value. [fast: false, auto-fix: false] + # FUTURE: would reduce checks and panics + - nilnil + # nlreturn checks for a new line before return and branch statements to increase code clarity [fast: true, auto-fix: false] + # DISCUSS: IMO the readability of does not always increase using more empty lines + - nlreturn + # noctx finds sending http request without context.Context [fast: false, auto-fix: false] + # only interesting if using http + - noctx + # Reports all names returns + # Named returns are not allowed which IMO reduces readability of code + - nonamedreturns + # detects snake case of variable naming and function name. + # has not been a problem in our code and deprecated + - nosnakecase + # paralleltest detects missing usage of t.Parallel() method in your Go test [fast: true, auto-fix: false] + # FUTURE: will break all of our tests + - paralleltest + # Finds slice declarations that could potentially be preallocated [fast: true, auto-fix: false] + # FUTURE: would improve performance + - prealloc + # find code that shadows one of Go's predeclared identifiers [fast: true, auto-fix: false] + # FUTURE: checks for overwrites + - predeclared + # Check Prometheus metrics naming via promlint [fast: true, auto-fix: false] + # Not interesting at the moment + - promlinter + # Checks that package variables are not reassigned + # FUTURE: checks if vars like Err's are reassigned which might break code + - reassign + # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. [fast: false, auto-fix: false] + # Linter aggregator, would allow to use less other linters + - revive + # checks for unpinned variables in go programs + # deprecated + - scopelint + # Finds unused struct fields [fast: false, auto-fix: false] + # deprecated, replaced by unused + - structcheck + # Stylecheck is a replacement for golint [fast: false, auto-fix: false] + # we use goimports + - stylecheck + # Checks the struct tags. [fast: true, auto-fix: false] + # FUTURE: would help for new structs + - tagliatelle + # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17 [fast: false, auto-fix: false] + # FUTURE: currently are no env vars set + - tenv + # linter checks if examples are testable (have an expected output) + # FUTURE: as soon as examples are added + - testableexamples + # linter that makes you use a separate _test package [fast: true, auto-fix: false] + # don't use because we test some unexported functions + - testpackage + # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers [fast: false, auto-fix: false] + # FUTURE: nice to improve test quality + - thelper + # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes [fast: false, auto-fix: false] + # FUTURE: nice to improve test quality + - tparallel + # Reports unused function parameters [fast: false, auto-fix: false] + # DISCUSS: nice idea and would improve code quality, but how to handle false positives? + - unparam + # A linter that detect the possibility to use variables/constants from the Go standard library. + # FUTURE: improves code quality + - usestdlibvars + # Finds unused global variables and constants [fast: false, auto-fix: false] + # deprecated, replaced by unused + - varcheck + # checks that the length of a variable's name matches its scope [fast: false, auto-fix: false] + # I would not use it because it more or less checks if var lenght matches + - varnamelen + # wastedassign finds wasted assignment statements. [fast: false, auto-fix: false] + # FUTURE: would improve code quality (maybe already checked by vet?) + - wastedassign + # Tool for detection of leading and trailing whitespace [fast: true, auto-fix: true] + # Not sure if it improves code readability + - whitespace + # Checks that errors returned from external packages are wrapped [fast: false, auto-fix: false] + # FUTURE: improves UX because all the errors will be ZITADEL errors + - wrapcheck + # Whitespace Linter - Forces you to use empty lines! [fast: true, auto-fix: false] + # FUTURE: improves code quality by allowing and blocking line breaks + - wsl +linters-settings: + gci: + sections: + - standard # Standard section: captures all standard packages. + - default # Default section: contains all imports that could not be matched to another section type. + - prefix(github.com/zitadel/zitadel) # Custom section: groups all imports with the specified Prefix. + custom-order: true diff --git a/.golangci.yaml b/.golangci.yaml index 1cae359605..4d81da1fd6 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,308 +1,142 @@ -issues: - new-from-rev: main - # Set to 0 to disable. - max-issues-per-linter: 0 - # Set to 0 to disable. - max-same-issues: 0 - exclude-dirs: - - .artifacts - - .backups - - .codecov - - .github - - .keys - - .vscode - - build - - console - - deploy - - docs - - guides - - internal/api/ui/login/static - - openapi - - proto - - tools - +version: "2" run: concurrency: 4 - timeout: 10m - go: '1.22' + go: "1.24" linters: enable: - # Simple linter to check that your code does not contain non-ASCII identifiers [fast: true, auto-fix: false] - asciicheck - # checks whether HTTP response body is closed successfully [fast: false, auto-fix: false] - bodyclose - # check the function whether use a non-inherited context [fast: false, auto-fix: false] - contextcheck - # Computes and checks the cognitive complexity of functions [fast: true, auto-fix: false] - - gocognit - # Checks Go code for unused constants, variables, functions and types [fast: false, auto-fix: false] - - unused - # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases [fast: false, auto-fix: false] - - errcheck - # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`. [fast: false, auto-fix: false] - errname - # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. [fast: false, auto-fix: false] - errorlint - # check exhaustiveness of enum switch statements [fast: false, auto-fix: false] - exhaustive - # Gci controls golang package import order and makes it always deterministic. [fast: true, auto-fix: false] - - gci - # Provides diagnostics that check for bugs, performance and style issues. [fast: false, auto-fix: false] + - gocognit - gocritic - # Linter for Go source code that specializes in simplifying a code [fast: false, auto-fix: false] - - gosimple - # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string [fast: false, auto-fix: false] - - govet - # Detects when assignments to existing variables are not used [fast: true, auto-fix: false] - - ineffassign - # Finds commonly misspelled English words in comments [fast: true, auto-fix: true] - misspell - # Finds naked returns in functions greater than a specified function length [fast: true, auto-fix: false] - nakedret - # Staticcheck is a go vet on steroids, applying a ton of static analysis checks [fast: false, auto-fix: false] - - staticcheck - # Like the front-end of a Go compiler, parses and type-checks Go code [fast: false, auto-fix: false] - - typecheck - # Reports ill-formed or insufficient nolint directives [fast: true, auto-fix: false] - nolintlint - # Checks for misuse of Sprintf to construct a host with port in a URL. - nosprintfhostport - # checks whether Err of rows is checked successfully in `sql.Rows` [fast: false, auto-fix: false] - rowserrcheck - # Checks that sql.Rows and sql.Stmt are closed. [fast: false, auto-fix: false] - sqlclosecheck - # Remove unnecessary type conversions [fast: false, auto-fix: false] - unconvert disable: - # Checks for dangerous unicode character sequences [fast: true, auto-fix: false] - # not needed because github does that out of the box - bidichk - # containedctx is a linter that detects struct contained context.Context field [fast: true, auto-fix: false] - # using contextcheck which looks more active - containedctx - # checks function and package cyclomatic complexity [fast: false, auto-fix: false] - # not use because gocognit is used - cyclop - # The owner seems to have abandoned the linter. Replaced by unused. - # deprecated, replaced by unused - - deadcode - # check declaration order and count of types, constants, variables and functions [fast: true, auto-fix: false] - # FUTURE: IMO it sometimes makes sense to declare consts or types after a func - decorder - # Go linter that checks if package imports are in a list of acceptable packages [fast: false, auto-fix: false] - # not required because of dependabot - depguard - # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f()) [fast: true, auto-fix: false] - # FUTURE: old code is not compatible - dogsled - # Tool for code clone detection [fast: true, auto-fix: false] - # FUTURE: old code is not compatible - dupl - # checks for duplicate words in the source code - # not sure if it makes sense - dupword - # check for two durations multiplied together [fast: false, auto-fix: false] - # FUTURE: checks for accident `1 * time.Second * time.Second` - durationcheck - # Checks types passed to the json encoding functions. Reports unsupported types and optionally reports occations, where the check for the returned error can be omitted. [fast: false, auto-fix: false] - # FUTURE: use asap, because we use json alot. nice feature is possiblity to check if err check is required + - err113 - errchkjson - # execinquery is a linter about query string checker in Query function which reads your Go src files and warning it finds - # FUTURE: might find some errors in sql queries - - execinquery - # Checks if all struct's fields are initialized [fast: false, auto-fix: false] - # deprecated - - exhaustivestruct - # Checks if all structure fields are initialized - # Not all fields have to be initialized - exhaustruct - # checks for pointers to enclosing loop variables [fast: false, auto-fix: false] - # FUTURE: finds bugs hard to find, could occur much later - - exportloopref - # Forbids identifiers [fast: true, auto-fix: false] - # see no reason. allows to define regexp which are not allowed to use - forbidigo - # finds forced type assertions [fast: true, auto-fix: false] - # not used because we mostly use `_, _ = a.(int)` - forcetypeassert - # Tool for detection of long functions [fast: true, auto-fix: false] - # not used because it ignores complexity - funlen - # check that no global variables exist [fast: true, auto-fix: false] - # We use some global variables which is ok IMO - gochecknoglobals - # Checks that no init functions are present in Go code [fast: true, auto-fix: false] - # we use inits for the database abstraction - gochecknoinits - # Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false] - # FUTURE: might be cool to check - goconst - # Computes and checks the cyclomatic complexity of functions [fast: true, auto-fix: false] - # not used because cyclop also checks complexity of package - gocyclo - # Check if comments end in a period [fast: true, auto-fix: true] - # FUTURE: checks if comments are written as specified - godot - # Tool for detection of FIXME, TODO and other comment keywords [fast: true, auto-fix: false] - # FUTURE: maybe makes sense later. IMO some view todos are ok for later tasks. - godox - # Golang linter to check the errors handling expressions [fast: false, auto-fix: false] - # Not used in favore of errorlint - - goerr113 - # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification [fast: true, auto-fix: true] - # ignored in favor of goimports - - gofmt - # Gofumpt checks whether code was gofumpt-ed. [fast: true, auto-fix: true] - # ignored in favor of goimports - - gofumpt - # Checks is file header matches to pattern [fast: true, auto-fix: false] - # ignored because we don't write licenses as headers - goheader - # In addition to fixing imports, goimports also formats your code in the same style as gofmt. [fast: true, auto-fix: true] - # ignored in favor of gci - - goimports - #deprecated]: Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes [fast: false, auto-fix: false] - # ignored in favor of goimports - - golint - # An analyzer to detect magic numbers. [fast: true, auto-fix: false] - # FUTURE: not that critical at the moment - - gomnd - # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod. [fast: true, auto-fix: false] - # FUTURE: not a problem at the moment - gomoddirectives - # Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations. [fast: true, auto-fix: false] - # FUTURE: maybe interesting because of licenses - gomodguard - # Checks that printf-like functions are named with `f` at the end [fast: true, auto-fix: false] - # FUTURE: not a problem at the moment - goprintffuncname - # Inspects source code for security problems [fast: false, auto-fix: false] - # TODO: I think it would be more interesting to integrate into gh code scanning: https://github.com/securego/gosec#integrating-with-code-scanning - gosec - # An analyzer to analyze expression groups. [fast: true, auto-fix: false] - # I think the groups (vars, consts, imports, ...) we have atm are ok - grouper - # Checks that your code uses short syntax for if-statements whenever possible [fast: true, auto-fix: false] - # Dont't use its deprecated - - ifshort - # Enforces consistent import aliases [fast: false, auto-fix: false] - # FUTURE: aliasing of imports is more or less consistent - importas - # A linter that checks the number of methods inside an interface. - # No need at the moment, repository abstraction was removed - interfacebloat - # A linter that suggests interface types - # Don't use it's archived - - interfacer - # Accept Interfaces, Return Concrete Types [fast: false, auto-fix: false] - # FUTURE: check if no interface is returned - ireturn - # Reports long lines [fast: true, auto-fix: false] - # FUTURE: would make code more readable - lll - # Checks key valur pairs for common logger libraries (kitlog,klog,logr,zap). - # FUTURE: useable as soon as we switch logger library - loggercheck - # maintidx measures the maintainability index of each function. [fast: true, auto-fix: false] - # not used because volume of halstead complexity feels strange as measurement https://en.wikipedia.org/wiki/Halstead_complexity_measures - maintidx - # Finds slice declarations with non-zero initial length [fast: false, auto-fix: false] - # I would prefer to use https://github.com/alexkohler/prealloc - makezero - # Reports deeply nested if statements [fast: true, auto-fix: false] - # focus only on if's + - mnd - nestif - # Finds the code that returns nil even if it checks that the error is not nil. [fast: false, auto-fix: false] - # FUTURE: check if it is allowed to return nil partially in error catch - nilerr - # Checks that there is no simultaneous return of `nil` error and an invalid value. [fast: false, auto-fix: false] - # FUTURE: would reduce checks and panics - nilnil - # nlreturn checks for a new line before return and branch statements to increase code clarity [fast: true, auto-fix: false] - # DISCUSS: IMO the readability of does not always increase using more empty lines - nlreturn - # noctx finds sending http request without context.Context [fast: false, auto-fix: false] - # only interesting if using http - noctx - # Reports all names returns - # Named returns are not allowed which IMO reduces readability of code - nonamedreturns - # detects snake case of variable naming and function name. - # has not been a problem in our code and deprecated - - nosnakecase - # paralleltest detects missing usage of t.Parallel() method in your Go test [fast: true, auto-fix: false] - # FUTURE: will break all of our tests - paralleltest - # Finds slice declarations that could potentially be preallocated [fast: true, auto-fix: false] - # FUTURE: would improve performance - prealloc - # find code that shadows one of Go's predeclared identifiers [fast: true, auto-fix: false] - # FUTURE: checks for overwrites - predeclared - # Check Prometheus metrics naming via promlint [fast: true, auto-fix: false] - # Not interesting at the moment - promlinter - # Checks that package variables are not reassigned - # FUTURE: checks if vars like Err's are reassigned which might break code - reassign - # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. [fast: false, auto-fix: false] - # Linter aggregator, would allow to use less other linters - revive - # checks for unpinned variables in go programs - # deprecated - - scopelint - # Finds unused struct fields [fast: false, auto-fix: false] - # deprecated, replaced by unused - - structcheck - # Stylecheck is a replacement for golint [fast: false, auto-fix: false] - # we use goimports - - stylecheck - # Checks the struct tags. [fast: true, auto-fix: false] - # FUTURE: would help for new structs - tagliatelle - # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17 [fast: false, auto-fix: false] - # FUTURE: currently are no env vars set - - tenv - # linter checks if examples are testable (have an expected output) - # FUTURE: as soon as examples are added - testableexamples - # linter that makes you use a separate _test package [fast: true, auto-fix: false] - # don't use because we test some unexported functions - testpackage - # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers [fast: false, auto-fix: false] - # FUTURE: nice to improve test quality - thelper - # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes [fast: false, auto-fix: false] - # FUTURE: nice to improve test quality - tparallel - # Reports unused function parameters [fast: false, auto-fix: false] - # DISCUSS: nice idea and would improve code quality, but how to handle false positives? - unparam - # A linter that detect the possibility to use variables/constants from the Go standard library. - # FUTURE: improves code quality - usestdlibvars - # Finds unused global variables and constants [fast: false, auto-fix: false] - # deprecated, replaced by unused - - varcheck - # checks that the length of a variable's name matches its scope [fast: false, auto-fix: false] - # I would not use it because it more or less checks if var lenght matches - varnamelen - # wastedassign finds wasted assignment statements. [fast: false, auto-fix: false] - # FUTURE: would improve code quality (maybe already checked by vet?) - wastedassign - # Tool for detection of leading and trailing whitespace [fast: true, auto-fix: true] - # Not sure if it improves code readability - whitespace - # Checks that errors returned from external packages are wrapped [fast: false, auto-fix: false] - # FUTURE: improves UX because all the errors will be ZITADEL errors - wrapcheck - # Whitespace Linter - Forces you to use empty lines! [fast: true, auto-fix: false] - # FUTURE: improves code quality by allowing and blocking line breaks - wsl -linters-settings: - gci: - sections: - - standard # Standard section: captures all standard packages. - - default # Default section: contains all imports that could not be matched to another section type. - - prefix(github.com/zitadel/zitadel) # Custom section: groups all imports with the specified Prefix. - custom-order: true + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + paths: + - .artifacts + - .backups + - .codecov + - .github + - .keys + - .vscode + - build + - console + - deploy + - docs + - guides + - internal/api/ui/login/static + - openapi + - proto + - tools + - third_party$ + - builtin$ + - examples$ +issues: + max-issues-per-linter: 0 + max-same-issues: 0 + new-from-rev: main +formatters: + enable: + - gci + settings: + gci: + sections: + - standard + - default + - prefix(github.com/zitadel/zitadel) + custom-order: true + exclusions: + generated: lax + paths: + - .artifacts + - .backups + - .codecov + - .github + - .keys + - .vscode + - build + - console + - deploy + - docs + - guides + - internal/api/ui/login/static + - openapi + - proto + - tools + - third_party$ + - builtin$ + - examples$ diff --git a/backend/v3/domain/instance.go b/backend/v3/domain/instance.go index cc08791d38..60a5f98f8d 100644 --- a/backend/v3/domain/instance.go +++ b/backend/v3/domain/instance.go @@ -110,11 +110,3 @@ type InstanceRepository interface { type CreateInstance struct { Name string `json:"name"` } - -type InstanceQueryOption func(*InstanceQueryOpts) - -type InstanceQueryOpts struct { - database.QueryOpts - - JoinDomains bool -} \ No newline at end of file diff --git a/backend/v3/domain/instance_domain.go b/backend/v3/domain/instance_domain.go index eadbd09406..76ce42048f 100644 --- a/backend/v3/domain/instance_domain.go +++ b/backend/v3/domain/instance_domain.go @@ -2,22 +2,16 @@ package domain import ( "context" - "encoding/json" "time" "github.com/zitadel/zitadel/backend/v3/storage/database" ) -type InstanceDomains struct { - domains []*InstanceDomain - Raw json.RawMessage -} - type InstanceDomain struct { - InstanceID string `json:"instanceId,omitempty" db:"instance_id"` - Domain string `json:"domain,omitempty" db:"domain"` - IsVerified bool `json:"isVerified,omitempty" db:"is_verified"` - IsPrimary bool `json:"isPrimary,omitempty" db:"is_primary"` + InstanceID string `json:"instanceId,omitempty" db:"instance_id"` + Domain string `json:"domain,omitempty" db:"domain"` + IsVerified bool `json:"isVerified,omitempty" db:"is_verified"` + IsPrimary bool `json:"isPrimary,omitempty" db:"is_primary"` ValidationType DomainValidationType `json:"validationType,omitempty" db:"validation_type"` CreatedAt string `json:"createdAt,omitempty" db:"created_at"` @@ -25,10 +19,10 @@ type InstanceDomain struct { } type AddInstanceDomain struct { - InstanceID string `json:"instanceId,omitempty" db:"instance_id"` - Domain string `json:"domain,omitempty" db:"domain"` - IsVerified bool `json:"isVerified,omitempty" db:"is_verified"` - IsPrimary bool `json:"isPrimary,omitempty" db:"is_primary"` + InstanceID string `json:"instanceId,omitempty" db:"instance_id"` + Domain string `json:"domain,omitempty" db:"domain"` + IsVerified bool `json:"isVerified,omitempty" db:"is_verified"` + IsPrimary bool `json:"isPrimary,omitempty" db:"is_primary"` VerificationType DomainValidationType `json:"validationType,omitempty" db:"validation_type"` // CreatedAt is the time when the domain was added. diff --git a/backend/v3/domain/organization.go b/backend/v3/domain/organization.go index 255c564a75..6e51fe19da 100644 --- a/backend/v3/domain/organization.go +++ b/backend/v3/domain/organization.go @@ -103,4 +103,3 @@ type MemberRepository interface { SetMemberRoles(ctx context.Context, orgID, userID string, roles []string) error RemoveMember(ctx context.Context, orgID, userID string) error } - diff --git a/backend/v3/domain/organization_domain.go b/backend/v3/domain/organization_domain.go index 9f8aac9ccc..c2c6390757 100644 --- a/backend/v3/domain/organization_domain.go +++ b/backend/v3/domain/organization_domain.go @@ -8,11 +8,11 @@ import ( ) type OrganizationDomain struct { - InstanceID string `json:"instanceId,omitempty" db:"instance_id"` - OrgID string `json:"orgId,omitempty" db:"org_id"` - Domain string `json:"domain,omitempty" db:"domain"` - IsVerified bool `json:"isVerified,omitempty" db:"is_verified"` - IsPrimary bool `json:"isPrimary,omitempty" db:"is_primary"` + InstanceID string `json:"instanceId,omitempty" db:"instance_id"` + OrgID string `json:"orgId,omitempty" db:"org_id"` + Domain string `json:"domain,omitempty" db:"domain"` + IsVerified bool `json:"isVerified,omitempty" db:"is_verified"` + IsPrimary bool `json:"isPrimary,omitempty" db:"is_primary"` ValidationType DomainValidationType `json:"validationType,omitempty" db:"validation_type"` CreatedAt string `json:"createdAt,omitempty" db:"created_at"` @@ -20,11 +20,11 @@ type OrganizationDomain struct { } type AddOrganizationDomain struct { - InstanceID string `json:"instanceId,omitempty" db:"instance_id"` - OrgID string `json:"orgId,omitempty" db:"org_id"` - Domain string `json:"domain,omitempty" db:"domain"` - IsVerified bool `json:"isVerified,omitempty" db:"is_verified"` - IsPrimary bool `json:"isPrimary,omitempty" db:"is_primary"` + InstanceID string `json:"instanceId,omitempty" db:"instance_id"` + OrgID string `json:"orgId,omitempty" db:"org_id"` + Domain string `json:"domain,omitempty" db:"domain"` + IsVerified bool `json:"isVerified,omitempty" db:"is_verified"` + IsPrimary bool `json:"isPrimary,omitempty" db:"is_primary"` ValidationType DomainValidationType `json:"validationType,omitempty" db:"validation_type"` // CreatedAt is the time when the domain was added. diff --git a/backend/v3/storage/database/column.go b/backend/v3/storage/database/column.go index 7e2629dbdd..731e48ac16 100644 --- a/backend/v3/storage/database/column.go +++ b/backend/v3/storage/database/column.go @@ -53,6 +53,6 @@ type ignoreCaseCol struct { // WriteIgnoreCase implements [ignoreCaseColumn]. func (c ignoreCaseCol) WriteIgnoreCase(builder *StatementBuilder) { - c.column.Write(builder) + c.Write(builder) builder.WriteString(c.suffix) } diff --git a/backend/v3/storage/database/dialect/postgres/conn.go b/backend/v3/storage/database/dialect/postgres/conn.go index 24c0de92c2..a556b7a545 100644 --- a/backend/v3/storage/database/dialect/postgres/conn.go +++ b/backend/v3/storage/database/dialect/postgres/conn.go @@ -23,7 +23,7 @@ func (c *pgxConn) Release(_ context.Context) error { // Begin implements [database.Client]. func (c *pgxConn) Begin(ctx context.Context, opts *database.TransactionOptions) (database.Transaction, error) { - tx, err := c.Conn.BeginTx(ctx, transactionOptionsToPgx(opts)) + tx, err := c.BeginTx(ctx, transactionOptionsToPgx(opts)) if err != nil { return nil, wrapError(err) } diff --git a/backend/v3/storage/database/dialect/postgres/pool.go b/backend/v3/storage/database/dialect/postgres/pool.go index 9722750e4c..bf4ca44c31 100644 --- a/backend/v3/storage/database/dialect/postgres/pool.go +++ b/backend/v3/storage/database/dialect/postgres/pool.go @@ -58,7 +58,7 @@ func (c *pgxPool) Exec(ctx context.Context, sql string, args ...any) (int64, err // Begin implements [database.Pool]. func (c *pgxPool) Begin(ctx context.Context, opts *database.TransactionOptions) (database.Transaction, error) { - tx, err := c.Pool.BeginTx(ctx, transactionOptionsToPgx(opts)) + tx, err := c.BeginTx(ctx, transactionOptionsToPgx(opts)) if err != nil { return nil, wrapError(err) } diff --git a/backend/v3/storage/database/query.go b/backend/v3/storage/database/query.go index 640a03d7e2..abc66d9377 100644 --- a/backend/v3/storage/database/query.go +++ b/backend/v3/storage/database/query.go @@ -51,7 +51,7 @@ func WithLeftJoin(table string, columns Condition) QueryOption { type joinType string const ( - JoinTypeLeft joinType = "LEFT" + JoinTypeLeft joinType = "LEFT" ) type join struct { @@ -68,13 +68,13 @@ type QueryOpts struct { Condition Condition // OrderBy is the columns to order the results by. // It is used to build the ORDER BY clause of the SQL statement. - OrderBy Columns + OrderBy Columns // Limit is the maximum number of results to return. // It is used to build the LIMIT clause of the SQL statement. - Limit uint32 + Limit uint32 // Offset is the number of results to skip before returning the results. // It is used to build the OFFSET clause of the SQL statement. - Offset uint32 + Offset uint32 // GroupBy is the columns to group the results by. // It is used to build the GROUP BY clause of the SQL statement. GroupBy Columns @@ -83,7 +83,6 @@ type QueryOpts struct { Joins []join } - func (opts *QueryOpts) Write(builder *StatementBuilder) { opts.WriteLeftJoins(builder) opts.WriteCondition(builder) @@ -145,4 +144,4 @@ func (opts *QueryOpts) WriteLeftJoins(builder *StatementBuilder) { builder.WriteString(" ON ") join.columns.Write(builder) } -} \ No newline at end of file +} diff --git a/backend/v3/storage/database/repository/instance.go b/backend/v3/storage/database/repository/instance.go index 5476316fc3..74277c3879 100644 --- a/backend/v3/storage/database/repository/instance.go +++ b/backend/v3/storage/database/repository/instance.go @@ -24,24 +24,23 @@ func InstanceRepository(client database.QueryExecutor) domain.InstanceRepository } } - // ------------------------------------------------------------- // repository // ------------------------------------------------------------- const ( queryInstanceStmt = `SELECT instances.id, instances.name, instances.default_org_id, instances.iam_project_id, instances.console_client_id, instances.console_app_id, instances.default_language, instances.created_at, instances.updated_at` + - ` , CASE WHEN count(instance_domains.domain) > 0 THEN jsonb_agg(json_build_object('domain', instance_domains.domain, 'isVerified', instance_domains.is_verified, 'isPrimary', instance_domains.is_primary, 'isGenerated', instance_domains.is_generated, 'validationType', instance_domains.validation_type, 'createdAt', instance_domains.created_at, 'updatedAt', instance_domains.updated_at)) ELSE NULL::JSONB END domains` + - ` FROM zitadel.instances` + ` , CASE WHEN count(instance_domains.domain) > 0 THEN jsonb_agg(json_build_object('domain', instance_domains.domain, 'isVerified', instance_domains.is_verified, 'isPrimary', instance_domains.is_primary, 'isGenerated', instance_domains.is_generated, 'validationType', instance_domains.validation_type, 'createdAt', instance_domains.created_at, 'updatedAt', instance_domains.updated_at)) ELSE NULL::JSONB END domains` + + ` FROM zitadel.instances` ) // Get implements [domain.InstanceRepository]. func (i *instance) Get(ctx context.Context, opts ...database.QueryOption) (*domain.Instance, error) { - opts = append(opts, - i.joinDomains(), + opts = append(opts, + i.joinDomains(), database.WithGroupBy(i.IDColumn(true)), ) - + options := new(database.QueryOpts) for _, opt := range opts { opt(options) @@ -56,11 +55,11 @@ func (i *instance) Get(ctx context.Context, opts ...database.QueryOption) (*doma // List implements [domain.InstanceRepository]. func (i *instance) List(ctx context.Context, opts ...database.QueryOption) ([]*domain.Instance, error) { - opts = append(opts, - i.joinDomains(), + opts = append(opts, + i.joinDomains(), database.WithGroupBy(i.IDColumn(true)), ) - + options := new(database.QueryOpts) for _, opt := range opts { opt(options) @@ -243,7 +242,7 @@ func scanInstance(ctx context.Context, querier database.Querier, builder *databa if err != nil { return nil, err } - + var instance rawInstance if err := rows.(database.CollectableRows).CollectExactlyOneRow(&instance); err != nil { return nil, err diff --git a/backend/v3/storage/database/repository/instance_domain.go b/backend/v3/storage/database/repository/instance_domain.go index db1ad509fa..fef2be4e35 100644 --- a/backend/v3/storage/database/repository/instance_domain.go +++ b/backend/v3/storage/database/repository/instance_domain.go @@ -229,4 +229,4 @@ func scanInstanceDomain(ctx context.Context, querier database.Querier, builder * } return instanceDomain, nil -} \ No newline at end of file +} diff --git a/backend/v3/storage/database/repository/org.go b/backend/v3/storage/database/repository/org.go index cb80f240d7..d1503393ea 100644 --- a/backend/v3/storage/database/repository/org.go +++ b/backend/v3/storage/database/repository/org.go @@ -58,12 +58,12 @@ func (o *org) List(ctx context.Context, opts ...database.QueryOption) ([]*domain database.WithGroupBy(o.InstanceIDColumn(true), o.IDColumn(true)), ) - options := new(database.QueryOpts) + options := new(database.QueryOpts) for _, opt := range opts { opt(options) } - - var builder database.StatementBuilder + + var builder database.StatementBuilder builder.WriteString(queryOrganizationStmt) options.Write(&builder) @@ -72,7 +72,7 @@ func (o *org) List(ctx context.Context, opts ...database.QueryOption) ([]*domain func (o *org) joinDomains() database.QueryOption { columns := make([]database.Condition, 0, 3) - columns = append(columns, + columns = append(columns, database.NewColumnCondition(o.InstanceIDColumn(true), o.Domains(false).InstanceIDColumn(true)), database.NewColumnCondition(o.IDColumn(true), o.Domains(false).OrgIDColumn(true)), ) @@ -89,7 +89,6 @@ func (o *org) joinDomains() database.QueryOption { ) } - const createOrganizationStmt = `INSERT INTO zitadel.organizations (id, name, instance_id, state)` + ` VALUES ($1, $2, $3, $4)` + ` RETURNING created_at, updated_at` @@ -103,7 +102,6 @@ func (o *org) Create(ctx context.Context, organization *domain.Organization) err return o.client.QueryRow(ctx, builder.String(), builder.Args()...).Scan(&organization.CreatedAt, &organization.UpdatedAt) } - // Update implements [domain.OrganizationRepository]. func (o *org) Update(ctx context.Context, id domain.OrgIdentifierCondition, instanceID string, changes ...database.Change) (int64, error) { if len(changes) == 0 { @@ -266,7 +264,7 @@ func scanOrganizations(ctx context.Context, querier database.Querier, builder *d if err := rows.(database.CollectableRows).Collect(&rawOrgs); err != nil { return nil, err } - + organizations := make([]*domain.Organization, len(rawOrgs)) for i, org := range rawOrgs { if len(org.RawDomains) > 0 { diff --git a/backend/v3/storage/database/repository/org_domain.go b/backend/v3/storage/database/repository/org_domain.go index f114785bbd..d41710f893 100644 --- a/backend/v3/storage/database/repository/org_domain.go +++ b/backend/v3/storage/database/repository/org_domain.go @@ -14,8 +14,6 @@ type orgDomain struct { *org } - - // ------------------------------------------------------------- // repository // ------------------------------------------------------------- @@ -146,7 +144,7 @@ func (o orgDomain) OrgIDCondition(orgID string) database.Condition { // Subtle: this method shadows the method ([domain.OrganizationRepository]).CreatedAtColumn of orgDomain.org. func (orgDomain) CreatedAtColumn(qualified bool) database.Column { if qualified { - return database.NewColumn("org_domains.created_at") + return database.NewColumn("org_domains.created_at") } return database.NewColumn("created_at") } @@ -154,7 +152,7 @@ func (orgDomain) CreatedAtColumn(qualified bool) database.Column { // DomainColumn implements [domain.OrganizationDomainRepository]. func (orgDomain) DomainColumn(qualified bool) database.Column { if qualified { - return database.NewColumn("org_domains.domain") + return database.NewColumn("org_domains.domain") } return database.NewColumn("domain") } @@ -163,7 +161,7 @@ func (orgDomain) DomainColumn(qualified bool) database.Column { // Subtle: this method shadows the method ([domain.OrganizationRepository]).InstanceIDColumn of orgDomain.org. func (orgDomain) InstanceIDColumn(qualified bool) database.Column { if qualified { - return database.NewColumn("org_domains.instance_id") + return database.NewColumn("org_domains.instance_id") } return database.NewColumn("instance_id") } @@ -171,7 +169,7 @@ func (orgDomain) InstanceIDColumn(qualified bool) database.Column { // IsPrimaryColumn implements [domain.OrganizationDomainRepository]. func (orgDomain) IsPrimaryColumn(qualified bool) database.Column { if qualified { - return database.NewColumn("org_domains.is_primary") + return database.NewColumn("org_domains.is_primary") } return database.NewColumn("is_primary") } @@ -179,7 +177,7 @@ func (orgDomain) IsPrimaryColumn(qualified bool) database.Column { // IsVerifiedColumn implements [domain.OrganizationDomainRepository]. func (orgDomain) IsVerifiedColumn(qualified bool) database.Column { if qualified { - return database.NewColumn("org_domains.is_verified") + return database.NewColumn("org_domains.is_verified") } return database.NewColumn("is_verified") } @@ -187,7 +185,7 @@ func (orgDomain) IsVerifiedColumn(qualified bool) database.Column { // OrgIDColumn implements [domain.OrganizationDomainRepository]. func (orgDomain) OrgIDColumn(qualified bool) database.Column { if qualified { - return database.NewColumn("org_domains.org_id") + return database.NewColumn("org_domains.org_id") } return database.NewColumn("org_id") } @@ -196,7 +194,7 @@ func (orgDomain) OrgIDColumn(qualified bool) database.Column { // Subtle: this method shadows the method ([domain.OrganizationRepository]).UpdatedAtColumn of orgDomain.org. func (orgDomain) UpdatedAtColumn(qualified bool) database.Column { if qualified { - return database.NewColumn("org_domains.updated_at") + return database.NewColumn("org_domains.updated_at") } return database.NewColumn("updated_at") } @@ -204,7 +202,7 @@ func (orgDomain) UpdatedAtColumn(qualified bool) database.Column { // ValidationTypeColumn implements [domain.OrganizationDomainRepository]. func (orgDomain) ValidationTypeColumn(qualified bool) database.Column { if qualified { - return database.NewColumn("org_domains.validation_type") + return database.NewColumn("org_domains.validation_type") } return database.NewColumn("validation_type") } @@ -218,7 +216,7 @@ func scanOrganizationDomain(ctx context.Context, client database.Querier, builde if err != nil { return nil, err } - + organizationDomain := &domain.OrganizationDomain{} if err := rows.(database.CollectableRows).CollectExactlyOneRow(organizationDomain); err != nil { return nil, err diff --git a/backend/v3/storage/database/repository/user_test.go b/backend/v3/storage/database/repository/user_test.go index b365fe5c95..2cf8a5e94b 100644 --- a/backend/v3/storage/database/repository/user_test.go +++ b/backend/v3/storage/database/repository/user_test.go @@ -74,4 +74,3 @@ package repository_test // user.Human().Update(context.Background(), user.IDCondition("test"), user.SetUsername("test")) // }) // } -