From 8aa2bc3d6c1bc65fbc6da9af8a588fcea3552e98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matth=C3=A4us=20G=2E=20Chajdas?= Date: Sun, 20 Sep 2020 10:24:09 +0200 Subject: Add a check for CR/LF in files. (#1547) * Add a check for CR/LF in files. This can occur when checking out things on Windows, and it breaks the tarball. This adds a script to check for the presence of CR/LF which exits early if anything gets found. * Improve error checking. * Include the external folder and check that. * Include .bashcomp files. * Use the correct CR/LF on the checker itself. * Address review feedback. * Remove || true * Fix docs * Print the first offending file name --- scripts/check_crlf.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 scripts/check_crlf.py (limited to 'scripts/check_crlf.py') diff --git a/scripts/check_crlf.py b/scripts/check_crlf.py new file mode 100644 index 00000000..14442d0e --- /dev/null +++ b/scripts/check_crlf.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" + Checker for line endings + ~~~~~~~~~~~~~~~~~~~~~~~~ + + Make sure Python (.py) and Bash completition (.bashcomp) files do not + contain CR/LF newlines. + + :copyright: Copyright 2006-2020 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import sys +import os + +if __name__ == '__main__': + for directory in sys.argv[1:]: + if not os.path.exists(directory): + continue + + for root, dirs, files in os.walk(directory): + for filename in files: + if not filename.endswith('.py') and not filename.endswith('.bashcomp'): + continue + + full_path = os.path.join(root, filename) + with open(full_path, 'rb') as f: + if b'\r\n' in f.read(): + print('CR/LF found in', full_path) + sys.exit(1) + + sys.exit(0) -- cgit v1.2.1