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
Copy file name to clipboardExpand all lines: README.md
+28-28Lines changed: 28 additions & 28 deletions
Original file line number
Diff line number
Diff line change
@@ -125,20 +125,20 @@ Since the default behavior of `revive` is compatible with `golint`, without prov
125
125
`revive` supports a `-config` flag whose value should correspond to a TOML file describing which rules to use for `revive`'s linting. If not provided, `revive` will try to use a global config file (assumed to be located at `$HOME/revive.toml`). Otherwise, if no configuration TOML file is found then `revive` uses a built-in set of default linting rules.
126
126
127
127
### Docker
128
-
A volume needs to be mounted to share the current repository with the container.
128
+
A volume must be mounted to share the current repository with the container.
129
129
Please refer to the [bind mounts Docker documentation](https://docs.docker.com/storage/bind-mounts/)
130
130
131
131
```bash
132
-
docker run -v "$(pwd)":/var/<repository> ghcr.io/mgechev/revive:v1.1.2-next -config /var/<repository>/revive.toml -formatter stylish ./var/kidle/...
132
+
docker run -v "$(pwd)":/var/<repository> ghcr.io/mgechev/revive:v1.3.7 -config /var/<repository>/revive.toml -formatter stylish ./var/kidle/...
133
133
```
134
134
135
135
-`-v` is for the volume
136
-
-`ghcr.io/mgechev/revive:v1.1.2-next` is the image name and its version corresponding to `revive` command
136
+
-`ghcr.io/mgechev/revive:v1.3.7` is the image name and its version corresponds to `revive` command
137
137
- The provided flags are the same as the binary usage.
138
138
139
139
### Bazel
140
140
141
-
If you want to use revive with Bazel, take a look at the [rules](https://github.com/atlassian/bazel-tools/tree/master/gorevive) that Atlassian maintains.
141
+
If you want to use revive with Bazel, look at the [rules](https://github.com/atlassian/bazel-tools/tree/master/gorevive) that Atlassian maintains.
142
142
143
143
### Text Editors
144
144
@@ -208,14 +208,14 @@ Please notice that if no particular configuration is provided, `revive` will beh
208
208
209
209
`revive` accepts the following command line parameters:
210
210
211
-
- `-config [PATH]`- path to config file in TOML format, defaults to `$HOME/revive.toml` if present.
211
+
- `-config [PATH]`- path to the config file in TOML format, defaults to `$HOME/revive.toml` if present.
212
212
- `-exclude [PATTERN]`- pattern for files/directories/packages to be excluded for linting. You can specify the files you want to exclude for linting either as package name (i.e. `github.com/mgechev/revive`), list them as individual files (i.e. `file.go`), directories (i.e. `./foo/...`), or any combination of the three.
213
213
- `-formatter [NAME]` - formatter to be used for the output. The currently available formatters are:
214
214
215
215
- `default`- will output the failures the same way that `golint` does.
216
216
- `json`- outputs the failures in JSON format.
217
-
- `ndjson`- outputs the failures as stream in newline delimited JSON (NDJSON) format.
218
-
- `friendly`- outputs the failures when found. Shows summary of all the failures.
217
+
- `ndjson`- outputs the failures as a stream in newline delimited JSON (NDJSON) format.
218
+
- `friendly`- outputs the failures when found. Shows the summary of all the failures.
219
219
- `stylish`- formats the failures in a table. Keep in mind that it doesn't stream the output so it might be perceived as slower compared to others.
220
220
- `checkstyle`- outputs the failures in XML format compatible with that of Java's [Checkstyle](https://checkstyle.org/).
221
221
- `-max_open_files`- maximum number of open files at the same time. Defaults to unlimited.
Using comments, you can disable the linter for the entire file or only range of lines:
239
+
Using comments, you can disable the linter for the entire file or only a range of lines:
240
240
241
241
```go
242
242
//revive:disable
@@ -259,7 +259,7 @@ func Public() private {
259
259
//revive:enable:unexported-return
260
260
```
261
261
262
-
This way, `revive` will not warn you for that you're returning an object of an unexported type, from an exported function.
262
+
This way, `revive` will not warn you that you're returning an object of an unexported type, from an exported function.
263
263
264
264
You can document why you disable the linter by adding a trailing text in the directive, for example
265
265
@@ -285,7 +285,7 @@ in the configuration. You can set the severity (defaults to _warning_) of the vi
285
285
286
286
### Configuration
287
287
288
-
`revive` can be configured with a TOML file. Here's a sample configuration with explanation for the individual properties:
288
+
`revive` can be configured with a TOML file. Here's a sample configuration with an explanation of the individual properties:
289
289
290
290
```toml
291
291
# When set to false, ignores files with "GENERATED" header, similar to golint
@@ -298,7 +298,7 @@ severity = "warning"
298
298
# with less than 0.8 confidence will be ignored.
299
299
confidence = 0.8
300
300
301
-
# Sets the error code for failures with severity "error"
301
+
# Sets the error code for failures with the "error" severity
302
302
errorCode = 0
303
303
304
304
# Sets the error code for failures with severity "warning"
@@ -323,7 +323,7 @@ To enable all available rules you need to add:
323
323
enableAllRules = true
324
324
```
325
325
326
-
This will enable all available rules no matter of what rules are named in the configuration file.
326
+
This will enable all available rules no matter what rules are named in the configuration file.
327
327
328
328
To disable a rule, you simply mark it as disabled in the configuration.
329
329
For example:
@@ -333,7 +333,7 @@ For example:
333
333
Disabled = true
334
334
```
335
335
When enabling all rules you still need/can provide specific configurations for rules.
336
-
The following files is an example configuration were all rules are enabled, with exception to those that are explicitly disabled, and some rules are configured with particular arguments:
336
+
The following file is an example configuration where all rules are enabled, except for those that are explicitly disabled, and some rules are configured with particular arguments:
337
337
338
338
```toml
339
339
severity = "warning"
@@ -429,7 +429,7 @@ warningCode = 0
429
429
430
430
You also can setup custom excludes for each rule.
431
431
432
-
It's alternative for global `-exclude` program arg.
432
+
It's an alternative for the global `-exclude` program arg.
433
433
434
434
```toml
435
435
ignoreGeneratedHeader = false
@@ -444,17 +444,17 @@ warningCode = 0
444
444
Exclude=["src/somepkg/*.go", "TEST"]
445
445
```
446
446
447
-
You can use following exclude patterns
447
+
You can use the following exclude patterns
448
448
449
449
1. full paths to files `src/pkg/mypkg/some.go`
450
450
2. globs `src/**/*.pb.go`
451
451
3. regexes (should have prefix ~) `~\.(pb|auto|generated)\.go$`
452
452
4. well-known `TEST` (same as `**/*_test.go`)
453
453
5. special cases:
454
-
a. `*` and `~` patterns exclude all files (same effect than disabling the rule)
454
+
a. `*` and `~` patterns exclude all files (same effect as disabling the rule)
455
455
b. `""` (empty) pattern excludes nothing
456
456
457
-
> NOTE: do not mess with `exclude` that can be used at top level of TOML file, that mean "exclude package patterns", not "exclude file patterns"
457
+
> NOTE: do not mess with `exclude` that can be used at the top level of TOML file, that means "exclude package patterns", not "exclude file patterns"
458
458
459
459
## Available Rules
460
460
@@ -539,7 +539,7 @@ List of all available rules. The rules ported from `golint` are left unchanged a
539
539
|[`enforce-slice-style`](./RULES_DESCRIPTIONS.md#enforce-slice-style)| string (defaults to "any") | Enforces consistent usage of `make([]type, 0)` or `[]type{}` for slice initialization. Does not affect `make(map[type]type, non_zero_len, or_non_zero_cap)` constructions. | no | no |
540
540
|[`enforce-repeated-arg-type-style`](./RULES_DESCRIPTIONS.md#enforce-repeated-arg-type-style)| string (defaults to "any") | Enforces consistent style for repeated argument and/or return value types. | no | no |
541
541
|[`max-control-nesting`](./RULES_DESCRIPTIONS.md#max-control-nesting)| int (defaults to 5) | Sets restriction for maximum nesting of control structures. | no | no |
542
-
|[`comments-density`](./RULES_DESCRIPTIONS.md#comments-density)| int (defaults to 0) | Enforces a minumum comment / code relation | no | no |
542
+
|[`comments-density`](./RULES_DESCRIPTIONS.md#comments-density)| int (defaults to 0) | Enforces a minimum comment / code relation | no | no |
543
543
544
544
545
545
## Configurable rules
@@ -555,7 +555,7 @@ This rule accepts two slices of strings, an allowlist and a blocklist of initial
555
555
arguments = [["ID"], ["VM"]]
556
556
```
557
557
558
-
This way, revive will not warn for identifier called `customId` but will warn that `customVm` should be called `customVM`.
558
+
This way, revive will not warn for an identifier called `customId` but will warn that `customVm` should be called `customVM`.
559
559
560
560
## Available Formatters
561
561
@@ -577,7 +577,7 @@ The default formatter produces the same output as `golint`.
577
577
578
578
### Plain
579
579
580
-
The plain formatter produces the same output as the default formatter and appends URL to the rule description.
580
+
The plain formatter produces the same output as the default formatter and appends the URL to the rule description.
581
581
582
582

583
583
@@ -616,7 +616,7 @@ The `Arguments` type is an alias of the type `[]interface{}`. The arguments of t
616
616
617
617
#### Example
618
618
619
-
Let's suppose we have developed a rule called `BanStructNameRule` which disallow us to name a structure with given identifier. We can set the banned identifier by using the TOML configuration file:
619
+
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:
620
620
621
621
```toml
622
622
[rule.ban-struct-name]
@@ -625,16 +625,16 @@ Let's suppose we have developed a rule called `BanStructNameRule` which disallow
625
625
626
626
With the snippet above we:
627
627
628
-
- Enable the rule with name `ban-struct-name`. The `Name()` method of our rule should return a string which matches `ban-struct-name`.
628
+
- Enable the rule with the name `ban-struct-name`. The `Name()` method of our rule should return a string that matches `ban-struct-name`.
629
629
- 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.
630
630
631
631
A sample rule implementation can be found [here](/rule/argument-limit.go).
632
632
633
633
#### Using `revive` as a library
634
634
If a rule is specific to your use case
635
-
(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.
635
+
(i.e. it is not a good candidate to be added to `revive`'s rule set) you can add it to your linter using `revive` as a linting engine.
636
636
637
-
The following code shows how to use `revive` in your own application.
637
+
The following code shows how to use `revive` in your application.
638
638
In the example only one rule is added (`myRule`), of course, you can add as many as you need to.
639
639
Your rules can be configured programmatically or with the standard `revive` configuration file.
640
640
The full rule set of `revive` is also actionable by your application.
You can still go further and use `revive` without its cli, as part of your library, or your own cli:
664
+
You can still go further and use `revive` without its CLI, as part of your library, or your CLI:
665
665
666
666
```go
667
667
package mylib
@@ -728,7 +728,7 @@ For a sample formatter, take a look at [this file](/formatter/json.go).
728
728
729
729
## Speed Comparison
730
730
731
-
Compared to `golint`, `revive` performs better because it lints the files for each individual rule into a separate goroutine. Here's a basic performance benchmark on MacBook Pro Early 2013 run on kubernetes:
731
+
Compared to `golint`, `revive` performs better because it lints the files for each individual rule into a separate goroutine. Here's a basic performance benchmark on MacBook Pro Early 2013 run on Kubernetes:
732
732
733
733
### golint
734
734
@@ -751,7 +751,7 @@ user 0m40.721s
751
751
sys 0m3.262s
752
752
```
753
753
754
-
Keep in mind that if you use rules which require type checking, the performance may drop to 2x faster than `golint`:
754
+
Keep in mind that if you use rules that require type checking, the performance may drop to 2x faster than `golint`:
755
755
756
756
```shell
757
757
# type checking enabled
@@ -762,7 +762,7 @@ user 2m6.708s
762
762
sys 0m17.192s
763
763
```
764
764
765
-
Currently, typechecking is enabled by default. If you want to run the linter without typechecking, remove all typed rules from the configuration file.
765
+
Currently, type-checking is enabled by default. If you want to run the linter without type-checking, remove all typed rules from the configuration file.
Failure: fmt.Sprintf("the file has a comment density of %2.f%% (%d comment lines for %d code lines) but expected a minimum of %d%%", density, commentsLines, statementsCount, r.minumumCommentsDensity),
56
+
Failure: fmt.Sprintf("the file has a comment density of %2.f%% (%d comment lines for %d code lines) but expected a minimum of %d%%", density, commentsLines, statementsCount, r.minimumCommentsDensity),
0 commit comments