gochecker

command module
v0.21.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2023 License: MIT Imports: 1 Imported by: 0

README

gochecker

Code Analysis Go Reference GitHub tag (latest SemVer)

Go tool to check the code (linter)

Another variation of the go linters. The gochecker is a wrapper for multichecker. The gochecker supports go vet interface and includes all official analyzers and some custom linters, see analyzers.go file for the full list. In theory the gochecker can support any analyzers which implement Analyzer type.

The gochecker was implemented in order to solve some limitations of the golangci-linter.

Installation

go install github.com/sv-tools/gochecker@latest

Usage

gochecker -config config.yaml ./...

or using cli flags:

gochecker -fieldalignment -fix ./...

and please check gochecker help or gochecker help <analyzer> for full help.

GitHub Action
jobs:
  gochecker:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3
      - name: Install Go
        uses: actions/setup-go@v3
      - name: Install gochecker
        run: go install github.com/sv-tools/gochecker@latest
      - name: gochecker
        run: gochecker -config gochecker.yaml -output github ./...
GitHub Action with reusable workflow
jobs:
  gochecker:
    uses: sv-tools/gochecker/.github/workflows/gochecker.yaml@main
    with:
      config: gochecker.yaml
      version: latest # optional; `latest` by default
      args: # optional; any additional command-line arguments
      go-version: # optional; the version of go to be used

Supported analyzers

Go passes

Or all the passes can be added as individual analyzers as well, which allows more precisely confixwguration of the gochecker.

  • asmdecl reports mismatches between assembly files and Go declarations.
  • assign detects useless assignments.
  • atomic checks for common mistakes using the sync/atomic package.
  • atomicalign checks for non-64-bit-aligned arguments to sync/atomic functions. On non-32-bit platforms, those functions panic if their argument variables are not 64-bit aligned. It is therefore the caller's responsibility to arrange for 64-bit alignment of such variables.
  • bools detects common mistakes involving boolean operators.
  • buildtag checks build tags.
  • cgocall detects some violations of the cgo pointer passing rules.
  • composite checks for unkeyed composite literals.
  • copylock checks for locks erroneously passed by value.
  • deepequalerrors checks for the use of reflect.DeepEqual with error values.
  • directive checks known Go toolchain directives.
  • errorsas checks that the second argument to errors.As is a pointer to a type implementing error.
  • fieldalignment detects structs that would use less memory if their fields were sorted.
  • framepointer reports assembly code that clobbers the frame pointer before saving it.
  • httpresponse checks for mistakes using HTTP responses.
  • ifaceassert flags impossible interface-interface type assertions.
  • loopclosure checks for references to enclosing loop variables from within nested functions.
  • lostcancel checks for failure to call a context cancellation function.
  • nilfunc checks for useless comparisons against nil.
  • nilness inspects the control-flow graph of an SSA function and reports errors such as nil pointer dereferences and degenerate nil pointer comparisons.
  • printf checks consistency of Printf format strings and arguments.
  • reflectvaluecompare checks for accidentally using == or reflect.DeepEqual to compare reflect.Value values. See issues 43993 and 18871.
  • shadow checks for shadowed variables.
  • shift checks for shifts that exceed the width of an integer.
  • sigchanyzer detects misuse of unbuffered signal as argument to signal.Notify.
  • sortslice checks for calls to sort.Slice that do not use a slice type as first argument.
  • stdmethods checks for misspellings in the signatures of methods similar to well-known interfaces.
  • stringintconv flags type conversions from integers to strings.
  • structtag checks struct field tags are well-formed.
  • testinggoroutine report calls to (*testing.T).Fatal from goroutines started by a test.
  • tests checks for common mistaken usages of tests and examples.
  • timeformat checks for the use of time.Format or time.Parse calls with a bad format.
  • unmarshal checks for passing non-pointer or non-interface types to unmarshal and decode functions.
  • unreachable checks for unreachable code.
  • unsafeptr checks for invalid conversions of uintptr to unsafe.Pointer.
  • unusedresult checks for unused results of calls to certain pure functions.
  • unusedwrite checks for unused writes to the elements of a struct or array object.
  • usesgenerics checks for usage of generic features added in Go 1.18.
External linters

The list of analyzers was taken from the golangci-lint and then each analyzer was checked and imported if it provides an object of the Analyzer type.

  • asciicheck checks that your code does not contain non-ASCII identifiers.
  • bidichk checks for dangerous unicode character sequences.
  • bodyclose checks whether res.Body is correctly closed.
  • checkcompilerdirectives checks that go compiler directives (//go: comments) are valid and catch easy mistakes.
  • checknoglobals check that no globals are present in Go code.
  • containedctx detects struct contained context.Context field. This is discouraged technique in favour of passing context as first argument of method or function.
  • contextcheck checks whether the function uses a non-inherited context, which will result in a broken call link.
  • cyclop calculates cyclomatic complexities of functions or packages in Go source code.
  • dupword checks for duplicate words in the source code (usually miswritten).
  • durationcheck detects cases where two time.Duration values are being multiplied in possibly erroneous ways.
  • err113 checks the errors handling expressions.
  • errcheck checks for unchecked errors in go programs.
  • errchkjson checks types passed to the json encoding functions. Reports unsupported types and reports occurrences where the check for the returned error can be omitted.
  • 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 is a simple query string checker in Query function.
  • exhaustive checks exhaustiveness of switch statements of enum-like constants in Go source code.
  • exhaustruct finds structures with uninitialized fields.
  • exportloopref finds exporting pointers for loop variables.
  • forbidigo forbids usage of particular identifiers.
  • forcetypeassert finds type assertions which did forcely.
  • gci controls golang package import order and makes it always deterministic.
  • ginkgolinter enforces some standards while using the ginkgo and gomega packages.
  • gocognit calculates cognitive complexities of functions in Go source code. A measurement of how hard does the code is intuitively to understand.
  • gosmopolitan checks your Go codebase for code smells that may prove to be hindrance to internationalization ("i18n") and/or localization ("l10n").
  • gofumpt enforce a stricter format than gofmt, while being backwards compatible.
  • goprintffuncname checks that printf-like functions are named with f at the end.
  • grouper analyzes expression groups.
  • ineffassign detects ineffectual assignments in Go code. An assignment is ineffectual if the variable assigned is not thereafter used.
  • interfacebloat checks length of interface.
  • ireturn accept interfaces, return concrete types.
  • loggercheck checks the odd number of key and value pairs for common logger libraries.
  • maintidx measures the maintainability index of each function.
  • makezero finds slice declarations that are not initialized with zero length and are later used with append.
  • mirror suggests use of alternative functions/methods in order to gain performance boosts by avoiding unnecessary []byte/string conversion calls.
  • mnd or magic_number detects magic numbers.
  • musttag checks that exported fields of a struct passed to a Marshal-like function are annotated with the relevant tag.
  • nilerr finds code which returns nil even though it checks that error is not nil.
  • nilnil checks that there is no simultaneous return of nil error and an invalid value.
  • nlreturn requires a new line before return and branch statements except when the return is alone inside a statement group (such as an if statement) to increase code clarity.
  • noctx finds sending http request without context.Context.
  • nonamedreturns reports all named returns.
  • nosprintfhostport checks that sprintf is not used to construct a host:port combination in a URL.
  • paralleltest checks that the t.Parallel gets called for the test method and for the range of test cases within the test.
  • predeclared finds code that overrides one of Go's predeclared identifiers (new, make, append, uint, etc.).
  • reassign detects when reassigning a top-level variable in another package.
  • rowserrcheck checks whether sql.Rows.Err is correctly checked.
  • ruleguard or go-critic is the most opinionated Go source code linter.
  • sqlclosecheck checks if SQL rows/statements are closed. Unclosed rows and statements may cause DB connection pool exhaustion.
  • tagalign aligns and sorts tags in Go struct. It can make the struct more readable and easier to maintain.
  • tenv detects using os.Setenv instead of t.Setenv since Go1.17.
  • testableexamples
  • testpackage checks if examples are testable (have an expected output).
  • thelper detects golang test helpers without t.Helper() call. Also, it checks the consistency of test helpers and has similar checks for benchmarks and TB interface.
  • tparallel finds inappropriate usage of t.Parallel() method in your Go test codes.
  • unparam reports unused function parameters and results in your code.
  • unused finds unused code, works with go v1.19 or older.
  • usestdlibvars detects the possibility to use variables/constants from the Go standard library.
  • varnamelen checks that the length of a variable's name matches its usage scope.
  • wastedassign finds wasted assignment statements.
  • zerologlint detects the wrong usage of zerolog that a user forgets to dispatch zerolog.Event with Send or Msg function, in which case nothing will be logged.

Some other linters

License

MIT licensed. See the bundled LICENSE file for more details.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
gci
Package gci integrates the [gci](https://github.com/daixiang0/gci) linter wrapping gci.Analyzer in order to provide the Suggested Fixes A lot of code has been copied from the gci/pkg/analyzer package.
Package gci integrates the [gci](https://github.com/daixiang0/gci) linter wrapping gci.Analyzer in order to provide the Suggested Fixes A lot of code has been copied from the gci/pkg/analyzer package.
unparam
Package unparam integrates the [unparam](https://github.com/mvdan/unparam) linter
Package unparam integrates the [unparam](https://github.com/mvdan/unparam) linter
unused
Package unused integrates the [unused](https://github.com/dominikh/go-tools/tree/master/unused) linter
Package unused integrates the [unused](https://github.com/dominikh/go-tools/tree/master/unused) linter

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL