From 0365be53161fadb6b992b6fcef00dfa76c9c03ee Mon Sep 17 00:00:00 2001 From: coanor Date: Fri, 13 Oct 2023 00:30:00 +0800 Subject: [PATCH] save --- promlinter.go | 7 ++++++- promlinter_test.go | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/promlinter.go b/promlinter.go index eda237d..8ffbb79 100644 --- a/promlinter.go +++ b/promlinter.go @@ -4,6 +4,7 @@ import ( "fmt" "go/ast" "go/token" + "log" "sort" "strconv" "strings" @@ -149,7 +150,7 @@ func RunLint(fs *token.FileSet, files []*ast.File, s Setting) []Issue { } // lint metrics - for idx, mfp := range v.metrics { + for _, mfp := range v.metrics { problems, err := promlint.NewWithMetricFamilies([]*dto.MetricFamily{mfp.MetricFamily}).Lint() if err != nil { panic(err) @@ -174,6 +175,10 @@ func RunLint(fs *token.FileSet, files []*ast.File, s Setting) []Issue { } } + for _, iss := range v.issues { + log.Printf("%s, pos: %s", iss.Metric, iss.Pos) + } + sort.Slice(v.issues, func(i, j int) bool { return v.issues[i].Pos.String() < v.issues[j].Pos.String() }) diff --git a/promlinter_test.go b/promlinter_test.go index e960cc0..2ce4500 100644 --- a/promlinter_test.go +++ b/promlinter_test.go @@ -23,7 +23,7 @@ func TestRun(t *testing.T) { } for idx, iss := range issues { - t.Logf("%d: %q", idx, iss) + t.Logf("%d: %q: %s", idx, iss.Metric, iss.Pos) switch iss.Metric { case "kube_daemonset_labels", "test_metric_name", "foo":