Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/THE108/enumlinter
Enum linter for enumerated types in Go
https://github.com/THE108/enumlinter
enum enumerated-types go golang linter
Last synced: about 1 month ago
JSON representation
Enum linter for enumerated types in Go
- Host: GitHub
- URL: https://github.com/THE108/enumlinter
- Owner: THE108
- License: mit
- Created: 2017-05-25T10:11:20.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-05-25T15:01:14.000Z (over 7 years ago)
- Last Synced: 2024-08-03T17:10:02.616Z (5 months ago)
- Topics: enum, enumerated-types, go, golang, linter
- Language: Go
- Size: 6.84 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Enum linter
===========Enum linter checks:
- incorrect type or basic literal is assigned to enumerated type value
- switch clause is not exhaustive (in progress)
Example
=======
```
type Enum intconst (
Apple Enum = iota
Pear
Banana
)...
var f Enum
f = Apple
f = 10
f = Enum(55.)fmt.Print(f)
ch := make(chan int, 1)
ch <- 123chEnum := make(chan Enum, 1)
chEnum <- 321m := map[string]Enum{
"aaa": 1234,
"bbb": Banana,
}s := S{
Fruit1: 88,
Fruit2: Pear,
Fruit3: f,
Fruit4: Enum(GetInt()),
Fruit5: Enum(<-ch),
Sub: subS{
Fruit: 11,
},
SubSub1: subsub{
Sub: subS{
Fruit: 22,
},
},
SubSub2: subsub{
Sub: subS{
Fruit: Enum(44),
},
},
}if f == Enum(22) {
fmt.Println("equal")
}if s.SubSub2.Sub.Fruit == 1 {
fmt.Println("equal")
}
```Run
===
```
$ enumlinter -type Enum ./enum.go
``````
./testdata/enum_assignment.go:40:6: Enum type constant must be used instead of a basic literal 10
./testdata/enum_assignment.go:41:6: ToEnum() like func must be used instead of a type casting Enum(55.)
./testdata/enum_assignment.go:49:12: Enum type constant must be used instead of a basic literal 321
./testdata/enum_assignment.go:52:10: Enum type constant must be used instead of a basic literal 1234
./testdata/enum_assignment.go:57:11: Enum type constant must be used instead of a basic literal 88
./testdata/enum_assignment.go:60:11: ToEnum() like func must be used instead of a type casting Enum(GetInt())
./testdata/enum_assignment.go:61:11: ToEnum() like func must be used instead of a type casting Enum(<-ch)
./testdata/enum_assignment.go:63:11: Enum type constant must be used instead of a basic literal 11
./testdata/enum_assignment.go:67:12: Enum type constant must be used instead of a basic literal 22
./testdata/enum_assignment.go:72:12: ToEnum() like func must be used instead of a type casting Enum(44)
./testdata/enum_assignment.go:77:10: ToEnum() like func must be used instead of a type casting Enum(22)
./testdata/enum_assignment.go:81:28: Enum type constant must be used instead of a basic literal 1
```