@@ -106,7 +106,7 @@ A volume must be mounted to share the current repository with the container.
106
106
Please refer to the [ bind mounts Docker documentation] ( https://docs.docker.com/storage/bind-mounts/ )
107
107
108
108
``` bash
109
- docker run -v " $( pwd) " :/var/< repository > ghcr.io/mgechev/revive:v1.3.7 -config /var/< repository > /revive.toml -formatter stylish ./var/kidle /...
109
+ docker run -v " $( pwd) " :/var/YOUR_REPOSITORY ghcr.io/mgechev/revive:v1.3.7 -config /var/YOUR_REPOSITORY /revive.toml -formatter stylish ./var/YOUR_REPOSITORY /...
110
110
```
111
111
112
112
- ` -v ` is for the volume
@@ -238,6 +238,7 @@ Using comments, you can disable the linter for the entire file or only a range o
238
238
//revive:disable
239
239
240
240
func Public() {}
241
+
241
242
//revive:enable
242
243
` ` `
243
244
@@ -251,8 +252,9 @@ You can do the same on a rule level. In case you want to disable only a particul
251
252
` ` ` go
252
253
//revive:disable:unexported-return
253
254
func Public() private {
254
- return private
255
+ return private
255
256
}
257
+
256
258
//revive:enable:unexported-return
257
259
` ` `
258
260
@@ -278,7 +280,7 @@ in the configuration. You can set the severity (defaults to _warning_) of the vi
278
280
279
281
` ` ` toml
280
282
[directive.specify-disable-reason]
281
- severity = "error"
283
+ severity = "error"
282
284
` ` `
283
285
284
286
# ## Configuration
@@ -305,11 +307,11 @@ warningCode = 0
305
307
# Configuration of the ` cyclomatic` rule. Here we specify that
306
308
# the rule should fail if it detects code with higher complexity than 10.
307
309
[rule.cyclomatic]
308
- arguments = [10]
310
+ arguments = [10]
309
311
310
312
# Sets the severity of the `package-comments` rule to "error".
311
313
[rule.package-comments]
312
- severity = "error"
314
+ severity = "error"
313
315
```
314
316
315
317
By default ` revive ` will enable only the linting rules that are named in the configuration file.
@@ -328,7 +330,7 @@ For example:
328
330
329
331
``` toml
330
332
[rule .line-length-limit ]
331
- Disabled = true
333
+ Disabled = true
332
334
```
333
335
334
336
When enabling all rules you still need/can provide specific configurations for rules.
@@ -346,29 +348,29 @@ enableAllRules = true
346
348
347
349
# Disabled rules
348
350
[rule .blank-imports ]
349
- Disabled = true
351
+ Disabled = true
350
352
[rule .file-header ]
351
- Disabled = true
353
+ Disabled = true
352
354
[rule .max-public-structs ]
353
- Disabled = true
355
+ Disabled = true
354
356
[rule .line-length-limit ]
355
- Disabled = true
357
+ Disabled = true
356
358
[rule .function-length ]
357
- Disabled = true
359
+ Disabled = true
358
360
[rule .banned-characters ]
359
- Disabled = true
361
+ Disabled = true
360
362
361
363
# Rule tuning
362
364
[rule .argument-limit ]
363
- Arguments = [5 ]
365
+ Arguments = [5 ]
364
366
[rule .cyclomatic ]
365
- Arguments = [10 ]
367
+ Arguments = [10 ]
366
368
[rule .cognitive-complexity ]
367
- Arguments = [7 ]
369
+ Arguments = [7 ]
368
370
[rule .function-result-limit ]
369
- Arguments = [3 ]
371
+ Arguments = [3 ]
370
372
[rule .error-strings ]
371
- Arguments = [" mypackage.Error" ]
373
+ Arguments = [" mypackage.Error" ]
372
374
```
373
375
374
376
### Default Configuration
@@ -440,9 +442,9 @@ errorCode = 0
440
442
warningCode = 0
441
443
442
444
[rule .blank-imports ]
443
- Exclude = [" **/*.pb.go" ]
445
+ Exclude = [" **/*.pb.go" ]
444
446
[rule .context-as-argument ]
445
- Exclude = [" src/somepkg/*.go" , " TEST" ]
447
+ Exclude = [" src/somepkg/*.go" , " TEST" ]
446
448
```
447
449
448
450
You can use the following exclude patterns
@@ -559,7 +561,7 @@ in `golint` but optionally, you can relax it (see [golint/lint/issues/89](https:
559
561
560
562
``` toml
561
563
[rule .var-naming ]
562
- arguments = [[" ID" ], [" VM" ]]
564
+ arguments = [[" ID" ], [" VM" ]]
563
565
```
564
566
565
567
This way, revive will not warn for an identifier called ` customId ` but will warn that ` customVm ` should be called ` customVM ` .
@@ -656,7 +658,9 @@ func (f myRule) Name() string {
656
658
return " myRule"
657
659
}
658
660
659
- func (f myRule ) Apply (*lint .File , lint .Arguments ) []lint .Failure { ... }
661
+ func (f myRule ) Apply (*lint .File , lint .Arguments ) []lint .Failure {
662
+ // ...
663
+ }
660
664
```
661
665
662
666
You can still go further and use ` revive ` without its CLI, as part of your library, or your CLI:
@@ -665,39 +669,39 @@ You can still go further and use `revive` without its CLI, as part of your libra
665
669
package mylib
666
670
667
671
import (
668
- " github.com/mgechev/revive/cli"
669
- " github.com/mgechev/revive/revivelib"
672
+ " github.com/mgechev/revive/config"
670
673
" github.com/mgechev/revive/lint"
674
+ " github.com/mgechev/revive/revivelib"
671
675
)
672
676
673
677
// Error checking removed for clarity
674
678
func LintMyFile (file string ) {
675
- conf , _ := config.GetConfig (" ../defaults.toml" )
679
+ conf , _ := config.GetConfig (" ../defaults.toml" )
676
680
677
681
revive , _ := revivelib.New (
678
- conf, // Configuration file
679
- true , // Set exit status
680
- 2048 , // Max open files
682
+ conf, // Configuration file
683
+ true , // Set exit status
684
+ 2048 , // Max open files
681
685
682
686
// Then add as many extra rules as you need
683
687
revivelib.NewExtraRule (&myRule{}, lint.RuleConfig {}),
684
688
)
685
689
686
690
failuresChan , err := revive.Lint (
687
- revivelib.Include (file),
688
- revivelib.Exclude (" ./fixtures" ),
689
- // You can use as many revivelib.Include or revivelib.Exclude as required
690
- )
691
- if err != nil {
692
- panic (" Shouldn't have failed: " + err.Error ())
693
- }
694
-
695
- // Now let's return the formatted errors
691
+ revivelib.Include (file),
692
+ revivelib.Exclude (" ./fixtures" ),
693
+ // You can use as many revivelib.Include or revivelib.Exclude as required
694
+ )
695
+ if err != nil {
696
+ panic (" Shouldn't have failed: " + err.Error ())
697
+ }
698
+
699
+ // Now let's return the formatted errors
696
700
failures , exitCode , _ := revive.Format (" stylish" , failuresChan)
697
701
698
- // failures is the string with all formatted lint error messages
699
- // exit code is 0 if no errors, 1 if errors (unless config options change it)
700
- // ... do something with them
702
+ // failures is the string with all formatted lint error messages
703
+ // exit code is 0 if no errors, 1 if errors (unless config options change it)
704
+ // ... do something with them
701
705
}
702
706
703
707
type myRule struct {}
@@ -706,7 +710,9 @@ func (f myRule) Name() string {
706
710
return " myRule"
707
711
}
708
712
709
- func (f myRule ) Apply (*lint .File , lint .Arguments ) []lint .Failure { ... }
713
+ func (f myRule ) Apply (*lint .File , lint .Arguments ) []lint .Failure {
714
+ // ...
715
+ }
710
716
```
711
717
712
718
### Custom Formatter
@@ -733,8 +739,8 @@ Here's a basic performance benchmark on MacBook Pro Early 2013 run on Kubernetes
733
739
734
740
### golint
735
741
736
- ``` shell
737
- time golint kubernetes/... > /dev/null
742
+ ``` zsh
743
+ $ time golint kubernetes/... > /dev/null
738
744
739
745
real 0m54.837s
740
746
user 0m57.844s
@@ -743,9 +749,9 @@ sys 0m9.146s
743
749
744
750
### revive's speed
745
751
746
- ``` shell
752
+ ``` zsh
747
753
# no type checking
748
- time revive -config untyped.toml kubernetes/... > /dev/null
754
+ $ time revive -config untyped.toml kubernetes/... > /dev/null
749
755
750
756
real 0m8.471s
751
757
user 0m40.721s
@@ -754,9 +760,9 @@ sys 0m3.262s
754
760
755
761
Keep in mind that if you use rules that require type checking, the performance may drop to 2x faster than ` golint ` :
756
762
757
- ``` shell
763
+ ``` zsh
758
764
# type checking enabled
759
- time revive kubernetes/... > /dev/null
765
+ $ time revive kubernetes/... > /dev/null
760
766
761
767
real 0m26.211s
762
768
user 2m6.708s
0 commit comments