Files
wehub-resource-sync bf9395e022
CI / license-header (push) Has been skipped
CI / e2e-dry-run (push) Has been skipped
CI / fast-gate (push) Failing after 0s
Test PR Label Logic / test-pr-labels (push) Failing after 1s
Skill Format Check / check-format (push) Failing after 2s
CI / security (push) Failing after 5s
CI / unit-test (push) Has been skipped
CI / lint (push) Has been skipped
CI / script-test (push) Has been skipped
CI / deterministic-gate (push) Has been skipped
CI / coverage (push) Has been skipped
CI / results (push) Has been cancelled
CI / deadcode (push) Has been cancelled
CI / e2e-live (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:22:54 +08:00

59 lines
1.2 KiB
Go

// Copyright (c) 2026 Lark Technologies Pte. Ltd.
// SPDX-License-Identifier: MIT
package report
import (
"fmt"
"io"
"sort"
)
type Action string
const (
ActionReject Action = "REJECT"
ActionLabel Action = "LABEL"
ActionWarning Action = "WARNING"
)
type Diagnostic struct {
Rule string `json:"rule"`
Action Action `json:"action"`
File string `json:"file"`
Line int `json:"line"`
Message string `json:"message"`
Suggestion string `json:"suggestion,omitempty"`
SubjectType string `json:"subject_type,omitempty"`
CommandPath string `json:"command_path,omitempty"`
FlagName string `json:"flag_name,omitempty"`
}
func Print(w io.Writer, ds []Diagnostic) {
sort.SliceStable(ds, func(i, j int) bool {
if ds[i].File != ds[j].File {
return ds[i].File < ds[j].File
}
if ds[i].Line != ds[j].Line {
return ds[i].Line < ds[j].Line
}
return ds[i].Rule < ds[j].Rule
})
for _, d := range ds {
fmt.Fprintf(w, "%s:%d: [%s/%s] %s\n", d.File, d.Line, d.Action, d.Rule, d.Message)
if d.Suggestion != "" {
fmt.Fprintf(w, " hint: %s\n", d.Suggestion)
}
}
}
func ExitCode(ds []Diagnostic) int {
for _, d := range ds {
if d.Action == ActionReject {
return 1
}
}
return 0
}