Skip to content

Commit 50fc802

Browse files
authored
s1034: Add explanatory example
1 parent 31e1ee5 commit 50fc802

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

simple/s1034/s1034.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,28 @@ var SCAnalyzer = lint.InitializeAnalyzer(&lint.Analyzer{
2424
Doc: &lint.RawDocumentation{
2525
Title: `Use result of type assertion to simplify cases`,
2626
Since: "2019.2",
27+
Text: `
28+
When using the type of a variable in a switch statement, the type of the variable is inferred from the case condition.
29+
30+
The following
31+
32+
switch o.(type) {
33+
case string:
34+
a = o.(string)
35+
case int:
36+
b = o.(int)
37+
}
38+
39+
can be simplified as
40+
41+
switch o.(type) {
42+
case string:
43+
a = o
44+
case int:
45+
b = o
46+
}
47+
48+
as the type of o has been established within the context of the case statement.`,
2749
MergeIf: lint.MergeIfAny,
2850
},
2951
})

0 commit comments

Comments
 (0)