-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔀 Merge branch 'ladislas/bugfix/hook-check-yaml'
- Loading branch information
Showing
14 changed files
with
490 additions
and
538 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[flake8] | ||
max-line-length = 120 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
Oops, something went wrong.