Skip to content

Commit 1117372

Browse files
authored
update doc (#1203)
* update doc * review updates * review updates
1 parent 77616f0 commit 1117372

File tree

2 files changed

+27
-36
lines changed

2 files changed

+27
-36
lines changed

DEVELOPING.md

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,9 @@ Clone the project:
1010
git clone [email protected]:mgechev/revive.git
1111
cd revive
1212
```
13-
14-
In order to fetch all the dependencies run:
15-
16-
```bash
17-
make install
18-
```
19-
2013
## Build
2114

2215
In order to build the project run:
23-
2416
```bash
2517
make build
2618
```
@@ -31,14 +23,38 @@ The command will produce the `revive` binary in the root of the project.
3123

3224
If you want to develop a new rule, follow as an example the already existing rules in the [rule package](https://github.com/mgechev/revive/tree/master/rule).
3325

34-
All rules should implement the following interface:
35-
26+
Each rule needs to implement the `lint.Rule` interface:
3627
```go
3728
type Rule interface {
3829
Name() string
3930
Apply(*File, Arguments) []Failure
4031
}
4132
```
33+
All rules with a configuration must implement `lint.ConfigurableRule` interface:
34+
```go
35+
type ConfigurableRule interface {
36+
Configure(Arguments) error
37+
}
38+
```
39+
40+
The `Arguments` type is an alias of the type `[]any`. The arguments of the rule are passed from the configuration file.
41+
42+
#### Example
43+
44+
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:
45+
46+
```toml
47+
[rule.ban-struct-name]
48+
arguments = ["Foo"]
49+
```
50+
51+
With the snippet above we:
52+
53+
- Enable the rule with the name `ban-struct-name`. The `Name()` method of our rule should return a string that matches `ban-struct-name`.
54+
- Configure the rule with the argument `Foo`. The list of arguments will be passed to `Apply(*File, Arguments)` together with the target file we're linting currently.
55+
56+
A sample rule implementation can be found [here](/rule/argument_limit.go).
57+
4258

4359
## Development of formatters
4460

README.md

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -636,32 +636,7 @@ To add a custom formatter you'll have to push it to this repository or fork it.
636636

637637
### Writing a Custom Rule
638638

639-
Each rule needs to implement the `lint.Rule` interface:
640-
641-
```go
642-
type Rule interface {
643-
Name() string
644-
Apply(*File, Arguments) []Failure
645-
}
646-
```
647-
648-
The `Arguments` type is an alias of the type `[]interface{}`. The arguments of the rule are passed from the configuration file.
649-
650-
#### Example
651-
652-
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:
653-
654-
```toml
655-
[rule.ban-struct-name]
656-
arguments = ["Foo"]
657-
```
658-
659-
With the snippet above we:
660-
661-
- Enable the rule with the name `ban-struct-name`. The `Name()` method of our rule should return a string that matches `ban-struct-name`.
662-
- Configure the rule with the argument `Foo`. The list of arguments will be passed to `Apply(*File, Arguments)` together with the target file we're linting currently.
663-
664-
A sample rule implementation can be found [here](/rule/argument_limit.go).
639+
See [DEVELOPING.md](./DEVELOPING.md) for instructions on how to write a custom rule.
665640

666641
#### Using `revive` as a library
667642

0 commit comments

Comments
 (0)