Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ladislas/bugfix/hook check yaml #687

Merged
merged 8 commits into from
Feb 16, 2024
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
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
Loading