Add a new CLI command to lint PO files
Partially addresses https://github.com/python-babel/babel/issues/1011
This adds a new lint command to babel:
$ pybabel lint --help
Usage: pybabel lint [options] <input-paths>
check message catalogs for common problems
Options:
-h, --help show this help message and exit
Example output:
$ pybabel lint messages.po
messages.po:20: placeholders in msgid differ from placeholders in msgstr:
placeholders in msgid but missing in msgstr: {foo}
placeholders in msgstr but missing in msgid: {bar}
The implementation is based on my team's implementation in Indico.
Some notes:
- Currently only f-string placeholders are checked. I didn't implement the old %-style formatting to keep the diff smaller, but I can add it later.
- There are currently no CLI options besides the
input-paths. We might want to consider adding a parameter to ignore a specific file/msgid but that can again be added later.
Feedback welcome!
(@akx would you mind taking a look?)
Codecov Report
Attention: Patch coverage is 93.24324% with 5 lines in your changes missing coverage. Please review.
Project coverage is 91.34%. Comparing base (
9d25e67) to head (3248f82). Report is 10 commits behind head on master.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| babel/messages/frontend.py | 93.24% | 5 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## master #1168 +/- ##
==========================================
- Coverage 91.47% 91.34% -0.14%
==========================================
Files 27 27
Lines 4636 4728 +92
==========================================
+ Hits 4241 4319 +78
- Misses 395 409 +14
| Flag | Coverage Δ | |
|---|---|---|
| macos-14-3.10 | 90.37% <93.24%> (+0.12%) |
:arrow_up: |
| macos-14-3.11 | 90.31% <93.24%> (+0.12%) |
:arrow_up: |
| macos-14-3.12 | 90.52% <93.24%> (+0.12%) |
:arrow_up: |
| macos-14-3.13 | 90.52% <93.24%> (+0.12%) |
:arrow_up: |
| macos-14-3.8 | 90.24% <93.24%> (+0.06%) |
:arrow_up: |
| macos-14-3.9 | 90.30% <93.24%> (+0.12%) |
:arrow_up: |
| macos-14-pypy3.10 | 90.37% <93.24%> (+0.12%) |
:arrow_up: |
| ubuntu-24.04-3.10 | 90.39% <93.24%> (+0.12%) |
:arrow_up: |
| ubuntu-24.04-3.11 | 90.33% <93.24%> (+0.12%) |
:arrow_up: |
| ubuntu-24.04-3.12 | 90.54% <93.24%> (+0.12%) |
:arrow_up: |
| ubuntu-24.04-3.13 | 90.54% <93.24%> (+0.12%) |
:arrow_up: |
| ubuntu-24.04-3.8 | 90.26% <93.24%> (+0.06%) |
:arrow_up: |
| ubuntu-24.04-3.9 | 90.32% <93.24%> (+0.12%) |
:arrow_up: |
| ubuntu-24.04-pypy3.10 | 90.39% <93.24%> (+0.12%) |
:arrow_up: |
| windows-2022-3.10 | 90.40% <93.24%> (+0.01%) |
:arrow_up: |
| windows-2022-3.11 | 90.34% <93.24%> (+0.01%) |
:arrow_up: |
| windows-2022-3.12 | 90.55% <93.24%> (+0.01%) |
:arrow_up: |
| windows-2022-3.13 | 90.55% <93.24%> (+0.01%) |
:arrow_up: |
| windows-2022-3.8 | 90.38% <93.24%> (+0.06%) |
:arrow_up: |
| windows-2022-3.9 | 90.33% <93.24%> (+0.01%) |
:arrow_up: |
| windows-2022-pypy3.10 | 90.40% <93.24%> (+0.01%) |
:arrow_up: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Why the new checker is not added to babel/messages/checkers.py? It could check using Message.check() method if added. Also, checker for %-styling formatting is already implemented.
(Side note: Trac provides check_catalog command via setup.py to check catalogs using the method.)
Why the new checker is not added to babel/messages/checkers.py?
Yeah, that might be a good idea. I'll look into that :)
Perhaps it might make more sense to start with implementing the python-brace-format flag