Skip to content

Commit

Permalink
WIP, saving progress
Browse files Browse the repository at this point in the history
  • Loading branch information
rgeyer committed Oct 3, 2023
1 parent 3c1213e commit 149168d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
19 changes: 12 additions & 7 deletions lint/results.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package lint

import (
"encoding/json"
"fmt"
"os"
"sort"
Expand All @@ -18,7 +19,7 @@ type Result struct {

type FixableResult struct {
Result
Fix func(*Dashboard) // if nil, it cannot be fixed
Fix func(*Dashboard) `json:"-"` // if nil, it cannot be fixed
}

type RuleResults struct {
Expand All @@ -27,7 +28,7 @@ type RuleResults struct {

type TargetResult struct {
Result
Fix func(Dashboard, Panel, *Target)
Fix func(Dashboard, Panel, *Target) `json:"-"`
}

type TargetRuleResults struct {
Expand Down Expand Up @@ -109,11 +110,11 @@ func (r *DashboardRuleResults) AddWarning(d Dashboard, message string) {

// ResultContext is used by ResultSet to keep all the state data about a lint execution and it's results.
type ResultContext struct {
Result RuleResults
Rule Rule
Dashboard *Dashboard
Panel *Panel
Target *Target
Result RuleResults `json:"result"`
Rule Rule `json:"rule"`
Dashboard *Dashboard `json:"-"`
Panel *Panel `json:"-"`
Target *Target `json:"-"`
}

func (r Result) TtyPrint() {
Expand Down Expand Up @@ -217,3 +218,7 @@ func (rs *ResultSet) AutoFix(d *Dashboard) int {
}
return changes
}

func (rs *ResultSet) MarshalJSON() ([]byte, error) {
return json.Marshal(rs.results)
}
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"encoding/json"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -86,7 +87,14 @@ var lintCmd = &cobra.Command{
}

results.Configure(config)
results.ReportByRule()
// results.ReportByRule()
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
err = enc.Encode(results)
// resBytes, err := json.Marshal(results)
if err != nil {
return fmt.Errorf("failed to generate json representation of results: %v", err)
}

if lintStrictFlag && results.MaximumSeverity() >= lint.Warning {
return fmt.Errorf("there were linting errors, please see previous output")
Expand Down

0 comments on commit 149168d

Please sign in to comment.