Skip to content

Commit

Permalink
Merge pull request theochem#69 from tovrstra/more_whitespace
Browse files Browse the repository at this point in the history
More sensitive whitespace linter
  • Loading branch information
tovrstra authored Sep 18, 2017
2 parents b6a2273 + cedb4a8 commit ed36bcb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
14 changes: 12 additions & 2 deletions cardboardlint/linter_whitespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,23 @@ def run_whitespace(_config, filenames):
line = None
lineno = -1
for lineno, line in enumerate(f):
# Check for tabs
charno = line.find('\t')
if charno >= 0:
messages.append(Message(filename, lineno + 1, charno + 1, 'tab'))
# Check for carriage return
charno = line.find('\r')
if charno >= 0:
messages.append(Message(filename, lineno + 1, charno + 1, 'carriage return'))
# Check for trailing whitespace
if line[:-1] != line.rstrip():
messages.append(Message(filename, lineno + 1, None, 'trailing whitespace'))
if line is not None and len(line.strip()) == 0:
messages.append(Message(filename, lineno + 1, None, 'trailing empty line'))
# Perform some checks on the last line
if line is not None:
if len(line.strip()) == 0:
messages.append(Message(filename, lineno + 1, None, 'trailing empty line'))
if not line.endswith("\n"):
messages.append(Message(filename, lineno + 1, None, 'last line missing \\n'))
return messages


Expand Down
1 change: 1 addition & 0 deletions tools/example/README.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
This directory contains a simple example for all supported linters. This example is used
to run through all code at least once.
Hello
8 changes: 4 additions & 4 deletions tools/example/broken.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- foo: bar
- foobar

egg
- foo: bar
- foobar

egg

0 comments on commit ed36bcb

Please sign in to comment.