-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
110 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright 2024 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// Package fillswitch defines an Analyzer that fills missing cases for type | ||
// switches and switches over named types. | ||
// | ||
// # Analyzer fillswitch | ||
// | ||
// fillswitch: check for missing cases in type switches or switches over named | ||
// types. | ||
// | ||
// This analyzer detects type switches or switches over named types that are | ||
// missing cases and provides a code action to fill those in. | ||
// | ||
// If the switch statement is over a named type, it will suggest cases for all | ||
// const values that are assignable to the named type. | ||
// | ||
// type T int | ||
// const ( | ||
// A T = iota | ||
// B | ||
// C | ||
// ) | ||
// | ||
// var t T | ||
// switch t { | ||
// case A: | ||
// } | ||
// | ||
// This analyzer will suggest a fix to fill in the remaining cases: | ||
// | ||
// var t T | ||
// switch t { | ||
// case A: | ||
// case B: | ||
// case C: | ||
// } | ||
// | ||
// If the switch statement is over type of an interface, it will suggest cases for all types | ||
// that implement the interface. | ||
// | ||
// type I interface { | ||
// M() | ||
// } | ||
// | ||
// type T struct{} | ||
// func (t *T) M() {} | ||
// | ||
// type E struct{} | ||
// func (e *E) M() {} | ||
// | ||
// var i I | ||
// switch i.(type) { | ||
// case *T: | ||
// } | ||
// | ||
// The analyzer will suggest a fix to fill in the remaining cases: | ||
// | ||
// var i I | ||
// switch i.(type) { | ||
// case *T: | ||
// case *E: | ||
// } | ||
// | ||
// The analyzer will only suggest cases for types that are defined on the same | ||
// package as the switch statement, or for types that are exported; and it will | ||
// not suggest any case if the switch handles the default case. | ||
package fillswitch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters