Skip to content

Commit 2e4e47e

Browse files
committed
fix(pre-commit): It should not "fix" .svg files
The update_vehicle_templates.py script should not produce files that conflict with the pre-comit rules
1 parent 4000c44 commit 2e4e47e

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ repos:
77
rev: v5.0.0
88
hooks:
99
- id: end-of-file-fixer
10-
- id: trailing-whitespace
1110
exclude: \.svg$
11+
- id: trailing-whitespace
1212
- id: check-added-large-files
1313
- id: check-case-conflict
1414
- id: check-executables-have-shebangs

ardupilot_methodic_configurator/backend_filesystem_json_with_schema.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"""
1010

1111
from json import JSONDecodeError
12-
from json import dump as json_dump
12+
from json import dumps as json_dumps
1313
from json import load as json_load
1414

1515
# from logging import warning as logging_warning
@@ -125,8 +125,10 @@ def save_json_data(self, data: dict, data_dir: str) -> tuple[bool, str]: # noqa
125125
filepath = os_path.join(data_dir, self.json_filename)
126126
try:
127127
with open(filepath, "w", encoding="utf-8", newline="\n") as file:
128-
json_dump(data, file, indent=4)
129-
file.write("\n") # pre-commit recommends adding an extra newline at the end of the file
128+
json_str = json_dumps(data, indent=4)
129+
# Strip the last newline to avoid double newlines
130+
# This is to ensure compatibility with pre-commit's end-of-file-fixer
131+
file.write(json_str.rstrip("\n") + "\n")
130132
except FileNotFoundError:
131133
msg = _("Directory '{}' not found").format(data_dir)
132134
logging_error(msg)

0 commit comments

Comments
 (0)