You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -31,14 +23,38 @@ The command will produce the `revive` binary in the root of the project.
31
23
32
24
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).
33
25
34
-
All rules should implement the following interface:
35
-
26
+
Each rule needs to implement the `lint.Rule` interface:
36
27
```go
37
28
typeRuleinterface {
38
29
Name() string
39
30
Apply(*File, Arguments) []Failure
40
31
}
41
32
```
33
+
All rules with a configuration must implement `lint.ConfigurableRule` interface:
34
+
```go
35
+
typeConfigurableRuleinterface {
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).
Copy file name to clipboardExpand all lines: README.md
+1-26Lines changed: 1 addition & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -636,32 +636,7 @@ To add a custom formatter you'll have to push it to this repository or fork it.
636
636
637
637
### Writing a Custom Rule
638
638
639
-
Each rule needs to implement the `lint.Rule` interface:
640
-
641
-
```go
642
-
typeRuleinterface {
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.
0 commit comments