41 lines
855 B
Go
41 lines
855 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"sort"
|
|
)
|
|
|
|
// spectralCounts reads spectral's JSON report: [errors, warnings, info+hint].
|
|
// An empty report is a clean lint ("[]"); anything not a JSON array means
|
|
// spectral did not produce its report, which is an error (could_not_run).
|
|
func spectralCounts(report string) ([3]int, error) {
|
|
var out [3]int
|
|
var results []struct {
|
|
Severity int `json:"severity"`
|
|
}
|
|
if err := json.Unmarshal([]byte(report), &results); err != nil {
|
|
return out, fmt.Errorf("spectral report unreadable: %w", err)
|
|
}
|
|
for _, r := range results {
|
|
switch r.Severity {
|
|
case 0:
|
|
out[0]++
|
|
case 1:
|
|
out[1]++
|
|
default:
|
|
out[2]++
|
|
}
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func sortedKeys(m map[string]string) []string {
|
|
out := make([]string, 0, len(m))
|
|
for k := range m {
|
|
out = append(out, k)
|
|
}
|
|
sort.Strings(out)
|
|
return out
|
|
}
|