oasis-tcs / sarif-spec

OASIS SARIF TC: Repository for development of the draft standard, where requests for modification should be made via Github Issues
https://github.com/oasis-tcs/sarif-spec
Other
167 stars 47 forks source link

"Semantic" markup in SARIF messages #662

Open davidmalcolm opened 3 days ago

davidmalcolm commented 3 days ago

There doesn't seem to be a way to add "semantic" markup to messages in SARIF logs.

For example, in GCC 15 I've added colorization to some diagnostics to highlight expected type vs actual type; see: https://godbolt.org/z/zqWGe5jKh

image

where note how

I'd like to capture this markup in the generated SARIF output, but we only support a subset of Markdown, and, in particular, HTML is forbidden.

KalleOlaviNiemitalo commented 3 days ago

What does GCC output for that in SARIF now, without colorization?

My first thought is that I'd place the color annotations in the multiFormatMessageString object in the reportingDescriptor and associate them with the placeholder numbers, something like:

{
    "text": "format '{0}' expects argument of type '{1}', but argument {2} has type '{3}' [{4}]",
    "placeholders": {
        "0": { "role": "expected_type" },
        "1": { "role": "expected_type" },
        "3": { "role": "actual_type" },
        "4": { "role": "option" }
    }
}

or as an array:

{
    "text": "format '{0}' expects argument of type '{1}', but argument {2} has type '{3}' [{4}]",
    "placeholders": [
        { "role": "expected_type" },
        { "role": "expected_type" },
        {},
        { "role": "actual_type" },
        { "role": "option" }
    ]
}

This scheme would make the color information trivial to ignore for SARIF consumers that don't care about it. However, this does not seem easy to apply to msg in the quoted source code, and to the diagram below it.

davidmalcolm commented 3 days ago

What does GCC output for that in SARIF now, without colorization?

From https://godbolt.org/z/9ja73xv19:

  "results": [{"ruleId": "-Wformat=",
                        "level": "warning",
                        "message": {"text": "format '%i' expects argument of type 'int', but argument 2 has type 'const char *'"},
                        "locations": [{"physicalLocation": {"artifactLocation": {"uri": "<source>"},
                                                            "region": {"startLine": 5,
                                                                       "startColumn": 17,
                                                                       "endColumn": 19},
                                                            "contextRegion": {"startLine": 5,
                                                                              "snippet": {"text": "  printf(\"hello %i\", msg);\n"}}},
                                       "logicalLocations": [{"name": "test_mismatching_types",
                                                             "fullyQualifiedName": "test_mismatching_types",
                                                             "decoratedName": "test_mismatching_types",
                                                             "kind": "function"}],
                                       "annotations": [{"startLine": 5,
                                                        "startColumn": 17,
                                                        "endColumn": 19,
                                                        "message": {"text": "int"}},
                                                       {"startLine": 5,
                                                        "startColumn": 22,
                                                        "endColumn": 25,
                                                        "message": {"text": "const char *"}}]}],
                        "fixes": [{"artifactChanges": [{"artifactLocation": {"uri": "<source>"},
                                                        "replacements": [{"deletedRegion": {"startLine": 5,
                                                                                            "startColumn": 17,
                                                                                            "endColumn": 19},
                                                                          "insertedContent": {"text": "%s"}}]}]}]}]}]}