Use sensible values for start/end line/columns for empty entries in the sarif 'region' structure.

This commit is contained in:
Michael Hohn
2021-11-09 15:04:36 -08:00
committed by =Michael Hohn
parent 2d1180a515
commit ab1d7c27ef
2 changed files with 20 additions and 6 deletions

View File

@@ -4,6 +4,21 @@ MIN_PYTHON = (3, 7)
if sys.version_info < MIN_PYTHON:
sys.exit("Python %s.%s or later is required.\n" % MIN_PYTHON)
def lineinfo(region):
""" Return sensible values for start/end line/columns for the possibly empty
entries in the sarif 'region' structure.
"""
startLine, startColumn, endLine, endColumn = map(
lambda e: region.get(e, -1), ['startLine', 'startColumn', 'endLine', 'endColumn'])
# Full information is startLine / startColumn / endLine / endcolumn
# - only have startLine / startColumn / _ / endcolumn
if endLine == -1: endLine = startLine
# - only have startLine / _ / _ / endcolumn
if startColumn == -1: startColumn = 1
return startLine, startColumn, endLine, endColumn
def indices(sarif_struct, *path):
""" Return a range for the indices of PATH """
return range(0, len(get(sarif_struct, *path)))
@@ -18,5 +33,4 @@ def get(sarif_struct, *path):
def msg(message):
""" Print message to stdout """
sys.stdout.write(message)
sys.stdout.write('\n')