mirror of
https://github.com/hohn/sarif-cli.git
synced 2025-12-16 17:23:03 +01:00
Use sensible values for start/end line/columns for empty entries in the sarif 'region' structure.
This commit is contained in:
committed by
=Michael Hohn
parent
2d1180a515
commit
ab1d7c27ef
@@ -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')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user