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
Allow whitelist for the context parameter check (#616)
* Allow a whitelist for the context parameter check
This allows users to configure a set of types that may appear before
`context.Context`.
Notably, I think this rule is useful for allowing the `*testing.T` type
to come before `context.Context`, though there may be other uses (such
as putting a tracer before it, etc).
See #605 for a little more context on this.
Fixes#605
* Save a level of indentation in context-as-arg validation
We can unindent if we make the above check more specific
* refactoring taking into account chavacava's review
Co-authored-by: chavacava <[email protected]>
Copy file name to clipboardExpand all lines: RULES_DESCRIPTIONS.md
+21-12Lines changed: 21 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -187,7 +187,16 @@ _Configuration_: N/A
187
187
188
188
_Description_: By [convention](https://github.com/golang/go/wiki/CodeReviewComments#contexts), `context.Context` should be the first parameter of a function. This rule spots function declarations that do not follow the convention.
189
189
190
-
_Configuration_: N/A
190
+
_Configuration_:
191
+
192
+
*`allowTypesBefore` : (string) comma-separated list of types that may be before 'context.Context'
_Description_: In GO it is idiomatic to minimize nesting statements, a typical example is to avoid if-then-else constructions. This rule spots constructions like
254
263
```go
255
264
if cond {
256
-
// do something
265
+
// do something
257
266
} else {
258
267
// do other thing
259
268
return ...
@@ -263,7 +272,7 @@ that can be rewritten into more idiomatic:
263
272
```go
264
273
if ! cond {
265
274
// do other thing
266
-
return ...
275
+
return ...
267
276
}
268
277
269
278
// do something
@@ -315,8 +324,8 @@ _Description_: Exported function and methods should have comments. This warns on
315
324
316
325
More information [here](https://github.com/golang/go/wiki/CodeReviewComments#doc-comments)
317
326
318
-
_Configuration_: ([]string) rule flags.
319
-
Please notice that without configuration, the default behavior of the rule is that of its `golint` counterpart.
327
+
_Configuration_: ([]string) rule flags.
328
+
Please notice that without configuration, the default behavior of the rule is that of its `golint` counterpart.
320
329
Available flags are:
321
330
322
331
*_checkPrivateReceivers_ enables checking public methods of private types
@@ -426,8 +435,8 @@ Example:
426
435
```
427
436
## import-shadowing
428
437
429
-
_Description_: In GO it is possible to declare identifiers (packages, structs,
430
-
interfaces, parameters, receivers, variables, constants...) that conflict with the
438
+
_Description_: In GO it is possible to declare identifiers (packages, structs,
439
+
interfaces, parameters, receivers, variables, constants...) that conflict with the
431
440
name of an imported package. This rule spots identifiers that shadow an import.
432
441
433
442
_Configuration_: N/A
@@ -517,7 +526,7 @@ _Configuration_: N/A
517
526
518
527
## range-val-address
519
528
520
-
_Description_: Range variables in a loop are reused at each iteration. This rule warns when assigning the address of the variable, passing the address to append() or using it in a map.
529
+
_Description_: Range variables in a loop are reused at each iteration. This rule warns when assigning the address of the variable, passing the address to append() or using it in a map.
521
530
522
531
_Configuration_: N/A
523
532
@@ -535,7 +544,7 @@ Even if possible, redefining these built in names can lead to bugs very difficul
535
544
_Configuration_: N/A
536
545
537
546
## string-of-int
538
-
_Description_: explicit type conversion `string(i)` where `i` has an integer type other than `rune` might behave not as expected by the developer (e.g. `string(42)` is not `"42"`). This rule spot that kind of suspicious conversions.
547
+
_Description_: explicit type conversion `string(i)` where `i` has an integer type other than `rune` might behave not as expected by the developer (e.g. `string(42)` is not `"42"`). This rule spot that kind of suspicious conversions.
539
548
540
549
_Configuration_: N/A
541
550
@@ -548,7 +557,7 @@ _Configuration_: Each argument is a slice containing 2-3 strings: a scope, a reg
548
557
549
558
1. The first string defines a scope. This controls which string literals the regex will apply to, and is defined as a function argument. It must contain at least a function name (`core.WriteError`). Scopes may optionally contain a number specifying which argument in the function to check (`core.WriteError[1]`), as well as a struct field (`core.WriteError[1].Message`, only works for top level fields). Function arguments are counted starting at 0, so `[0]` would refer to the first argument, `[1]` would refer to the second, etc. If no argument number is provided, the first argument will be used (same as `[0]`).
550
559
551
-
2. The second string is a regular expression (beginning and ending with a `/` character), which will be used to check the string literals in the scope.
560
+
2. The second string is a regular expression (beginning and ending with a `/` character), which will be used to check the string literals in the scope.
552
561
553
562
3. The third string (optional) is a message containing the purpose for the regex, which will be used in lint errors.
554
563
@@ -663,8 +672,8 @@ _Configuration_: N/A
663
672
664
673
## useless-break
665
674
666
-
_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.
667
-
Therefore, inserting a `break` at the end of a case clause has no effect.
675
+
_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.
676
+
Therefore, inserting a `break` at the end of a case clause has no effect.
668
677
669
678
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