* refactor: extract shared code for linting if-else chains
The rules "early-return", "indent-error-flow" and
"superfluous-else" have a similar structure. This
moves the common logic for classifying if-else chains
to a common package.
A few side benefits:
- "early-return" now handles os.Exit/log.Panicf/etc
- "superfluous-else" now handles (builtin) panic
- "superfluous-else" and "indent-error-flow" now handle if/else
chains with 2+ "if" branches
* internal/ifelse: style fixes, renames, spelling
This fixes a false positive reported by revive on the following:
select {}
This is a way to block the program indefinitely.
It is used in cases like:
- Running a long-running server in a background thread
and blocking `main` from exiting until the application dies.
This is something you might do if your process has
multiple servers/listeners in the same process.
```go
go grpcListenAndServe()
go httpListenAndServe()
go logFlusher()
select {}
```
- In programs compiled to WASM to prevent the application from exiting,
so that the Javascript components may interact with it.
```go
func main() {
js.Global().Set("foo", foo)
select {}
}
```
Without this, one may see an error like,
"Error: Go program has already exited"
As a workaround, these programs can block forever
by receiving from a throwaway channel (`<-make(chan struct{})`),
but `select {}` is still a completely valid way of doing this,
so supporting it makes sense.
The issue was previously reported in #698 but was closed
because the author was satisfied with a `//nolint` comment.
Now that this rule is part of the default rule set (#799)
the case for addressing the false positive is stronger.
Resolves#804
* added comment-spacing rule for revive
* added test for comment-spacings rule
* adds comment-spacings rule to the configuration
* renames the source file to match rule name
* adds some tests
* refactor Comment-Spacings Rule to remove whiteList and avoid Panic at empty comment
* refactoring and adds rule configuration
* adds rule documentation
Co-authored-by: chavacava <salvadorcavadini+github@gmail.com>
* Yet more bad defer / recover patterns
`recover()` is an eternal font of excitement.
* demonstrating another flavor of failure
* removing leftover code
* update documentation
* removes test not related to the rule itself
Co-authored-by: chavacava <salvadorcavadini+github@gmail.com>
* Check whether the tag name is duplicate or not
* - minor refactoring
- continues checking tag even if name is repeated
* adds test cases for duplicated tag names
* adds test case with two tag types (json & yaml)
* Fix allow the same tag name in different tag key
* fix checks on protobuf tag names
Co-authored-by: chavacava <salvadorcavadini+github@gmail.com>
* Allow to customize user functions in rule `error-strings`
* Rollback the Available Rules table format in README
* adds memoization of the rule's configuration
Co-authored-by: chavacava <salvadorcavadini+github@gmail.com>
Setting the entire file AST as the node causes golangci-lint to print
the entire file source as the context, and line and column numbers set
to 1. Point to the package name node instead.
Closes#688
* Fixes issue #619 imports-blacklist support regex
* refactors method name and error message
* restores original test cases
Co-authored-by: chavacava <salvadorcavadini+github@gmail.com>