Add static analyzer to discourage use of panic() (#15075)

* Implement static analysis to prevent panics

* Add nopanic to nogo

* Fix violations and add exclusions

Fix violations and add exclusions for all

* Changelog fragment

* Use pass.Report instead of pass.Reportf

* Remove strings.ToLower for checking init method name

* Add exclusion for herumi init

* Move api/client/beacon template function to init and its own file

* Fix nopanic testcase
This commit is contained in:
Preston Van Loon
2025-03-19 13:04:15 -05:00
committed by GitHub
parent 16d5abd21b
commit 2aa52fb56a
74 changed files with 329 additions and 104 deletions

View File

@@ -27,11 +27,12 @@ func (pq priorityQueue) Swap(i, j int) {
pq[j].index = j
}
// Push a LeakyBucket to priorityQueue
func (pq *priorityQueue) Push(x interface{}) {
n := len(*pq)
b, ok := x.(*LeakyBucket)
if !ok {
panic(fmt.Sprintf("%T", x))
panic(fmt.Sprintf("%T", x)) // lint:nopanic -- This method should be improved. High risk for misuse!
}
b.index = n
*pq = append(*pq, b)