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
_Description_: This rule warns on some common mistakes when using `defer` statement. It currently alerts on the following situations:
276
277
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|
| 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|
285
286
286
287
These gotchas are described [here](https://blog.learngoprogramming.com/gotchas-of-defer-in-go-1-8d070894cb01)
287
288
288
289
_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`:
289
290
290
291
```toml
291
292
[rule.defer]
292
-
arguments=[["call-chain","loop"]]
293
+
arguments = [["call-chain","loop"]]
293
294
```
294
295
295
296
## dot-imports
@@ -402,44 +403,42 @@ Example:
402
403
arguments = ["make"]
403
404
```
404
405
405
-
406
406
## enforce-repeated-arg-type-style
407
407
408
-
**Description**: This rule is designed to maintain consistency in the declaration
408
+
_Description_: This rule is designed to maintain consistency in the declaration
409
409
of repeated argument and return value types in Go functions. It supports three styles:
410
410
'any', 'short', and 'full'. The 'any' style is lenient and allows any form of type
411
411
declaration. The 'short' style encourages omitting repeated types for conciseness,
412
412
whereas the 'full' style mandates explicitly stating the type for each argument
413
413
and return value, even if they are repeated, promoting clarity.
414
414
415
-
**Configuration (1)**: (string) as a single string, it configures both argument
415
+
_Configuration (1)_: (string) as a single string, it configures both argument
416
416
and return value styles. Accepts 'any', 'short', or 'full' (default: 'any').
417
417
418
-
**Configuration (2)**: (map[string]any) as a map, allows separate configuration
418
+
_Configuration (2)_: (map[string]any) as a map, allows separate configuration
419
419
for function arguments and return values. Valid keys are "funcArgStyle" and
420
420
"funcRetValStyle", each accepting 'any', 'short', or 'full'. If a key is not
421
421
specified, the default value of 'any' is used.
422
422
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,
424
424
it flags instances where types are omitted in repeated arguments or return values.
425
425
For 'short' style, it highlights opportunities to omit repeated types for brevity.
426
426
Incorrect or unknown configuration values will result in an error.
_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`.
922
924
923
925
_Configuration_: N/A
924
926
925
927
## useless-break
926
928
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.
928
930
Therefore, inserting a `break` at the end of a case clause has no effect.
929
931
930
932
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