mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:44:58 +00:00
Meta: Resolve some pylint violations in Python lint scripts
Resolves: * all: consider-using-sys-exit * all: wrong-import-order * all: TODO: Require that a few keys are set? (fixme) * some: missing-function-docstring * some: line-too-long
This commit is contained in:
parent
e875513ff7
commit
666aeecaa2
4 changed files with 140 additions and 54 deletions
|
@ -4,57 +4,64 @@ import os
|
|||
import subprocess
|
||||
import sys
|
||||
|
||||
os.chdir(os.path.dirname(__file__) + "/..")
|
||||
|
||||
files = subprocess.run(
|
||||
[
|
||||
"git", "ls-files", "--",
|
||||
"*.cpp",
|
||||
"*.h",
|
||||
"*.gml",
|
||||
"*.html",
|
||||
"*.js",
|
||||
"*.css",
|
||||
"*.sh",
|
||||
"*.py",
|
||||
"*.json",
|
||||
"CMake*.txt",
|
||||
"**/CMake*.txt",
|
||||
":!:AK/Tests/*.json",
|
||||
":!:Kernel/FileSystem/ext2_fs.h",
|
||||
":!:Userland/Libraries/LibELF/exec_elf.h"
|
||||
],
|
||||
capture_output=True
|
||||
).stdout.decode().strip('\n').split('\n')
|
||||
def run():
|
||||
"""Check files checked in to git for trailing newlines at end of file."""
|
||||
files = subprocess.run(
|
||||
[
|
||||
"git", "ls-files", "--",
|
||||
"*.cpp",
|
||||
"*.h",
|
||||
"*.gml",
|
||||
"*.html",
|
||||
"*.js",
|
||||
"*.css",
|
||||
"*.sh",
|
||||
"*.py",
|
||||
"*.json",
|
||||
"CMake*.txt",
|
||||
"**/CMake*.txt",
|
||||
":!:AK/Tests/*.json",
|
||||
":!:Kernel/FileSystem/ext2_fs.h",
|
||||
":!:Userland/Libraries/LibELF/exec_elf.h"
|
||||
],
|
||||
check=True,
|
||||
capture_output=True
|
||||
).stdout.decode().strip('\n').split('\n')
|
||||
|
||||
no_newline_at_eof_errors = []
|
||||
blank_lines_at_eof_errors = []
|
||||
no_newline_at_eof_errors = []
|
||||
blank_lines_at_eof_errors = []
|
||||
|
||||
did_fail = False
|
||||
for filename in files:
|
||||
with open(filename, "r") as f:
|
||||
f.seek(0, os.SEEK_END)
|
||||
did_fail = False
|
||||
for filename in files:
|
||||
with open(filename, "r") as f:
|
||||
f.seek(0, os.SEEK_END)
|
||||
|
||||
f.seek(f.tell() - 1, os.SEEK_SET)
|
||||
if f.read(1) != '\n':
|
||||
did_fail = True
|
||||
no_newline_at_eof_errors.append(filename)
|
||||
continue
|
||||
|
||||
while True:
|
||||
f.seek(f.tell() - 2, os.SEEK_SET)
|
||||
char = f.read(1)
|
||||
if not char.isspace():
|
||||
break
|
||||
if char == '\n':
|
||||
f.seek(f.tell() - 1, os.SEEK_SET)
|
||||
if f.read(1) != '\n':
|
||||
did_fail = True
|
||||
blank_lines_at_eof_errors.append(filename)
|
||||
break
|
||||
no_newline_at_eof_errors.append(filename)
|
||||
continue
|
||||
|
||||
if no_newline_at_eof_errors:
|
||||
print("Files with no newline at the end:", " ".join(no_newline_at_eof_errors))
|
||||
if blank_lines_at_eof_errors:
|
||||
print("Files that have blank lines at the end:", " ".join(blank_lines_at_eof_errors))
|
||||
while True:
|
||||
f.seek(f.tell() - 2, os.SEEK_SET)
|
||||
char = f.read(1)
|
||||
if not char.isspace():
|
||||
break
|
||||
if char == '\n':
|
||||
did_fail = True
|
||||
blank_lines_at_eof_errors.append(filename)
|
||||
break
|
||||
|
||||
if did_fail:
|
||||
sys.exit(1)
|
||||
if no_newline_at_eof_errors:
|
||||
print("Files with no newline at the end:", " ".join(no_newline_at_eof_errors))
|
||||
if blank_lines_at_eof_errors:
|
||||
print("Files that have blank lines at the end:", " ".join(blank_lines_at_eof_errors))
|
||||
|
||||
if did_fail:
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
os.chdir(os.path.dirname(__file__) + "/..")
|
||||
run()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue