Skip to content

Commit

Permalink
pre-commit: Replace required properties automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
Holzhaus committed Jun 8, 2021
1 parent f13e003 commit 26b7e7d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tools/qmlformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import subprocess
import pathlib
import sys
import re

QMLFORMAT_MISSING_MESSAGE = """
qmlformat is not installed or not in your $PATH. It is included in Qt 5.15
Expand All @@ -30,6 +31,20 @@ def main(argv=None):
for filename in args.file:
subprocess.call((qmlformat_executable, "-i", filename))

# Replace required properties
# (incompatible with Qt 5.12)
with open(filename, mode="r") as fp:
text = fp.read()

text = re.sub(
r"^(\s*)required property (.*)$",
r"\g<1>property \g<2> // required",
text,
)

with open(filename, mode="w") as fp:
fp.write(text)

return 0


Expand Down

0 comments on commit 26b7e7d

Please sign in to comment.