forked from coala/coala-bears
-
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.
Linter bear for translated PO and POT files. Closes coala#892
- Loading branch information
Showing
8 changed files
with
82 additions
and
0 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
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,41 @@ | ||
from coalib.bearlib.abstractions.Linter import linter | ||
from coalib.results.RESULT_SEVERITY import RESULT_SEVERITY | ||
from dependency_management.requirements.PipRequirement import PipRequirement | ||
|
||
|
||
@linter(executable='dennis-cmd', | ||
output_format='regex', | ||
output_regex=r'(?P<message>(?P<severity>[EW])[0-9]{3}: .*)' | ||
r'\n(?P<line>[0-9]+):.*\n(?P<end_line>[0-9]+):.*', | ||
severity_map={'W': RESULT_SEVERITY.NORMAL, | ||
'E': RESULT_SEVERITY.MAJOR}) | ||
class DennisBear: | ||
""" | ||
Lints your translated PO and POT files! | ||
Check multiple lint rules on all the strings in the PO file | ||
generating a list of errors and a list of warnings. | ||
See http://dennis.readthedocs.io/en/latest/linting.html for | ||
list of all error codes. | ||
http://dennis.readthedocs.io/ | ||
""" | ||
|
||
LANGUAGES = {'po', 'pot'} | ||
REQUIREMENTS = {PipRequirement('dennis', '0.8')} | ||
AUTHORS = {'The coala developers'} | ||
AUTHORS_EMAILS = {'[email protected]'} | ||
LICENSE = 'AGPL-3.0' | ||
CAN_DETECT = {'Syntax'} | ||
|
||
@staticmethod | ||
def create_arguments(filename, file, config_file, allow_untranslated=True): | ||
""" | ||
:param allow_untranslated: Set to false to display unchanged | ||
translation warning. | ||
""" | ||
if allow_untranslated: | ||
return ('lint', filename, '--excluderules', 'W302') | ||
else: | ||
return ('lint', filename) |
Empty file.
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,30 @@ | ||
import os | ||
from queue import Queue | ||
|
||
|
||
from bears.gettext.DennisBear import DennisBear | ||
from coalib.testing.LocalBearTestHelper import LocalBearTestHelper | ||
from coalib.settings.Section import Section | ||
from coalib.settings.Setting import Setting | ||
|
||
|
||
class DennisBearTest(LocalBearTestHelper): | ||
|
||
def setUp(self): | ||
self.section = Section('test section') | ||
self.uut = DennisBear(self.section, Queue()) | ||
self.valid_test_file = os.path.join(os.path.dirname(__file__), | ||
'test_files', | ||
'dennis_valid_test.po') | ||
self.invalid_test_file = os.path.join(os.path.dirname(__file__), | ||
'test_files', | ||
'dennis_invalid_test.po') | ||
|
||
def test_valid(self): | ||
self.check_validity(self.uut, [], self.valid_test_file) | ||
|
||
def test_invalid(self): | ||
self.check_validity(self.uut, [], self.invalid_test_file, valid=False) | ||
# Test without ignoring W302 | ||
self.section.append(Setting('allow_untranslated', 'False')) | ||
self.check_validity(self.uut, [], self.valid_test_file, valid=False) |
Empty file.
Empty file.
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,4 @@ | ||
msgid 'Foo' | ||
msgstr 'Foo' | ||
msgid 'Foo' | ||
msgstr ' ' |
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,6 @@ | ||
msgid 'Foo' | ||
msgstr 'Foo' | ||
msgid '{Foo} hi' | ||
msgstr '{Foo}' | ||
msgid '%s Foo' | ||
msgstr '%s Foo' |