Meta: Add script for checking WebIDL files
Some checks are pending
CI / Lagom (false, FUZZ, ubuntu-22.04, Linux, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, macos-14, macOS, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, ubuntu-22.04, Linux, GNU) (push) Waiting to run
CI / Lagom (true, NO_FUZZ, ubuntu-22.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-22.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Push notes / build (push) Waiting to run

This adds a new script for linting WebIDL files, and adds it to the set
of scripts Meta/lint-ci.sh runs. Initially, this script does just one
thing: normalizes IDL definition lines so they start with four spaces.
This commit is contained in:
sideshowbarker 2024-09-10 16:10:05 +09:00 committed by Sam Atkins
parent 51528ec677
commit a7578164d4
Notes: github-actions[bot] 2024-09-10 20:17:50 +00:00
2 changed files with 70 additions and 0 deletions

69
Meta/check-idl-files.py Executable file
View file

@ -0,0 +1,69 @@
#!/usr/bin/env python3
import argparse
import os
import pathlib
import re
import subprocess
import sys
script_name = pathlib.Path(__file__).resolve().name
lines_to_skip = re.compile(
r"^($| *//|\};|#import |.+ includes .+|\[[^\]]+\]"
r"|interface |dictionary |enum |namespace |typedef |callback )"
)
parser = argparse.ArgumentParser()
parser.add_argument("--overwrite-inplace", action=argparse.BooleanOptionalAction)
parser.add_argument('filenames', nargs='*')
args = parser.parse_args()
def find_files_here_or_argv():
if args.filenames:
raw_list = args.filenames
else:
process = subprocess.run(["git", "ls-files"], check=True, capture_output=True)
raw_list = process.stdout.decode().strip("\n").split("\n")
return filter(lambda filename: filename.endswith(".idl"), raw_list)
def run():
"""Lint WebIDL files checked into git for four leading spaces on each line."""
files_without_four_leading_spaces = set()
did_fail = False
for filename in find_files_here_or_argv():
lines = []
with open(filename, "r") as f:
for line_number, line in enumerate(f, start=1):
if lines_to_skip.match(line):
lines.append(line)
continue
if not line.startswith(" "):
if args.overwrite_inplace:
line = " " + line.lstrip()
lines.append(line)
continue
did_fail = True
files_without_four_leading_spaces.add(filename)
print(
f"{filename}:{line_number} error: Line does not start with four spaces:{line.rstrip()}")
lines.append(line)
if args.overwrite_inplace:
with open(filename, "w") as f:
f.writelines(lines)
if files_without_four_leading_spaces:
print("\nWebIDL files that have lines without four leading spaces:",
" ".join(files_without_four_leading_spaces))
if not args.overwrite_inplace:
print(
f"\nTo fix the WebIDL files in place, run: ./Meta/{script_name} --overwrite-inplace")
if did_fail:
sys.exit(1)
if __name__ == "__main__":
os.chdir(os.path.dirname(__file__) + "/..")
run()

View file

@ -15,6 +15,7 @@ set +e
for cmd in \ for cmd in \
Meta/check-debug-flags.sh \ Meta/check-debug-flags.sh \
Meta/check-idl-files.py \
Meta/check-newlines-at-eof.py \ Meta/check-newlines-at-eof.py \
Meta/check-png-sizes.sh \ Meta/check-png-sizes.sh \
Meta/check-style.py \ Meta/check-style.py \