Open davidmalcolm opened 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.
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"}}]}]}]}]}]}
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
where note how
%i
in the message line and quoted source and theint
in the message line and the source annotation all appear in green (they're marked up internally asexpected_type
)const char *
in the message line and in the source annotation and themsg
in the quoted source all appear in dark blue (they're marked up internally asactual_type
)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.