parseAndDisplayPoutineOutput parses poutine JSON output and displays it in the desired format Returns the total number of warnings found for the specific file
(stdout, targetFile string, verbose bool)
| 273 | // parseAndDisplayPoutineOutput parses poutine JSON output and displays it in the desired format |
| 274 | // Returns the total number of warnings found for the specific file |
| 275 | func parseAndDisplayPoutineOutput(stdout, targetFile string, verbose bool) (int, error) { |
| 276 | // Parse JSON output from stdout |
| 277 | var output poutineOutput |
| 278 | if stdout == "" { |
| 279 | return 0, nil // No output means no findings |
| 280 | } |
| 281 | |
| 282 | trimmed := strings.TrimSpace(stdout) |
| 283 | if !strings.HasPrefix(trimmed, "{") { |
| 284 | // Non-JSON output, likely an error |
| 285 | if len(trimmed) > 0 { |
| 286 | return 0, fmt.Errorf("unexpected poutine output format: %s", trimmed) |
| 287 | } |
| 288 | return 0, nil |
| 289 | } |
| 290 | |
| 291 | if err := json.Unmarshal([]byte(stdout), &output); err != nil { |
| 292 | return 0, fmt.Errorf("failed to parse poutine JSON output: %w", err) |
| 293 | } |
| 294 | |
| 295 | // Filter findings to only those relevant to the target file |
| 296 | var relevantFindings []poutineFinding |
| 297 | for _, finding := range output.Findings { |
| 298 | if finding.Meta.Path == targetFile { |
| 299 | relevantFindings = append(relevantFindings, finding) |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | totalWarnings := len(relevantFindings) |
| 304 | |
| 305 | // Skip files with 0 warnings |
| 306 | if totalWarnings == 0 { |
| 307 | return 0, nil |
| 308 | } |
| 309 | |
| 310 | // Read file content for context display |
| 311 | fileContent, err := os.ReadFile(targetFile) |
| 312 | var fileLines []string |
| 313 | if err == nil { |
| 314 | fileLines = strings.Split(string(fileContent), "\n") |
| 315 | } |
| 316 | |
| 317 | // Display detailed findings using CompilerError format |
| 318 | for _, finding := range relevantFindings { |
| 319 | // Get rule details |
| 320 | ruleInfo := output.Rules[finding.RuleID] |
| 321 | severity := ruleInfo.Level |
| 322 | if severity == "" { |
| 323 | severity = "warning" // Default to warning if not specified |
| 324 | } |
| 325 | |
| 326 | title := ruleInfo.Title |
| 327 | if title == "" { |
| 328 | title = finding.RuleID |
| 329 | } |
| 330 | |
| 331 | // Get line number (poutine uses 1-based indexing) |
| 332 | lineNum := finding.Meta.Line |