From be21296b38dadeed1e08569033a02136163ef5fa Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 6 Aug 2014 21:56:10 +0200 Subject: [PATCH] Use pylint for CRLF checking. --- scripts/pylint_checkers/crlf.py | 28 ++++++++++++++++++++++++++++ scripts/run_checks.py | 8 +++----- 2 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 scripts/pylint_checkers/crlf.py diff --git a/scripts/pylint_checkers/crlf.py b/scripts/pylint_checkers/crlf.py new file mode 100644 index 000000000..c3ed1c166 --- /dev/null +++ b/scripts/pylint_checkers/crlf.py @@ -0,0 +1,28 @@ +"""Checker for CRLF in files.""" + +from pylint.interfaces import IRawChecker +from pylint.checkers import BaseChecker + + +class CrlfChecker(BaseChecker): + + """Check for CRLF in files.""" + + __implements__ = IRawChecker + + name = 'crlf' + msgs = {'W9001': ('Uses CRLFs', 'crlf', None)} + options = () + priority = -1 + + def process_module(self, node): + """Process the module.""" + for (lineno, line) in enumerate(node.file_stream): + if b'\r\n' in line: + self.add_message('crlf', line=lineno) + return + + +def register(linter): + """Register the checker.""" + linter.register_checker(CrlfChecker(linter)) diff --git a/scripts/run_checks.py b/scripts/run_checks.py index 690293ed0..a61a7e72b 100755 --- a/scripts/run_checks.py +++ b/scripts/run_checks.py @@ -68,7 +68,8 @@ options = { 'other': { 'pylint': ['--output-format=colorized', '--reports=no', '--rcfile=.pylintrc', - '--load-plugins=pylint_checkers.config'], + '--load-plugins=pylint_checkers.config,' + 'pylint_checkers.crlf'], 'flake8': ['--config=.flake8'], }, } @@ -198,10 +199,7 @@ def _check_file(fn): ok = True with open(fn, 'rb') as f: for line in f: - if b'\r\n' in line: - print("Found CRLF in {}".format(fn)) - ok = False - elif any(line.decode('UTF-8').startswith(c * 7) for c in "<>=|"): + if any(line.decode('UTF-8').startswith(c * 7) for c in "<>=|"): print("Found conflict marker in {}".format(fn)) ok = False elif b'set_trace()' in line and not (