mirror of
https://github.com/mgechev/revive.git
synced 2025-03-25 21:29:16 +02:00
parent
a6c7415c67
commit
a4da5361d2
25
README.md
25
README.md
@ -64,6 +64,31 @@ revive -config revive.toml -exclude file1.go -exclude file2.go -formatter friend
|
||||
* The output will be formatted with the `friendly` formatter
|
||||
* The linter will analyze `github.com/mgechev/revive` and the files in `package`
|
||||
|
||||
### Comment Annotations
|
||||
|
||||
Using comments, you can disable the linter for the entire file or only range of lines:
|
||||
|
||||
```go
|
||||
//revive:disable
|
||||
|
||||
func Public() {}
|
||||
//revive:enable
|
||||
```
|
||||
|
||||
The snippet above, will disable `revive` between the `revive:disable` and `revive:enable` comments. If you skip `revive:enable`, the linter will be disabled for the rest of the file.
|
||||
|
||||
You can do the same on a rule level. In case you want to disable only a particular rule, you can use:
|
||||
|
||||
```go
|
||||
//revive:disable:unexported-return
|
||||
func Public() private {
|
||||
return private
|
||||
}
|
||||
//revive:enable:unexported-return
|
||||
```
|
||||
|
||||
This way, `revive` will not warn you for that you're returning an object of an unexported type, from an exported function.
|
||||
|
||||
### Configuration
|
||||
|
||||
`revive` can be configured with a TOML file. Here's a sample configuration with explanation for the individual properties:
|
||||
|
23
fixtures/disable-annotations.go
Normal file
23
fixtures/disable-annotations.go
Normal file
@ -0,0 +1,23 @@
|
||||
package fixtures
|
||||
|
||||
//revive:disable
|
||||
func Public1() {
|
||||
}
|
||||
|
||||
//revive:enable
|
||||
|
||||
func Public2() { // MATCH /exported function Public2 should have comment or be unexported/
|
||||
}
|
||||
|
||||
//revive:disable:exported
|
||||
func Public3() {
|
||||
}
|
||||
|
||||
//revive:enable:exported
|
||||
|
||||
//revive:disable:random
|
||||
|
||||
func Public4() { // MATCH /exported function Public4 should have comment or be unexported/
|
||||
}
|
||||
|
||||
//revive:enable:random
|
12
test/disable-annotations_test.go
Normal file
12
test/disable-annotations_test.go
Normal file
@ -0,0 +1,12 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mgechev/revive/lint"
|
||||
"github.com/mgechev/revive/rule"
|
||||
)
|
||||
|
||||
func TestDisabledAnnotations(t *testing.T) {
|
||||
testRule(t, "disable-annotations", &rule.ExportedRule{}, &lint.RuleConfig{})
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user