Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# EditorConfig for app/ — ensures consistent formatting across editors
# https://editorconfig.org

root = true

[*.{arb,json}]
indent_style = space
indent_size = 4
insert_final_newline = true
charset = utf-8
26 changes: 26 additions & 0 deletions scripts/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,32 @@ if [ -n "$STAGED_PYTHON_FILES" ]; then
echo "$STAGED_PYTHON_FILES" | xargs git add
fi

# ARB (l10n JSON) formatting for app/lib/l10n/
STAGED_ARB_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.arb$')

if [ -n "$STAGED_ARB_FILES" ]; then
BAD_ARB=""
for f in $STAGED_ARB_FILES; do
if grep -qP '^\s{2}"' "$f" && ! grep -qP '^\s{4}"' "$f"; then
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this logic won't detect 2-space indented ARB files with nested objects. ARB files have metadata like @key with nested description fields, so a 2-space file would have lines with both 2 spaces (level 1) and 4 spaces (level 2). the condition fails because ! grep -qP '^\s{4}"' returns false

Suggested change
if grep -qP '^\s{2}"' "$f" && ! grep -qP '^\s{4}"' "$f"; then
if grep -qP '^\s{2}"' "$f"; then

BAD_ARB="$BAD_ARB $f"
fi
done
if [ -n "$BAD_ARB" ]; then
if command -v jq >/dev/null 2>&1; then
echo "Reformatting ARB files to 4-space indent..."
for f in $BAD_ARB; do
jq --indent 4 '.' "$f" > "$f.tmp" && mv "$f.tmp" "$f"
done
echo "$BAD_ARB" | xargs git add
else
echo "ERROR: These ARB files use 2-space indent instead of 4-space:" >&2
echo "$BAD_ARB" >&2
echo "Install jq to auto-fix, or reformat manually with: jq --indent 4 '.' <file>" >&2
exit 1
fi
fi
fi

# C/C++ formatting for firmware/
STAGED_C_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(c|cpp|cc|cxx|h|hpp)$' | grep -E '^(omi/|omiGlass/)')

Expand Down