diff options
| author | 2025-09-01 15:47:16 +0200 | |
|---|---|---|
| committer | 2025-09-01 15:47:16 +0200 | |
| commit | 1f15d552a6d6c39e7e689f6c928623135cc2ff86 (patch) | |
| tree | fee2e5c8bbecadff67fd75c36d7a42b0a826873c /scripts/build | |
| parent | 86ccea91c23af9f35570cea43ab9ecc6192d2586 (diff) | |
scripts/build: add a python script for checking EoF markers across source treescript-eof-marker
Diffstat (limited to 'scripts/build')
| -rw-r--r-- | scripts/build/check_eof.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/scripts/build/check_eof.py b/scripts/build/check_eof.py new file mode 100644 index 00000000000..d681ca8edcd --- /dev/null +++ b/scripts/build/check_eof.py @@ -0,0 +1,27 @@ +#!/usr/bin/python3 +## +## license:BSD-3-Clause +## copyright-holders:Angelo Salese +"""Checks that all files in source code ends with a newline at end of file +""" + +import os +import sys + +if __name__ == '__main__': + CHAR_DEPTH = 2 if sys.platform in ["win32", "cygwin"] else 1 + for r, _, f in os.walk("src"): + FILEPATHS = [os.path.join(r, file) for file in f] + for item in FILEPATHS: + if not item.endswith((".cpp", ".h", ".mm", ".lua", ".py")): + continue + with open(item, mode="r", encoding="utf-8") as fh: + try: + fh.seek(0, os.SEEK_END) + fh.seek(fh.tell() - CHAR_DEPTH, os.SEEK_SET) + value = fh.read(CHAR_DEPTH) + if value != os.linesep: + raise ValueError(value, item) + except UnicodeDecodeError: + print(item, file=sys.stderr) + raise |
