Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions simple/s1034/s1034.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,28 @@ var SCAnalyzer = lint.InitializeAnalyzer(&lint.Analyzer{
Doc: &lint.RawDocumentation{
Title: `Use result of type assertion to simplify cases`,
Since: "2019.2",
Text: `
When using the type of a variable in a switch statement, the type of the variable is inferred from the case condition.

The following

switch o.(type) {
case string:
a = o.(string)
case int:
b = o.(int)
}

can be simplified as

switch o.(type) {
case string:
a = o
case int:
b = o
}

as the type of o has been established within the context of the case statement.`,
MergeIf: lint.MergeIfAny,
},
})
Expand Down