mirror of
https://github.com/hohn/sarif-cli.git
synced 2025-12-16 17:23:03 +01:00
refactor: introduce get_location_message_info
This commit is contained in:
committed by
=Michael Hohn
parent
8036ea5ffc
commit
1f7e78b049
@@ -26,9 +26,7 @@ for runi in S.indices(sarif_struct, 'runs'):
|
|||||||
#
|
#
|
||||||
for resi in S.indices(sarif_struct, 'runs', runi, 'results'):
|
for resi in S.indices(sarif_struct, 'runs', runi, 'results'):
|
||||||
result = S.get(sarif_struct, 'runs', runi, 'results', resi)
|
result = S.get(sarif_struct, 'runs', runi, 'results', resi)
|
||||||
message = S.get(result, 'message', 'text')
|
message, artifact, region = S.get_location_message_info(result)
|
||||||
artifact = S.get(result, 'locations', 0, 'physicalLocation', 'artifactLocation')
|
|
||||||
region = S.get(result, 'locations', 0, 'physicalLocation', 'region')
|
|
||||||
l1, c1, l2, c2 = S.lineinfo(region)
|
l1, c1, l2, c2 = S.lineinfo(region)
|
||||||
filepath = "%s:%d:%d:%d:%d" % (artifact['uri'], l1, c1, l2, c2)
|
filepath = "%s:%d:%d:%d:%d" % (artifact['uri'], l1, c1, l2, c2)
|
||||||
S.msg("%s: %s\n\n" % (filepath, message))
|
S.msg("%s: %s\n\n" % (filepath, message))
|
||||||
|
|||||||
@@ -6,6 +6,16 @@ MIN_PYTHON = (3, 7)
|
|||||||
if sys.version_info < MIN_PYTHON:
|
if sys.version_info < MIN_PYTHON:
|
||||||
sys.exit("Python %s.%s or later is required.\n" % MIN_PYTHON)
|
sys.exit("Python %s.%s or later is required.\n" % MIN_PYTHON)
|
||||||
|
|
||||||
|
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)
|
||||||
|
"""
|
||||||
|
message = get(result, 'message', 'text')
|
||||||
|
artifact = get(result, 'locations', 0, 'physicalLocation', 'artifactLocation')
|
||||||
|
region = get(result, 'locations', 0, 'physicalLocation', 'region')
|
||||||
|
return (message, artifact, region)
|
||||||
|
|
||||||
def display_underlined(l1, c1, l2, c2, line, line_num):
|
def display_underlined(l1, c1, l2, c2, line, line_num):
|
||||||
""" Display the given line followed by a second line with underscores at the locations.
|
""" Display the given line followed by a second line with underscores at the locations.
|
||||||
|
|
||||||
@@ -26,7 +36,7 @@ def underline_for_result(first_line, first_column, last_line, last_column, line,
|
|||||||
"""Provide the underline for a result line.
|
"""Provide the underline for a result line.
|
||||||
|
|
||||||
first_line, first_column, last_line, last_column :
|
first_line, first_column, last_line, last_column :
|
||||||
the region from S.lineinfo(region)
|
the region from lineinfo(region)
|
||||||
line:
|
line:
|
||||||
the line of source
|
the line of source
|
||||||
line_num:
|
line_num:
|
||||||
@@ -109,5 +119,5 @@ def msg(message):
|
|||||||
def dbg(message):
|
def dbg(message):
|
||||||
""" Print message to stderr """
|
""" Print message to stderr """
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
sys.stderr.write(message)
|
sys.stderr.write("warning: %s" % message)
|
||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
|
|||||||
Reference in New Issue
Block a user