diff --git a/bin/sarif-results-summary b/bin/sarif-results-summary index cfb1269..833459d 100755 --- a/bin/sarif-results-summary +++ b/bin/sarif-results-summary @@ -33,13 +33,17 @@ for runi in S.indices(sarif_struct, 'runs'): # Non-path problems # TODO: just pull out the uri, not the artifact message, artifact, region = S.get_location_message_info(result) - l1, c1, l2, c2 = S.lineinfo(region) + if region == S.WholeFile: + l1, c1, l2, c2 = -1, -1, -1, -1 + else: + l1, c1, l2, c2 = S.lineinfo(region) filepath = "%s:%d:%d:%d:%d" % (artifact['uri'], l1, c1, l2, c2) if args.csv: S.write_csv(cw, "result", artifact['uri'], l1, c1, l2, c2, message) else: S.msg("RESULT: %s: %s\n\n" % (filepath, message)) - if args.list_source: + + if region != S.WholeFile and args.list_source: lines = S.load_lines(args.list_source, artifact['uri'], l1, l2) if args.csv: pass diff --git a/sarif_cli/__init__.py b/sarif_cli/__init__.py index ec694ef..913c682 100644 --- a/sarif_cli/__init__.py +++ b/sarif_cli/__init__.py @@ -33,14 +33,22 @@ def get_relatedlocation_message_info(related_location): region = get(related_location, 'physicalLocation', 'region') return message, artifact, region +class WholeFile: + pass + def get_location_message_info(result): """ Given one of the results, extract message information. The `result` typically starts from get(sarif_struct, 'runs', run_index, 'results', res_index) + + Returns: (message, artifact, region) + For an empty 'region' key, returns (message, artifact, sarif_cli.WholeFile) + """ message = get(result, 'message', 'text') artifact = get(result, 'locations', 0, 'physicalLocation', 'artifactLocation') - region = get(result, 'locations', 0, 'physicalLocation', 'region') + # If there is no 'region' key, use the whole file + region = get(result, 'locations', 0, 'physicalLocation').get('region', WholeFile) return (message, artifact, region) def display_underlined(l1, c1, l2, c2, line, line_num):