Skip to content

Commit 5f6f0eb

Browse files
authored
adds usage of revive as third party library (#653)
1 parent 1c28383 commit 5f6f0eb

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

README.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,11 @@ Current supported version of the standard is [SARIF-v2.1.0](https://docs.oasis-o
537537

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

540-
**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/).
540+
To extend the linter with a custom rule you can push it to this repository or use `revive` as a library (see below)
541541

542-
### Custom Rule
542+
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/).
543+
544+
### Writing a Custom Rule
543545

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

@@ -568,6 +570,36 @@ With the snippet above we:
568570

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

573+
#### Using `revive` as a library
574+
If a rule is specific to your use case
575+
(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.
576+
577+
The following code shows how to use `revive` in your own application.
578+
In the example only one rule is added (`myRule`), of course, you can add as many as you need to.
579+
Your rules can be configured programmatically or with the standard `revive` configuration file.
580+
The full rule set of `revive` is also actionable by your application.
581+
582+
```go
583+
package main
584+
585+
import (
586+
"github.com/mgechev/revive/cli"
587+
"github.com/mgechev/revive/lint"
588+
)
589+
590+
func main() {
591+
cli.RunRevive(cli.NewExtraRule(&myRule{}, lint.RuleConfig{}))
592+
}
593+
594+
type myRule struct{}
595+
596+
func (f myRule) Name() string {
597+
return "myRule"
598+
}
599+
600+
func (f myRule) Apply(*lint.File, lint.Arguments) []lint.Failure { ... }
601+
```
602+
571603
### Custom Formatter
572604

573605
Each formatter needs to implement the following interface:

0 commit comments

Comments
 (0)