Skip to content

Commit

Permalink
adds usage of revive as third party library (#653)
Browse files Browse the repository at this point in the history
  • Loading branch information
chavacava committed Mar 20, 2022
1 parent 1c28383 commit 5f6f0eb
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -537,9 +537,11 @@ Current supported version of the standard is [SARIF-v2.1.0](https://docs.oasis-o

The tool can be extended with custom rules or formatters. This section contains additional information on how to implement such.

**To extend the linter with a custom rule or a formatter you'll have to push it to this repository or fork it**. This is due to the limited `-buildmode=plugin` support which [works only on Linux (with known issues)](https://golang.org/pkg/plugin/).
To extend the linter with a custom rule you can push it to this repository or use `revive` as a library (see below)

### Custom Rule
To add a custom formatter you'll have to push it to this repository or fork it. This is due to the limited `-buildmode=plugin` support which [works only on Linux (with known issues)](https://golang.org/pkg/plugin/).

### Writing a Custom Rule

Each rule needs to implement the `lint.Rule` interface:

Expand Down Expand Up @@ -568,6 +570,36 @@ With the snippet above we:

A sample rule implementation can be found [here](/rule/argument-limit.go).

#### Using `revive` as a library
If a rule is specific to your use case
(i.e. it is not a good candidate to be added to `revive`'s rule set) you can add it to your own linter using `revive` as linting engine.

The following code shows how to use `revive` in your own application.
In the example only one rule is added (`myRule`), of course, you can add as many as you need to.
Your rules can be configured programmatically or with the standard `revive` configuration file.
The full rule set of `revive` is also actionable by your application.

```go
package main

import (
"github.com/mgechev/revive/cli"
"github.com/mgechev/revive/lint"
)

func main() {
cli.RunRevive(cli.NewExtraRule(&myRule{}, lint.RuleConfig{}))
}

type myRule struct{}

func (f myRule) Name() string {
return "myRule"
}

func (f myRule) Apply(*lint.File, lint.Arguments) []lint.Failure { ... }
```

### Custom Formatter

Each formatter needs to implement the following interface:
Expand Down

0 comments on commit 5f6f0eb

Please sign in to comment.