* enforce-slice-style: Support nil declaration enforcement
Add support for enforcing nil slice declarations as recommended by both
the Go Code Review and Uber style guides.
This initial version is quite strict in that it also prevents using
empty literal and make-style slices in struct assignments and as
function arguments.
* Add more tests
* docs
* modifies-value-receiver: warn on slice or map
Assignments which index into the slice or map are already ignored on
line 72, and those where the whole receiver is slice or map on line 50.
We should not ignore assignments where the member variable is slice
or map.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
* Remove extra space
---------
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Co-authored-by: Denis Voytyuk <5462781+denisvmedia@users.noreply.github.com>
Add the ability to allow list of packages to be dot imported.
Add a new don-imports configuration:
* `allowedPackages`: (string) comma-separated list of allowed dot import packages
Example:
```toml
[rule.dot-imports]
arguments = [{ allowedPackages = "github.com/onsi/ginkgo/v2,github.com/onsi/gomega" }]
```
* 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>
Noticed during migration from our heavily modified "go-lint" to "revive" that there is an additional line printed. I am unsure that the convention for this project is on this, we do not allow adding such a call.
* Allow a whitelist for the context parameter check
This allows users to configure a set of types that may appear before
`context.Context`.
Notably, I think this rule is useful for allowing the `*testing.T` type
to come before `context.Context`, though there may be other uses (such
as putting a tracer before it, etc).
See #605 for a little more context on this.
Fixes#605
* Save a level of indentation in context-as-arg validation
We can unindent if we make the above check more specific
* refactoring taking into account chavacava's review
Co-authored-by: chavacava <salvadorcavadini+github@gmail.com>