Enable linter for exhaustive coverage in enum switch statements#3641
Enable linter for exhaustive coverage in enum switch statements#3641
Conversation
| return nil, fmt.Errorf("run timed out: %s", run.State.StateMessage) | ||
|
|
||
| // TODO: handle other result states. | ||
| default: |
There was a problem hiding this comment.
There are a few more states we need to handle. This is the only real problem that this linter surfaced.
| } | ||
|
|
||
| // Infof creates a new info diagnostic. | ||
| func Infof(format string, args ...any) Diagnostics { |
There was a problem hiding this comment.
Turns out this wasn't used anywhere.
| dst.SetString(strconv.FormatFloat(src.MustFloat(), 'f', -1, 64)) | ||
| return nil | ||
| default: | ||
| // Fall through to the error case. |
There was a problem hiding this comment.
non-blocking / style question: should we just move error case inside default? then comment won't be needed.
There was a problem hiding this comment.
For most of the other types, there are other cases that also fall through to the error case.
If we move it into the default, we need to duplicate the error case into those other branches.
| switch kind { | ||
| case reflect.Struct, reflect.Map: | ||
| expectedJsonType = "object" | ||
| case reflect.Slice: |
There was a problem hiding this comment.
reflect.Array belongs here as well?
There was a problem hiding this comment.
That maps to fixed-size arrays. We don't use those anywhere to my knowledge (not for JSON marshalling/unmarshalling at least). The patch here matches the existing logic.
|
Changes
Linter will error for switch statements on an enum where not all enum values are covered.
The statement can still use a
default:clause to explicitly fall through.Why
Observation here: #3546 (comment)