Skip to content

Commit

Permalink
🔀 Merge branch 'ladislas/bugfix/hook-check-yaml'
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Feb 16, 2024
2 parents f57cb14 + 61cc732 commit be9b67f
Show file tree
Hide file tree
Showing 14 changed files with 490 additions and 538 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max-line-length = 120
10 changes: 6 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,17 @@ repos:
- id: check_xcstrings_stale_entries
name: Check .xcstrings files for stale entries
description: This hook checks .xcstrings files for stale entries
entry: Tools/Hooks/check_xcstrings_stale_entries.sh
language: script
entry: python3 Tools/Hooks/check_xcstrings_stale_entries.py
language: python
additional_dependencies: ["pygments"]
files: '.*\.xcstrings'

- id: check_xcstrings_unusual_terminators
name: Check .xcstrings files for unusual terminators
description: This hook checks .xcstrings files for unusual terminators
entry: Tools/Hooks/check_xcstrings_unusual_terminators.sh
language: script
entry: python3 Tools/Hooks/check_xcstrings_unusual_terminators.py
language: python
additional_dependencies: ["pygments"]
files: '.*\.xcstrings'

- id: check_yaml_definitions_professions
Expand Down
145 changes: 0 additions & 145 deletions Specs/jtd/tests/activity.yml

This file was deleted.

67 changes: 0 additions & 67 deletions Specs/jtd/tests/curriculum.yml

This file was deleted.

80 changes: 0 additions & 80 deletions Specs/jtd/tests/skills.yml

This file was deleted.

57 changes: 57 additions & 0 deletions Tools/Hooks/check_xcstrings_stale_entries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/python3
"""Module providing a hook to check for stale entries in .xcstrings files."""

# Leka - iOS Monorepo
# Copyright APF France handicap
# SPDX-License-Identifier: Apache-2.0

import json
import sys
from pygments import highlight
from pygments.lexers.data import JsonLexer
from pygments.formatters.terminal import TerminalFormatter


def check_for_stale_entries(json_file):
"""Check for stale entries in a .xcstrings file."""
with open(json_file, "r", encoding="utf8") as file:
data = json.load(file)
strings = data.get("strings", {})

stale_entries = []

for key, value in strings.items():
if value.get("extractionState") == "stale":
stale_entries.append((key, strings[key]))

return stale_entries


def main():
"""Main function."""
# ? Check if a file was specified
if len(sys.argv) > 1:
xcstrings_files = sys.argv[1:]
else:
print("❌ No file specified")
sys.exit(1)

must_fail = False

for file in xcstrings_files:
stale_entries = check_for_stale_entries(file)
if stale_entries:
print(f"❌ Stale entries found in {file}")
for key, data in stale_entries:
data = json.dumps(data, indent=4)
print(highlight(f'"{key}": {data}', JsonLexer(), TerminalFormatter()))
must_fail = True

if must_fail:
return 1

return 0


if __name__ == "__main__":
sys.exit(main())
Loading

0 comments on commit be9b67f

Please sign in to comment.