Skip to content

Commit 0d5d3ea

Browse files
Drop YAML output format and add description to issue JSON
- Remove --output yaml option from all commands (issues, metrics, report, reportcard, analyzers, status, vulnerabilities) - Remove yaml struct tags from all type definitions - Delete YAML golden files and associated tests - Move gopkg.in/yaml.v3 to indirect dependency - Add description field to JSON issue output - Remove leftover table format from report command completions
1 parent 02c60d0 commit 0d5d3ea

25 files changed

Lines changed: 119 additions & 384 deletions

command/issues/issues.go

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/pterm/pterm"
2323
"github.com/spf13/cobra"
2424
"github.com/spf13/pflag"
25-
"gopkg.in/yaml.v3"
2625
)
2726

2827
type IssuesOptions struct {
@@ -99,7 +98,7 @@ func NewCmdIssuesWithDeps(deps *cmddeps.Deps) *cobra.Command {
9998
cmd.Flags().IntVarP(&opts.LimitArg, "limit", "l", 30, "Maximum number of issues to fetch")
10099

101100
// --output, -o flag
102-
cmd.Flags().StringVarP(&opts.OutputFormat, "output", "o", "pretty", "Output format: pretty, json, yaml")
101+
cmd.Flags().StringVarP(&opts.OutputFormat, "output", "o", "pretty", "Output format: pretty, json")
103102

104103
// --verbose, -v flag
105104
cmd.Flags().BoolVarP(&opts.Verbose, "verbose", "v", false, "Show issue description")
@@ -124,7 +123,6 @@ func NewCmdIssuesWithDeps(deps *cmddeps.Deps) *cobra.Command {
124123
return []string{
125124
"pretty\tPretty-printed output",
126125
"json\tJSON output",
127-
"yaml\tYAML output",
128126
}, cobra.ShellCompDirectiveNoFileComp
129127
})
130128
_ = cmd.RegisterFlagCompletionFunc("category", func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
@@ -299,8 +297,6 @@ func (opts *IssuesOptions) Run(ctx context.Context) error {
299297
switch opts.OutputFormat {
300298
case "json":
301299
return opts.outputJSON()
302-
case "yaml":
303-
return opts.outputYAML()
304300
default:
305301
return opts.outputHuman()
306302
}
@@ -537,33 +533,35 @@ func (opts *IssuesOptions) outputHuman() error {
537533
return nil
538534
}
539535

540-
// --- JSON/YAML output ---
536+
// --- JSON output ---
541537

542538
type IssueJSON struct {
543-
Path string `json:"path" yaml:"path"`
544-
BeginLine int `json:"begin_line" yaml:"begin_line"`
545-
EndLine int `json:"end_line" yaml:"end_line"`
546-
IssueCode string `json:"issue_code" yaml:"issue_code"`
547-
Title string `json:"title" yaml:"title"`
548-
Category string `json:"category" yaml:"category"`
549-
Severity string `json:"severity" yaml:"severity"`
550-
Source string `json:"source" yaml:"source"`
551-
Analyzer string `json:"analyzer" yaml:"analyzer"`
539+
Path string `json:"path"`
540+
BeginLine int `json:"begin_line"`
541+
EndLine int `json:"end_line"`
542+
IssueCode string `json:"issue_code"`
543+
Title string `json:"title"`
544+
Description string `json:"description"`
545+
Category string `json:"category"`
546+
Severity string `json:"severity"`
547+
Source string `json:"source"`
548+
Analyzer string `json:"analyzer"`
552549
}
553550

554551
func (opts *IssuesOptions) toJSONIssues() []IssueJSON {
555552
result := make([]IssueJSON, 0, len(opts.issues))
556553
for _, issue := range opts.issues {
557554
result = append(result, IssueJSON{
558-
Path: issue.Location.Path,
559-
BeginLine: issue.Location.Position.BeginLine,
560-
EndLine: issue.Location.Position.EndLine,
561-
IssueCode: issue.IssueCode,
562-
Title: issue.IssueText,
563-
Category: issue.IssueCategory,
564-
Severity: issue.IssueSeverity,
565-
Source: issue.IssueSource,
566-
Analyzer: issue.Analyzer.Shortcode,
555+
Path: issue.Location.Path,
556+
BeginLine: issue.Location.Position.BeginLine,
557+
EndLine: issue.Location.Position.EndLine,
558+
IssueCode: issue.IssueCode,
559+
Title: issue.IssueText,
560+
Description: issue.Description,
561+
Category: issue.IssueCategory,
562+
Severity: issue.IssueSeverity,
563+
Source: issue.IssueSource,
564+
Analyzer: issue.Analyzer.Shortcode,
567565
})
568566
}
569567
return result
@@ -577,14 +575,6 @@ func (opts *IssuesOptions) outputJSON() error {
577575
return opts.writeOutput(data, true)
578576
}
579577

580-
func (opts *IssuesOptions) outputYAML() error {
581-
data, err := yaml.Marshal(opts.toJSONIssues())
582-
if err != nil {
583-
return clierrors.NewCLIError(clierrors.ErrAPIError, "Failed to format YAML output", err)
584-
}
585-
return opts.writeOutput(data, false)
586-
}
587-
588578
func (opts *IssuesOptions) writeOutput(data []byte, trailingNewline bool) error {
589579
w := opts.stdout()
590580
if trailingNewline {

command/issues/tests/golden_files/commit_scope_output.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"end_line": 42,
66
"issue_code": "GO-R1005",
77
"title": "Error return value not checked",
8+
"description": "Error return value of a function call is not checked",
89
"category": "BUG_RISK",
910
"severity": "MAJOR",
1011
"source": "static",
@@ -16,6 +17,7 @@
1617
"end_line": 20,
1718
"issue_code": "GO-S1001",
1819
"title": "Potential SQL injection",
20+
"description": "SQL query constructed with string concatenation",
1921
"category": "SECURITY",
2022
"severity": "CRITICAL",
2123
"source": "ai",

command/issues/tests/golden_files/default_branch_output.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"end_line": 42,
66
"issue_code": "GO-R1005",
77
"title": "Error return value not checked",
8+
"description": "Error return value of a function call is not checked",
89
"category": "BUG_RISK",
910
"severity": "MAJOR",
1011
"source": "",
@@ -16,6 +17,7 @@
1617
"end_line": 20,
1718
"issue_code": "GO-S1001",
1819
"title": "Potential SQL injection",
20+
"description": "SQL query constructed with string concatenation",
1921
"category": "SECURITY",
2022
"severity": "CRITICAL",
2123
"source": "",
@@ -27,6 +29,7 @@
2729
"end_line": 88,
2830
"issue_code": "GO-R1003",
2931
"title": "Function too complex",
32+
"description": "Cyclomatic complexity exceeds threshold",
3033
"category": "ANTI_PATTERN",
3134
"severity": "MINOR",
3235
"source": "",

command/issues/tests/golden_files/default_branch_output.yaml

Lines changed: 0 additions & 27 deletions
This file was deleted.

command/issues/tests/golden_files/filtered_category_output.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"end_line": 20,
66
"issue_code": "GO-S1001",
77
"title": "Potential SQL injection",
8+
"description": "SQL query constructed with string concatenation",
89
"category": "SECURITY",
910
"severity": "CRITICAL",
1011
"source": "",

command/issues/tests/golden_files/filtered_combined_output.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"end_line": 20,
66
"issue_code": "GO-S1001",
77
"title": "Potential SQL injection",
8+
"description": "SQL query constructed with string concatenation",
89
"category": "SECURITY",
910
"severity": "CRITICAL",
1011
"source": "",

command/issues/tests/golden_files/filtered_path_output.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"end_line": 20,
66
"issue_code": "GO-S1001",
77
"title": "Potential SQL injection",
8+
"description": "SQL query constructed with string concatenation",
89
"category": "SECURITY",
910
"severity": "CRITICAL",
1011
"source": "",

command/issues/tests/golden_files/filtered_severity_output.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"end_line": 20,
66
"issue_code": "GO-S1001",
77
"title": "Potential SQL injection",
8+
"description": "SQL query constructed with string concatenation",
89
"category": "SECURITY",
910
"severity": "CRITICAL",
1011
"source": "",

command/issues/tests/golden_files/filtered_source_output.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"end_line": 20,
66
"issue_code": "GO-S1001",
77
"title": "Potential SQL injection",
8+
"description": "SQL query constructed with string concatenation",
89
"category": "SECURITY",
910
"severity": "CRITICAL",
1011
"source": "ai",

command/issues/tests/golden_files/pr_scope_output.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"end_line": 33,
66
"issue_code": "GO-R1002",
77
"title": "Unused variable declared",
8+
"description": "Variable declared but never used",
89
"category": "BUG_RISK",
910
"severity": "MINOR",
1011
"source": "",

0 commit comments

Comments
 (0)