Skip to content

Commit 1bb03d7

Browse files
authored
docs: missing item and homogeneous style (#994)
1 parent 4242f24 commit 1bb03d7

File tree

1 file changed

+55
-53
lines changed

1 file changed

+55
-53
lines changed

RULES_DESCRIPTIONS.md

+55-53
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ List of all available rules.
3030
- [empty-block](#empty-block)
3131
- [empty-lines](#empty-lines)
3232
- [enforce-map-style](#enforce-map-style)
33+
- [enforce-repeated-arg-type-style](#enforce-repeated-arg-type-style)
3334
- [enforce-slice-style](#enforce-slice-style)
3435
- [error-naming](#error-naming)
3536
- [error-return](#error-return)
@@ -113,7 +114,7 @@ Example:
113114

114115
```toml
115116
[rule.argument-limit]
116-
arguments =[4]
117+
arguments = [4]
117118
```
118119

119120
## atomic
@@ -132,7 +133,7 @@ Example:
132133

133134
```toml
134135
[rule.banned-characters]
135-
arguments =["Ω","Σ","σ"]
136+
arguments = ["Ω","Σ","σ"]
136137
```
137138
## bare-return
138139

@@ -172,7 +173,7 @@ Example:
172173

173174
```toml
174175
[rule.cognitive-complexity]
175-
arguments =[7]
176+
arguments = [7]
176177
```
177178
## comment-spacings
178179

@@ -192,7 +193,7 @@ Example:
192193

193194
```toml
194195
[rule.comment-spacings]
195-
arguments =["mypragma:", "+optional"]
196+
arguments = ["mypragma:", "+optional"]
196197
```
197198
## comments-density
198199

@@ -204,7 +205,7 @@ Example:
204205

205206
```toml
206207
[rule.comments-density]
207-
arguments =[15]
208+
arguments = [15]
208209
```
209210

210211
## confusing-naming
@@ -256,7 +257,7 @@ Example:
256257

257258
```toml
258259
[rule.cyclomatic]
259-
arguments =[3]
260+
arguments = [3]
260261
```
261262
## datarace
262263

@@ -274,22 +275,22 @@ _Configuration_: N/A
274275

275276
_Description_: This rule warns on some common mistakes when using `defer` statement. It currently alerts on the following situations:
276277

277-
| name | description |
278-
|------|-------------|
279-
| call-chain| even if deferring call-chains of the form `foo()()` is valid, it does not helps code understanding (only the last call is deferred)|
280-
|loop | deferring inside loops can be misleading (deferred functions are not executed at the end of the loop iteration but of the current function) and it could lead to exhausting the execution stack |
281-
| method-call| deferring a call to a method can lead to subtle bugs if the method does not have a pointer receiver|
282-
| recover | calling `recover` outside a deferred function has no effect|
283-
| immediate-recover | calling `recover` at the time a defer is registered, rather than as part of the deferred callback. e.g. `defer recover()` or equivalent.|
284-
| return | returning values form a deferred function has no effect|
278+
| name | description |
279+
|-------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
280+
| call-chain | even if deferring call-chains of the form `foo()()` is valid, it does not helps code understanding (only the last call is deferred) |
281+
| loop | deferring inside loops can be misleading (deferred functions are not executed at the end of the loop iteration but of the current function) and it could lead to exhausting the execution stack |
282+
| method-call | deferring a call to a method can lead to subtle bugs if the method does not have a pointer receiver |
283+
| recover | calling `recover` outside a deferred function has no effect |
284+
| immediate-recover | calling `recover` at the time a defer is registered, rather than as part of the deferred callback. e.g. `defer recover()` or equivalent. |
285+
| return | returning values form a deferred function has no effect |
285286

286287
These gotchas are described [here](https://blog.learngoprogramming.com/gotchas-of-defer-in-go-1-8d070894cb01)
287288

288289
_Configuration_: by default all warnings are enabled but it is possible selectively enable them through configuration. For example to enable only `call-chain` and `loop`:
289290

290291
```toml
291292
[rule.defer]
292-
arguments=[["call-chain","loop"]]
293+
arguments = [["call-chain","loop"]]
293294
```
294295

295296
## dot-imports
@@ -402,44 +403,42 @@ Example:
402403
arguments = ["make"]
403404
```
404405

405-
406406
## enforce-repeated-arg-type-style
407407

408-
**Description**: This rule is designed to maintain consistency in the declaration
408+
_Description_: This rule is designed to maintain consistency in the declaration
409409
of repeated argument and return value types in Go functions. It supports three styles:
410410
'any', 'short', and 'full'. The 'any' style is lenient and allows any form of type
411411
declaration. The 'short' style encourages omitting repeated types for conciseness,
412412
whereas the 'full' style mandates explicitly stating the type for each argument
413413
and return value, even if they are repeated, promoting clarity.
414414

415-
**Configuration (1)**: (string) as a single string, it configures both argument
415+
_Configuration (1)_: (string) as a single string, it configures both argument
416416
and return value styles. Accepts 'any', 'short', or 'full' (default: 'any').
417417

418-
**Configuration (2)**: (map[string]any) as a map, allows separate configuration
418+
_Configuration (2)_: (map[string]any) as a map, allows separate configuration
419419
for function arguments and return values. Valid keys are "funcArgStyle" and
420420
"funcRetValStyle", each accepting 'any', 'short', or 'full'. If a key is not
421421
specified, the default value of 'any' is used.
422422

423-
**Note**: The rule applies checks based on the specified styles. For 'full' style,
423+
_Note_: The rule applies checks based on the specified styles. For 'full' style,
424424
it flags instances where types are omitted in repeated arguments or return values.
425425
For 'short' style, it highlights opportunities to omit repeated types for brevity.
426426
Incorrect or unknown configuration values will result in an error.
427427

428-
**Example (1)**:
428+
Example (1):
429429

430430
```toml
431431
[rule.enforce-repeated-arg-type-style]
432-
arguments = ["short"]
432+
arguments = ["short"]
433433
```
434434

435-
**Example (2):**
435+
Example (2):
436436

437437
```toml
438438
[rule.enforce-repeated-arg-type-style]
439-
arguments = [ { funcArgStyle = "full", funcRetValStyle = "short" } ]
439+
arguments = [{ funcArgStyle = "full", funcRetValStyle = "short" }]
440440
```
441441

442-
443442
## enforce-slice-style
444443

445444
_Description_: This rule enforces consistent usage of `make([]type, 0)`, `[]type{}`, or `var []type` for slice initialization.
@@ -459,7 +458,6 @@ Example:
459458
arguments = ["make"]
460459
```
461460

462-
463461
## exported
464462

465463
_Description_: Exported function and methods should have comments. This warns on undocumented exported functions and methods.
@@ -478,7 +476,7 @@ Example:
478476

479477
```toml
480478
[rule.exported]
481-
arguments =["checkPrivateReceivers","disableStutteringCheck"]
479+
arguments = ["checkPrivateReceivers", "disableStutteringCheck"]
482480
```
483481

484482
## file-header
@@ -491,7 +489,7 @@ Example:
491489

492490
```toml
493491
[rule.file-header]
494-
arguments =["This is the text that must appear at the top of source files."]
492+
arguments = ["This is the text that must appear at the top of source files."]
495493
```
496494

497495
## flag-parameter
@@ -512,7 +510,7 @@ Example:
512510

513511
```toml
514512
[rule.function-result-limit]
515-
arguments =[3]
513+
arguments = [3]
516514
```
517515

518516
## function-length
@@ -525,7 +523,7 @@ Example:
525523

526524
```toml
527525
[rule.function-length]
528-
arguments =[10,0]
526+
arguments = [10, 0]
529527
```
530528
Will check for functions exceeding 10 statements and will not check the number of lines of functions
531529

@@ -554,14 +552,14 @@ _Description_: Aligns with Go's naming conventions, as outlined in the official
554552
the principles of good package naming. Users can follow these guidelines by default or define a custom regex rule.
555553
Importantly, aliases with underscores ("_") are always allowed.
556554

557-
_Configuration_ (1): (string) as plain string accepts allow regexp pattern for aliases (default: ^[a-z][a-z0-9]{0,}$).
555+
_Configuration_ (1): (`string`) as plain string accepts allow regexp pattern for aliases (default: `^[a-z][a-z0-9]{0,}$`).
558556

559-
_Configuration_ (2): (map[string]string) as a map accepts two values:
557+
_Configuration_ (2): (`map[string]string`) as a map accepts two values:
560558
* for a key "allowRegex" accepts allow regexp pattern
561559
* for a key "denyRegex deny regexp pattern
562560

563561
_Note_: If both `allowRegex` and `denyRegex` are provided, the alias must comply with both of them.
564-
If none are given (i.e. an empty map), the default value ^[a-z][a-z0-9]{0,}$ for allowRegex is used.
562+
If none are given (i.e. an empty map), the default value `^[a-z][a-z0-9]{0,}$` for allowRegex is used.
565563
Unknown keys will result in an error.
566564

567565
Example (1):
@@ -575,12 +573,12 @@ Example (2):
575573

576574
```toml
577575
[rule.import-alias-naming]
578-
arguments = [ { allowRegex = "^[a-z][a-z0-9]{0,}$", denyRegex = '^v\d+$' } ]
576+
arguments = [{ allowRegex = "^[a-z][a-z0-9]{0,}$", denyRegex = '^v\d+$' }]
579577
```
580578

581579
## import-shadowing
582580

583-
_Description_: In GO it is possible to declare identifiers (packages, structs,
581+
_Description_: In Go it is possible to declare identifiers (packages, structs,
584582
interfaces, parameters, receivers, variables, constants...) that conflict with the
585583
name of an imported package. This rule spots identifiers that shadow an import.
586584

@@ -595,8 +593,8 @@ _Configuration_: block-list of package names (or regular expression package name
595593
Example:
596594

597595
```toml
598-
[imports-blocklist]
599-
arguments =["crypto/md5", "crypto/sha1", "crypto/**/pkix"]
596+
[rule.imports-blocklist]
597+
arguments = ["crypto/md5", "crypto/sha1", "crypto/**/pkix"]
600598
```
601599

602600
## increment-decrement
@@ -634,10 +632,11 @@ Example:
634632

635633
```toml
636634
[rule.line-length-limit]
637-
arguments =[80]
635+
arguments = [80]
638636
```
639637

640638
## max-control-nesting
639+
641640
_Description_: Warns if nesting level of control structures (`if-then-else`, `for`, `switch`) exceeds a given maximum.
642641

643642
_Configuration_: (int) maximum accepted nesting level of control structures (defaults to 5)
@@ -646,10 +645,9 @@ Example:
646645

647646
```toml
648647
[max-control-nesting]
649-
arguments =[3]
648+
arguments = [3]
650649
```
651650

652-
653651
## max-public-structs
654652

655653
_Description_: Packages declaring too many public structs can be hard to understand/use,
@@ -663,7 +661,7 @@ Example:
663661

664662
```toml
665663
[rule.max-public-structs]
666-
arguments =[3]
664+
arguments = [3]
667665
```
668666

669667
## modifies-parameter
@@ -694,10 +692,13 @@ _Configuration_: N/A
694692

695693
Example:
696694

697-
if isGenerated(content) && !config.IgnoreGeneratedHeader {
695+
```go
696+
if isGenerated(content) && !config.IgnoreGeneratedHeader {
697+
```
698698
Swap left and right side :
699-
700-
if !config.IgnoreGeneratedHeader && isGenerated(content) {
699+
```go
700+
if !config.IgnoreGeneratedHeader && isGenerated(content) {
701+
```
701702
702703
## package-comments
703704
@@ -768,7 +769,8 @@ Example:
768769
arguments = [
769770
["core.WriteError[1].Message", "/^([^A-Z]|$)/", "must not start with a capital letter"],
770771
["fmt.Errorf[0]", "/(^|[^\\.!?])$/", "must not end in punctuation"],
771-
["panic", "/^[^\\n]*$/", "must not contain line breaks"]]
772+
["panic", "/^[^\\n]*$/", "must not contain line breaks"],
773+
]
772774
```
773775
774776
## string-of-int
@@ -789,7 +791,7 @@ To accept the `inline` option in JSON tags (and `outline` and `gnu` in BSON tags
789791
790792
```toml
791793
[rule.struct-tag]
792-
arguments = ["json,inline","bson,outline,gnu"]
794+
arguments = ["json,inline", "bson,outline,gnu"]
793795
```
794796
795797
## superfluous-else
@@ -835,9 +837,9 @@ foo, _ := bar(.*Baz).
835837
836838
Example:
837839
838-
```yaml
840+
```toml
839841
[rule.unchecked-type-assertion]
840-
arguments = [{acceptIgnoredAssertionResult=true}]
842+
arguments = [{acceptIgnoredAssertionResult=true}]
841843
```
842844
843845
## unconditional-recursion
@@ -868,7 +870,7 @@ Example:
868870
869871
```toml
870872
[unhandled-error]
871-
arguments =["os\.(Create|WriteFile|Chmod)", "fmt\.Print", "myFunction", "net\..*", "bytes\.Buffer\.Write"]
873+
arguments = ["os\.(Create|WriteFile|Chmod)", "fmt\.Print", "myFunction", "net\..*", "bytes\.Buffer\.Write"]
872874
```
873875
## unnecessary-stmt
874876
@@ -890,7 +892,7 @@ _Configuration_: Supports arguments with single of `map[string]any` with option
890892
891893
```toml
892894
[rule.unused-parameter]
893-
Arguments = [ { allowRegex = "^_" } ]
895+
Arguments = [{ allowRegex = "^_" }]
894896
```
895897
896898
allows any names started with `_`, not just `_` itself:
@@ -907,7 +909,7 @@ _Configuration_: Supports arguments with single of `map[string]any` with option
907909
908910
```toml
909911
[rule.unused-receiver]
910-
Arguments = [ { allowRegex = "^_" } ]
912+
Arguments = [{ allowRegex = "^_" }]
911913
```
912914
913915
allows any names started with `_`, not just `_` itself:
@@ -918,13 +920,13 @@ func (_my *MyStruct) SomeMethod() {} // matches rule
918920
919921
## use-any
920922
921-
_Description_: Since GO 1.18, `interface{}` has an alias: `any`. This rule proposes to replace instances of `interface{}` with `any`.
923+
_Description_: Since Go 1.18, `interface{}` has an alias: `any`. This rule proposes to replace instances of `interface{}` with `any`.
922924
923925
_Configuration_: N/A
924926
925927
## useless-break
926928
927-
_Description_: This rule warns on useless `break` statements in case clauses of switch and select statements. GO, unlike other programming languages like C, only executes statements of the selected case while ignoring the subsequent case clauses.
929+
_Description_: This rule warns on useless `break` statements in case clauses of switch and select statements. Go, unlike other programming languages like C, only executes statements of the selected case while ignoring the subsequent case clauses.
928930
Therefore, inserting a `break` at the end of a case clause has no effect.
929931
930932
Because `break` statements are rarely used in case clauses, when switch or select statements are inside a for-loop, the programmer might wrongly assume that a `break` in a case clause will take the control out of the loop.

0 commit comments

Comments
 (0)