mirror of
https://github.com/hohn/sarif-cli.git
synced 2025-12-16 17:23:03 +01:00
fix: traverse all languages
This commit is contained in:
committed by
=Michael Hohn
parent
c6641019bf
commit
a0af2c8c59
@@ -14,32 +14,36 @@ args = parser.parse_args()
|
||||
with open(args.file, 'r') if args.file != '-' else sys.stdin as fp:
|
||||
sarif_struct = json.load(fp)
|
||||
|
||||
# Make sure there are some results
|
||||
num_results = len(S.get(sarif_struct, 'runs', 0, 'results'))
|
||||
if num_results == 0:
|
||||
S.exit(0)
|
||||
|
||||
# Collect the file names
|
||||
# File name collection
|
||||
uris = set()
|
||||
|
||||
# Locations for @kind problem
|
||||
# e.g.,
|
||||
# sarif_struct['runs'][0]['results'][5]['locations'][0]['physicalLocation']['artifactLocation']
|
||||
for resi in range(0, len(S.get(sarif_struct, 'runs', 0, 'results'))):
|
||||
uri = S.get(sarif_struct, 'runs', 0, 'results', resi, 'locations', 0,
|
||||
'physicalLocation', 'artifactLocation', 'uri')
|
||||
uris.add(uri)
|
||||
|
||||
# Locations for @kind path-problem
|
||||
# e.g. sarif_struct['runs'][0]['results'][22]['codeFlows'][0]['threadFlows'][0]['locations'][1]['location']
|
||||
for resi in range(0, len(S.get(sarif_struct, 'runs', 0, 'results'))):
|
||||
if 'codeFlows' in S.get(sarif_struct, 'runs', 0, 'results', resi).keys():
|
||||
locations = S.get(sarif_struct, 'runs', 0, 'results', resi, 'codeFlows', 0,
|
||||
'threadFlows', 0, 'locations')
|
||||
for loci in range(0, len(locations)):
|
||||
uri = S.get(locations, loci, 'location', 'physicalLocation',
|
||||
'artifactLocation', 'uri')
|
||||
uris.add(uri)
|
||||
# Traverse all runs
|
||||
for runi in S.indices(sarif_struct, 'runs'):
|
||||
# Make sure there are some results
|
||||
num_results = len(S.get(sarif_struct, 'runs', runi, 'results'))
|
||||
if num_results == 0: continue
|
||||
|
||||
# Collect the file names
|
||||
|
||||
# Locations for @kind problem
|
||||
# e.g.,
|
||||
# sarif_struct['runs'][0]['results'][5]['locations'][0]['physicalLocation']['artifactLocation']
|
||||
for resi in S.indices(sarif_struct, 'runs', runi, 'results'):
|
||||
uri = S.get(sarif_struct, 'runs', runi, 'results', resi, 'locations', 0,
|
||||
'physicalLocation', 'artifactLocation', 'uri')
|
||||
uris.add(uri)
|
||||
|
||||
# Locations for @kind path-problem
|
||||
# e.g. sarif_struct['runs'][0]['results'][22]['codeFlows'][0]['threadFlows'][0]['locations'][1]['location']
|
||||
for resi in S.indices(sarif_struct, 'runs', runi, 'results'):
|
||||
if 'codeFlows' in S.get(sarif_struct, 'runs', runi, 'results', resi).keys():
|
||||
locations = S.get(sarif_struct, 'runs', runi, 'results', resi, 'codeFlows', 0,
|
||||
'threadFlows', 0, 'locations')
|
||||
for loci in range(0, len(locations)):
|
||||
uri = S.get(locations, loci, 'location', 'physicalLocation',
|
||||
'artifactLocation', 'uri')
|
||||
uris.add(uri)
|
||||
# Dump the file names
|
||||
uris = list(uris)
|
||||
uris.sort()
|
||||
for u in uris:
|
||||
|
||||
@@ -12,21 +12,19 @@ args = parser.parse_args()
|
||||
with open(args.file, 'r') if args.file != '-' else sys.stdin as fp:
|
||||
sarif_struct = json.load(fp)
|
||||
|
||||
num_results = len(S.get(sarif_struct, 'runs', 0, 'results'))
|
||||
S.msg("Found %d results\n\n" % num_results)
|
||||
if num_results == 0:
|
||||
S.exit(0)
|
||||
|
||||
for resi in range(0, len(S.get(sarif_struct, 'runs', 0, 'results'))):
|
||||
message = S.get(sarif_struct, 'runs', 0, 'results', resi, 'message', 'text')
|
||||
artifact = S.get(sarif_struct, 'runs', 0, 'results', resi, 'locations', 0,
|
||||
'physicalLocation', 'artifactLocation')
|
||||
region = S.get(sarif_struct, 'runs', 0, 'results', resi, 'locations', 0,
|
||||
'physicalLocation', 'region')
|
||||
filepath = "%s:%d:%d" % (artifact['uri'], region['startLine'],
|
||||
region.get('startColumn', -1))
|
||||
S.msg("%s: %s\n" % (filepath, message))
|
||||
|
||||
|
||||
|
||||
for runi in S.indices(sarif_struct, 'runs'):
|
||||
num_results = len(S.get(sarif_struct, 'runs', runi, 'results'))
|
||||
language = S.get(sarif_struct, 'runs', runi, 'properties',
|
||||
'semmle.sourceLanguage')
|
||||
S.msg("Found %d results for %s \n\n" % (num_results, language))
|
||||
if num_results == 0: continue
|
||||
|
||||
for resi in S.indices(sarif_struct, 'runs', runi, 'results'):
|
||||
message = S.get(sarif_struct, 'runs', runi, 'results', resi, 'message', 'text')
|
||||
artifact = S.get(sarif_struct, 'runs', runi, 'results', resi, 'locations', 0,
|
||||
'physicalLocation', 'artifactLocation')
|
||||
region = S.get(sarif_struct, 'runs', runi, 'results', resi, 'locations', 0,
|
||||
'physicalLocation', 'region')
|
||||
filepath = "%s:%d:%d" % (artifact['uri'], region['startLine'],
|
||||
region.get('startColumn', -1))
|
||||
S.msg("%s: %s\n" % (filepath, message))
|
||||
|
||||
@@ -4,6 +4,10 @@ MIN_PYTHON = (3, 7)
|
||||
if sys.version_info < MIN_PYTHON:
|
||||
sys.exit("Python %s.%s or later is required.\n" % MIN_PYTHON)
|
||||
|
||||
def indices(sarif_struct, *path):
|
||||
""" Return a range for the indices of PATH """
|
||||
return range(0, len(get(sarif_struct, *path)))
|
||||
|
||||
def get(sarif_struct, *path):
|
||||
""" Get the sarif entry at PATH """
|
||||
res = sarif_struct
|
||||
|
||||
Reference in New Issue
Block a user