module
0.0.0-20240612221214-2d1bb3d3a696
Repository: https://github.com/belehovegor/golang-linter.git
Documentation: pkg.go.dev
# 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 ifb
implementa
. Need TypeCheck? UPD: Detected by existing linters
UBER
Performance
- StrConv instead fmt - possible with AST. Highlighting: ERROR. Grade: đ. Status: test
- 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
- Map capacity - possible with AST. Highlighting: WARNING (cause of "try") Grade: đ. Status: not implemented
Guidelines
- 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
- 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
- Receivers and Interfaces - possible with TypeCheck info (we should resolve expression type?)?. Highlighting: ERROR. Status: not implemented
- Zero-value Mutexes are Valid - possible with AST. Highlighting: ERROR. Grade: đ. Status: test
- 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
- 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 - Channel Size is One or None - possible with AST. Highlighting: WARNING (cause of "usually"). Grade: đ. Status: test
- Start Enums at One - possible with AST. Highlighting: WARNING (cause of "usually"). Grade: đ. Status: test
- Use "time" to handle time -
impossible. We can't detect places where
Int/Float...
use likeTime
. We can try to detect writeTime.time
to Json without specific tag, but it is doubtful. - 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: đ
- Error wrapping - I don't understand example. I think they mean just apply context to error if possible. It looks like impossible for detection.
- Error naming - Possible with AST. Highlighting: Error (because we can?). Grade: đ.
- 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: đ.
- Handle Type Assertion Failures - possible with AST. Highlighting: WARNING (cause of optional?). Grade: đ. Status: test
- Don't Panic - possible with AST. Highlighting: Error. Grade: đ. Status: test
- 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: đ-đ.
- Avoid Mutable Globals - possible with
AST? Detect global
var
declaration is enough. Highlighting: WARNING (cause of "usually"). Grade: đ. Status: test - 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: đ
- 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.
- Avoid init() - possible with AST. Highlighting: WARNING (cause of optional?). Grade: đ.
- Exit in Main - possible with AST. Highlighting: Error. Grade: đ.
- Exit Main Once possible with AST. Highlighting: WARNING (cause of "if possible"). Grade: đ.
- 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: đ.
- Don't fire-and-forget goroutines - may be possible with AST, but I think it is confusing task. Highlighting: WARNING (cause of accuracy). Grade: đ.
- 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
- Avoid overly long lines - 99 chars < IntelliJ default limit for line. Possible with readLines) Grade: đ. Status: need to check default linter!
- Be Consistent - general recommendation
- Group Similar Declarations - partly possible with AST (last subrule). Grade: đ.
- Import Group Ordering - possible with AST. Already in golangci-lint? Grade: đ. Status: need to check default linter!
- Package Names - possible with AST. Already in golangci-lint (partly). Grade: đ. Status: need to check default linter!
- Function Names - possible with AST. Already in golangci-lint? Grade: đ. Status: need to check default linter!
- Import Aliasing -
possible with AST, but we need to library sources.
Grade: đ. - 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: đ.
- Reduce Nesting - partly possible with CFG. Grade: đ.
- Unnecessary Else - possible with CFG (mb AST). Grade: đ.
- 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: âšī¸.
- Prefix Unexported Globals with _ -
possible with AST, but we need to analyze all project files for collect
import
. Grade: đ. - Embedding in Structs - possible with AST. Grade: đ.
- Local Variable Declarations - possible with AST, but exist cases where the default value is clearer when the var keyword is used.
- nil is a valid slice - look like possible with AST, but I am not understand completely
- Reduce Scope of Variables - possible with CFG. Grade: âšī¸.
- Avoid Naked Parameters - possible with AST but optional
- Use Raw String Literals to Avoid Escaping - possible with AST. Grade: đ.
- Use Field Names to Initialize Structs - possible with AST. Grade: đ.
- Omit Zero Value Fields in Structs - possible with AST. Grade: đ.
- Use var for Zero Value Structs - possible with AST. Grade: đ.
- Initializing Struct References - possible with AST. Grade: đ.
- Initializing Maps - partly possible with AST. Full coverage of rule with CFG.
- Format Strings outside Printf - possible with CFG (mb AST). Grade: đ.
- Naming Printf-style Functions - I think it is impossible to check that functions is printf-style
Patterns
# Packages
No description provided by the author