diff options
author | Fabio Natali <me@fabionatali.com> | 2015-09-21 13:49:15 +0100 |
---|---|---|
committer | Fabio Natali <me@fabionatali.com> | 2015-09-21 13:49:15 +0100 |
commit | 91828a23e28ef0f7d0e15d240ef29874f88b8b1d (patch) | |
tree | 1388b36a385bc8cb3aaa9c16507f9d862937796c | |
parent | c167eaa1a0752f97322490a92b8f2bc4e8531812 (diff) | |
download | pylint-91828a23e28ef0f7d0e15d240ef29874f88b8b1d.tar.gz |
Fix issue #314: bad-whitespace looks weird when the line does not end with newline
-rw-r--r-- | pylint/checkers/format.py | 7 | ||||
-rw-r--r-- | pylint/test/functional/bad_whitespace.py | 3 | ||||
-rw-r--r-- | pylint/test/functional/bad_whitespace.txt | 7 |
3 files changed, 15 insertions, 2 deletions
diff --git a/pylint/checkers/format.py b/pylint/checkers/format.py index 322645e..9b0f211 100644 --- a/pylint/checkers/format.py +++ b/pylint/checkers/format.py @@ -126,8 +126,11 @@ MSGS = { def _underline_token(token): length = token[3][1] - token[2][1] offset = token[2][1] - return token[4] + (' ' * offset) + ('^' * length) - + referenced_line = token[4] + # If the referenced line does not end with a newline char, fix it + if referenced_line[-1] != '\n': + referenced_line += '\n' + return referenced_line + (' ' * offset) + ('^' * length) def _column_distance(token1, token2): if token1 == token2: diff --git a/pylint/test/functional/bad_whitespace.py b/pylint/test/functional/bad_whitespace.py new file mode 100644 index 0000000..fe22a21 --- /dev/null +++ b/pylint/test/functional/bad_whitespace.py @@ -0,0 +1,3 @@ +# pylint: disable = invalid-name, missing-docstring, unused-variable, unused-argument +def function(hello): + x, y, z = (1,2,3,) # [bad-whitespace, bad-whitespace, missing-final-newline]
\ No newline at end of file diff --git a/pylint/test/functional/bad_whitespace.txt b/pylint/test/functional/bad_whitespace.txt new file mode 100644 index 0000000..524d4d9 --- /dev/null +++ b/pylint/test/functional/bad_whitespace.txt @@ -0,0 +1,7 @@ +bad-whitespace:3::"Exactly one space required after comma + x, y, z = (1,2,3,) # [bad-whitespace, bad-whitespace, missing-final-newline] + ^" +bad-whitespace:3::"Exactly one space required after comma + x, y, z = (1,2,3,) # [bad-whitespace, bad-whitespace, missing-final-newline] + ^" +missing-final-newline:3::"Final newline missing" |