Skip to content

Commit

Permalink
Show column offset on all formatters (#673)
Browse files Browse the repository at this point in the history
Recently, #618 introduced column offsets to the custom formatter.
But other formatters should also show the column offset.

Signed-off-by: Eric Brown <browne@vmware.com>
  • Loading branch information
ericwb committed Dec 19, 2020
1 parent 82db41a commit 5f07310
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions bandit/formatters/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def report(manager, fileobj, sev_level, conf_level, lines=-1):
'issue_confidence',
'issue_text',
'line_number',
'col_offset',
'line_range',
'more_info']

Expand Down
5 changes: 3 additions & 2 deletions bandit/formatters/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ def _output_issue_str(issue, indent, show_lineno=True, show_code=True,
bits.append("%s Severity: %s Confidence: %s" % (
indent, issue.severity.capitalize(), issue.confidence.capitalize()))

bits.append("%s Location: %s:%s" % (
bits.append("%s Location: %s:%s:%s" % (
indent, issue.fname,
issue.lineno if show_lineno else ""))
issue.lineno if show_lineno else "",
issue.col_offset if show_lineno else ""))

bits.append("%s More Info: %s%s" % (
indent, docs_utils.get_url(issue.test_id), COLOR['DEFAULT']))
Expand Down
5 changes: 3 additions & 2 deletions bandit/formatters/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ def _output_issue_str(issue, indent, show_lineno=True, show_code=True,
bits.append("%s Severity: %s Confidence: %s" % (
indent, issue.severity.capitalize(), issue.confidence.capitalize()))

bits.append("%s Location: %s:%s" % (
indent, issue.fname, issue.lineno if show_lineno else ""))
bits.append("%s Location: %s:%s:%s" % (
indent, issue.fname, issue.lineno if show_lineno else "",
issue.col_offset if show_lineno else ""))

bits.append("%s More Info: %s" % (
indent, docs_utils.get_url(issue.test_id)))
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/formatters/test_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ def _template(_issue, _indent_val, _code, _color):
"{} Severity: {} Confidence: {}".
format(_indent_val, _issue.severity.capitalize(),
_issue.confidence.capitalize()),
"{} Location: {}:{}".
format(_indent_val, _issue.fname, _issue.lineno),
"{} Location: {}:{}:{}".
format(_indent_val, _issue.fname, _issue.lineno,
_issue.col_offset),
"{} More Info: {}{}".format(
_indent_val, docs_utils.get_url(_issue.test_id),
screen.COLOR['DEFAULT'])]
Expand All @@ -56,6 +57,7 @@ def _template(_issue, _indent_val, _code, _color):
self.assertEqual(expected_return, issue_text)

issue.lineno = ''
issue.col_offset = ''
issue_text = screen._output_issue_str(issue, indent_val,
show_lineno=False)
expected_return = _template(issue, indent_val, 'DDDDDDD',
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/formatters/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ def _template(_issue, _indent_val, _code):
"{} Severity: {} Confidence: {}".
format(_indent_val, _issue.severity.capitalize(),
_issue.confidence.capitalize()),
"{} Location: {}:{}".
format(_indent_val, _issue.fname, _issue.lineno),
"{} Location: {}:{}:{}".
format(_indent_val, _issue.fname, _issue.lineno,
_issue.col_offset),
"{} More Info: {}".format(
_indent_val, docs_utils.get_url(_issue.test_id))]
if _code:
Expand All @@ -53,6 +54,7 @@ def _template(_issue, _indent_val, _code):
self.assertEqual(expected_return, issue_text)

issue.lineno = ''
issue.col_offset = ''
issue_text = b_text._output_issue_str(issue, indent_val,
show_lineno=False)
expected_return = _template(issue, indent_val, 'DDDDDDD')
Expand Down

0 comments on commit 5f07310

Please sign in to comment.