6 from subprocess
import check_output
10 p = argparse.ArgumentParser()
11 p.add_argument(
"input")
12 p.add_argument(
"--exclude", nargs=
"+")
13 p.add_argument(
"--fix", action=
"store_true")
14 p.add_argument(
"--reject-multiple-newlines", action=
"store_true")
15 p.add_argument(
"--github", action=
"store_true")
33 +
sum(([
"-not",
"-path", exclude]
for exclude
in args.exclude), [])
44 file = os.path.normpath(file)
49 if not lines[-1].endswith(
"\n"):
50 print(f
"Missing newline at end of file: {file}")
52 with
open(file,
"a")
as f:
58 f
"::error file={file},line={len(lines)},title=End of file check::missing newline"
60 elif args.reject_multiple_newlines
and lines[-1] ==
"\n":
61 print(f
"Multiple newlines at end of file: {file}")
63 while lines[-1] ==
"\n":
65 with
open(file,
"w")
as f:
66 f.write(
"".
join(lines))
71 f
"::error file={{{file}}},line={{{len(lines)}}},title=End of file check::multiple newlines"
75 print(f
"failed for files: {' '.join(failed)}")
82 if "__main__" == __name__: