Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix json and yaml formatters to respect num lines #929

Merged
merged 1 commit into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions bandit/core/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def get_code(self, max_lines=3, tabbed=False):
lines.append(tmplt % (line, text))
return "".join(lines)

def as_dict(self, with_code=True):
def as_dict(self, with_code=True, max_lines=3):
"""Convert the issue to a dict of values for outputting."""
out = {
"filename": self.fname,
Expand All @@ -213,7 +213,7 @@ def as_dict(self, with_code=True):
}

if with_code:
out["code"] = self.get_code()
out["code"] = self.get_code(max_lines=max_lines)
return out

def from_dict(self, data, with_code=True):
Expand Down
8 changes: 5 additions & 3 deletions bandit/formatters/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,16 @@ def report(manager, fileobj, sev_level, conf_level, lines=-1):
if baseline:
collector = []
for r in results:
d = r.as_dict()
d = r.as_dict(max_lines=lines)
d["more_info"] = docs_utils.get_url(d["test_id"])
if len(results[r]) > 1:
d["candidates"] = [c.as_dict() for c in results[r]]
d["candidates"] = [
c.as_dict(max_lines=lines) for c in results[r]
]
collector.append(d)

else:
collector = [r.as_dict() for r in results]
collector = [r.as_dict(max_lines=lines) for r in results]
for elem in collector:
elem["more_info"] = docs_utils.get_url(elem["test_id"])

Expand Down
2 changes: 1 addition & 1 deletion bandit/formatters/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def report(manager, fileobj, sev_level, conf_level, lines=-1):
sev_level=sev_level, conf_level=conf_level
)

collector = [r.as_dict() for r in results]
collector = [r.as_dict(max_lines=lines) for r in results]
for elem in collector:
elem["more_info"] = docs_utils.get_url(elem["test_id"])

Expand Down