Skip to content

Commit

Permalink
Add basic lint travis check
Browse files Browse the repository at this point in the history
  • Loading branch information
OttoWinter committed Feb 11, 2019
1 parent 231a7b0 commit be70c98
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
* text eol=lf

*.ico binary
*.jpg binary
*.png binary
*.zip binary
*.mp3 binary
*.gif binary
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ cache:
- "$TRAVIS_BUILD_DIR/.piolibdeps"

script:
- python travis.py
- platformio run -e $BUILD_TARGET

matrix:
Expand Down
46 changes: 46 additions & 0 deletions travis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from __future__ import print_function
import glob
import sys
import codecs
import os.path

errors = []


def find_all(a_str, sub):
for i, line in enumerate(a_str.splitlines()):
column = 0
while True:
column = line.find(sub, column)
if column == -1:
break
yield i, column
column += len(sub)


files = []
for root, _, fs in os.walk('src'):
for f in fs:
_, ext = os.path.splitext(f)
if ext in ('.h', '.c', '.cpp', '.tcc'):
files.append(os.path.join(root, f))
files.sort()

for f in files:
try:
with codecs.open(f, 'r', encoding='utf-8') as f_handle:
content = f_handle.read()
except UnicodeDecodeError:
errors.append("File {} is not readable as UTF-8. Please set your editor to UTF-8 mode."
"".format(f))
for line, col in find_all(content, '\t'):
errors.append("File {} contains tab character on line {}:{}. "
"Please convert tabs to spaces.".format(f, line, col))
for line, col in find_all(content, '\r'):
errors.append("File {} contains windows newline on line {}:{}. "
"Please set your editor to unix newline mode.".format(f, line, col))

for error in errors:
print(error)

sys.exit(len(errors))

0 comments on commit be70c98

Please sign in to comment.