This document explains how to build, test, and develop features for revive.
Clone the project:
git clone [email protected]:mgechev/revive.git
cd revive
In order to build the project run:
make build
The command will produce the revive
binary in the root of the project.
If you want to develop a new rule, follow as an example the already existing rules in the rule package.
Each rule needs to implement the lint.Rule
interface:
type Rule interface {
Name() string
Apply(*File, Arguments) []Failure
}
All rules with a configuration must implement lint.ConfigurableRule
interface:
type ConfigurableRule interface {
Configure(Arguments) error
}
The Arguments
type is an alias of the type []any
. The arguments of the rule are passed from the configuration file.
Let's suppose we have developed a rule called BanStructNameRule
which disallow us to name a structure with a given identifier. We can set the banned identifier by using the TOML configuration file:
[rule.ban-struct-name]
arguments = ["Foo"]
With the snippet above we:
- Enable the rule with the name
ban-struct-name
. TheName()
method of our rule should return a string that matchesban-struct-name
. - Configure the rule with the argument
Foo
. The list of arguments will be passed toApply(*File, Arguments)
together with the target file we're linting currently.
A sample rule implementation can be found here.
If you want to develop a new formatter, follow as an example the already existing formatters in the formatter package.
All formatters should implement the following interface:
type Formatter interface {
Format(<-chan Failure, RulesConfig) (string, error)
Name() string
}