golang-linter

module
v0.0.0-...-2d1bb3d Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2024 License: MIT

README ΒΆ

golang-linter

  • errcheck - Check unchecked errors in Go code. These unchecked errors can be critical bugs in some cases.
  • goimports - Check import statements are formatted according to the 'goimport' command. Reformat imports in autofix mode.
  • revive - Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. what can do
  • govet - Vet examines Go source code and reports suspicious constructs. It is roughly the same as 'go vet' and uses its passes.
  • staticcheck - It's a set of rules from staticcheck.

Checks:

Custom PA
  • Variable usage with mutex check - possible with tags ad CFG. Highlighting: WARNING (cause of accuracy?)
  • Null interface call check - possible with CFG. Highlighting: WARNING (cause of accuracy?)
  • Cast interface to type check - possible with AST (golang-linter should check that first var is interface). Highlighting: WARNING (cause of accuracy?). !ATTENTION! res = a.(b) valid for checker if b implement a. Need TypeCheck? UPD: Detected by existing linters
UBER
Performance
  1. StrConv instead fmt - possible with AST. Highlighting: ERROR. Grade: 😍. Status: test
  2. String to byte repeating avoid - possible with AST (we just want to find "str to byte" in cycle)? Highlighting: WARNING (cause of accuracy?). Status: test
  3. Map capacity - possible with AST. Highlighting: WARNING (cause of "try") Grade: 😍. Status: not implemented
Guidelines
  1. Pointers to Interfaces - possible with AST (pointer variable decl + assignment with new(...) or we need a TypeCheck info for resolve expressions?)? Highlighting: WARNING (cause of "usually"). Status: not implemented
  2. Verify Interface Compliance - possible with AST (just find custom interface and decl with casting it to null)? Highlighting: ERROR (or it is not important?). Status: not implemented
  3. Receivers and Interfaces - possible with TypeCheck info (we should resolve expression type?)?. Highlighting: ERROR. Status: not implemented
  4. Zero-value Mutexes are Valid - possible with AST. Highlighting: ERROR. Grade: 😍. Status: test
  5. Copy Slices and Maps at Boundaries - possible with ??? (I think with AST we can check fact that input and output variables was copied or not, but if we create copies in some call - AST useless, it should be CFG analysis). Highlighting: WARNING (cause of accuracy?) Status: not implemented
  6. Defer to Clean Up - possible with AST? We can just find usages of Unlock and Close operation outside defer. Highlighting: WARNING (cause of accuracy?). Grade: 😍. Status: draft
  7. Channel Size is One or None - possible with AST. Highlighting: WARNING (cause of "usually"). Grade: 😍. Status: test
  8. Start Enums at One - possible with AST. Highlighting: WARNING (cause of "usually"). Grade: 😍. Status: test
  9. Use "time" to handle time - impossible. We can't detect places where Int/Float... use like Time. We can try to detect write Time.time to Json without specific tag, but it is doubtful.
  10. Errors - possible with AST. Highlighting: WARNING (cause of accuracy). We can check error.New() outside VarDecl and fmt.Errorf outside Struct, but it may be useless. Grade: 😐
  11. Error wrapping - I don't understand example. I think they mean just apply context to error if possible. It looks like impossible for detection.
  12. Error naming - Possible with AST. Highlighting: Error (because we can?). Grade: 😍.
  13. Handle Errors Once - Possible with AST but better with CFG. All we want is check log error with return in one scope? Highlighting: WARNING (cause of accuracy). Grade: 😐.
  14. Handle Type Assertion Failures - possible with AST. Highlighting: WARNING (cause of optional?). Grade: 😍. Status: test
  15. Don't Panic - possible with AST. Highlighting: Error. Grade: 😍. Status: test
  16. Use go.uber.org/atomic - possible with AST. We need detect types from this and suggest to use uber atomic. Highlighting: WARNING (cause of optional?). Grade: 😐-😍.
  17. Avoid Mutable Globals - possible with AST? Detect global var declaration is enough. Highlighting: WARNING (cause of "usually"). Grade: 😍. Status: test
  18. Avoid Embedding Types in Public Structs - Possible with AST but a more complex than other AST tasks. We need to find structures that use other structures from our project and check that property declared? I think I'm wrong. Highlighting: WARNING (cause of accuracy). Grade: 😐
  19. Avoid Using Built-In Names - possible with AST? I don't know how look go parser rules, but it may be very easy. Highlighting: Error. Grade: 😍. Status: may be ready in default linters.
  20. Avoid init() - possible with AST. Highlighting: WARNING (cause of optional?). Grade: 😍.
  21. Exit in Main - possible with AST. Highlighting: Error. Grade: 😍.
  22. Exit Main Once possible with AST. Highlighting: WARNING (cause of "if possible"). Grade: 😍.
  23. Use field tags in marshaled structs - for this task we need to get types (struct) of variables and find these structs. Go ast/cfg hold this data? Highlighting: WARNING (cause of accuracy). Grade: 😐.
  24. Don't fire-and-forget goroutines - may be possible with AST, but I think it is confusing task. Highlighting: WARNING (cause of accuracy). Grade: 😐.
  25. No goroutines in init() - possible with AST. Highlighting: Error. Grade: 😍.
Style

Highlighting: WARNING (cause of it is style?). All rules need to check default realization in golangci-lint

  1. Avoid overly long lines - 99 chars < IntelliJ default limit for line. Possible with readLines) Grade: 😍. Status: need to check default linter!
  2. Be Consistent - general recommendation
  3. Group Similar Declarations - partly possible with AST (last subrule). Grade: 😍.
  4. Import Group Ordering - possible with AST. Already in golangci-lint? Grade: 😐. Status: need to check default linter!
  5. Package Names - possible with AST. Already in golangci-lint (partly). Grade: 😍. Status: need to check default linter!
  6. Function Names - possible with AST. Already in golangci-lint? Grade: 😍. Status: need to check default linter!
  7. Import Aliasing - possible with AST, but we need to library sources.
    Grade: 😐.
  8. Function Grouping and Ordering - I think it is possible with AST, because we need only approximate order of intra-procedure execution, but CFG more correct. Grade: 😐.
  9. Reduce Nesting - partly possible with CFG. Grade: 😐.
  10. Unnecessary Else - possible with CFG (mb AST). Grade: 😐.
  11. Top-level Variable Declarations - potential possible with AST, but I think we can't support this right now - for stable work we should check type of any expression or identifier. Grade: ☹️.
  12. Prefix Unexported Globals with _ - possible with AST, but we need to analyze all project files for collect import. Grade: 😐.
  13. Embedding in Structs - possible with AST. Grade: 😍.
  14. Local Variable Declarations - possible with AST, but exist cases where the default value is clearer when the var keyword is used.
  15. nil is a valid slice - look like possible with AST, but I am not understand completely
  16. Reduce Scope of Variables - possible with CFG. Grade: ☹️.
  17. Avoid Naked Parameters - possible with AST but optional
  18. Use Raw String Literals to Avoid Escaping - possible with AST. Grade: 😍.
  19. Use Field Names to Initialize Structs - possible with AST. Grade: 😍.
  20. Omit Zero Value Fields in Structs - possible with AST. Grade: 😍.
  21. Use var for Zero Value Structs - possible with AST. Grade: 😍.
  22. Initializing Struct References - possible with AST. Grade: 😍.
  23. Initializing Maps - partly possible with AST. Full coverage of rule with CFG.
  24. Format Strings outside Printf - possible with CFG (mb AST). Grade: 😐.
  25. Naming Printf-style Functions - I think it is impossible to check that functions is printf-style
Patterns
  1. Test tables
  2. Functional Options

Jump to

Keyboard shortcuts

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