From be70c9876412c0383ed2e1bcd5abd936b996fba7 Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Mon, 11 Feb 2019 14:57:59 +0100 Subject: [PATCH] Add basic lint travis check --- .gitattributes | 8 ++++++++ .travis.yml | 1 + travis.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 .gitattributes create mode 100644 travis.py diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..59f9f88d --- /dev/null +++ b/.gitattributes @@ -0,0 +1,8 @@ +* text eol=lf + +*.ico binary +*.jpg binary +*.png binary +*.zip binary +*.mp3 binary +*.gif binary diff --git a/.travis.yml b/.travis.yml index 6256dac0..44393942 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,7 @@ cache: - "$TRAVIS_BUILD_DIR/.piolibdeps" script: + - python travis.py - platformio run -e $BUILD_TARGET matrix: diff --git a/travis.py b/travis.py new file mode 100644 index 00000000..ed40b1eb --- /dev/null +++ b/travis.py @@ -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))