Skip to content

Commit

Permalink
bears/gettext: Add DennisBear
Browse files Browse the repository at this point in the history
Linter bear for translated PO and POT files.

Closes coala#892
  • Loading branch information
yp-palF authored and sils committed Jan 10, 2017
1 parent 9d9c018 commit 9c1a0bf
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 0 deletions.
1 change: 1 addition & 0 deletions bear-requirements.txt
Expand Up @@ -4,6 +4,7 @@ bandit~=1.2
cmakelint~=1.3
cppclean~=0.12.0
cpplint~=1.3
dennis~=0.8
eradicate~=0.1.6
guess-language-spirit~=0.5.2
html-linter~=0.3.0
Expand Down
41 changes: 41 additions & 0 deletions bears/gettext/DennisBear.py
@@ -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 = {'coala-devel@googlegroups.com'}
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 added bears/gettext/__init__.py
Empty file.
30 changes: 30 additions & 0 deletions tests/gettext/DennisBearTest.py
@@ -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 added tests/gettext/__init__.py
Empty file.
Empty file.
4 changes: 4 additions & 0 deletions tests/gettext/test_files/dennis_invalid_test.po
@@ -0,0 +1,4 @@
msgid 'Foo'
msgstr 'Foo'
msgid 'Foo'
msgstr ' '
6 changes: 6 additions & 0 deletions tests/gettext/test_files/dennis_valid_test.po
@@ -0,0 +1,6 @@
msgid 'Foo'
msgstr 'Foo'
msgid '{Foo} hi'
msgstr '{Foo}'
msgid '%s Foo'
msgstr '%s Foo'

0 comments on commit 9c1a0bf

Please sign in to comment.