Skip to content

Conversation

@mikelolasagasti
Copy link
Collaborator

Introduce a new --output/-o flag to select the output format (text or json). Implements a JSONFormatter for structured violation reporting and marks --format and --output as mutually exclusive for clarity.

Checklist

  • Description of proposed change
  • Documentation (README, docs/, man pages) is updated
  • Unit tests for the proposed change

Introduce a new `--output/-o` flag to select the output format (`text`
or `json`). Implements a JSONFormatter for structured violation
reporting and marks `--format` and `--output` as mutually exclusive for
clarity.

Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
@mikelolasagasti
Copy link
Collaborator Author

Current output:

./checkmake fixtures/missing_phony.make 
     RULE          DESCRIPTION               FILE NAME           LINE NUMBER 
 minphony       Required target     fixtures/missing_phony.make  21          
                "all" must be                                                
                declared PHONY.                                              
 minphony       Required target     fixtures/missing_phony.make  21          
                "test" must be                                               
                declared PHONY.                                              
 phonydeclared  Target "all"        fixtures/missing_phony.make  16          
                should be declared                                           
                PHONY.                                                       
Error: violations found (3)

With json output:

./checkmake fixtures/missing_phony.make -o json
[
  {
    "rule": "minphony",
    "violation": "Required target \"all\" must be declared PHONY.",
    "file_name": "fixtures/missing_phony.make",
    "line_number": 21
  },
  {
    "rule": "minphony",
    "violation": "Required target \"test\" must be declared PHONY.",
    "file_name": "fixtures/missing_phony.make",
    "line_number": 21
  },
  {
    "rule": "phonydeclared",
    "violation": "Target \"all\" should be declared PHONY.",
    "file_name": "fixtures/missing_phony.make",
    "line_number": 16
  }
]
Error: violations found (3)

Parsing with jq:

./checkmake -o json fixtures/missing_phony.make | jq -r '.[] | "\(.rule):\(.line_number)"'
Error: violations found (3)
phonydeclared:16
minphony:21
minphony:21

Note that "Error: violations found (3)" message is part of stderr and not stdout.

Copy link
Collaborator

@obnoxxx obnoxxx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a reasonable enhancement.

Nice to have it covered with tests!

LGTM.

@mikelolasagasti mikelolasagasti merged commit 9277032 into checkmake:main Nov 4, 2025
4 checks passed
@mikelolasagasti mikelolasagasti deleted the output-json branch November 4, 2025 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants