Skip to content

Commit

Permalink
Update the documentation for comment annotations
Browse files Browse the repository at this point in the history
Fix #1
  • Loading branch information
mgechev committed Jun 1, 2018
1 parent a6c7415 commit a4da536
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
23 changes: 23 additions & 0 deletions fixtures/disable-annotations.go
Original file line number Diff line number Diff line change
@@ -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 changes: 12 additions & 0 deletions test/disable-annotations_test.go
Original file line number Diff line number Diff line change
@@ -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{})
}

0 comments on commit a4da536

Please sign in to comment.