Commit 886278db authored by Michal Čihař's avatar Michal Čihař

Merge pull request #778 from phw/checks-can-be-disabled-by-default

Checks can be disabled by default
parents 72d423c8 bcf3895f
......@@ -32,17 +32,22 @@ class Check(object):
target = False
source = False
ignore_untranslated = True
default_disabled = False
severity = 'info'
def __init__(self):
id_dash = self.check_id.replace('_', '-')
self.doc_id = 'check-%s' % id_dash
self.enable_string = id_dash
self.ignore_string = 'ignore-%s' % id_dash
def check_target(self, sources, targets, unit):
'''
Checks target strings.
'''
# Is this disabled by default
if self.default_disabled and not self.enable_string in unit.all_flags:
return False
# Is this check ignored
if self.ignore_string in unit.all_flags:
return False
......
......@@ -103,18 +103,14 @@ class BaseFormatCheck(TargetCheck):
'''
Base class for fomat string checks.
'''
flag = None
regexp = None
default_disabled = True
severity = 'danger'
def check_target_unit(self, sources, targets, unit):
'''
Checks single unit, handling plurals.
'''
# Verify unit is properly flagged
if self.flag not in unit.all_flags:
return False
# Special case languages with single plural form
if len(sources) > 1 and len(targets) == 1:
return self.check_format(
......@@ -225,7 +221,6 @@ class PythonFormatCheck(BaseFormatCheck):
check_id = 'python_format'
name = _('Python format')
description = _('Format string does not match source')
flag = 'python-format'
regexp = PYTHON_PRINTF_MATCH
def is_position_based(self, string):
......@@ -239,7 +234,6 @@ class PHPFormatCheck(BaseFormatCheck):
check_id = 'php_format'
name = _('PHP format')
description = _('Format string does not match source')
flag = 'php-format'
regexp = PHP_PRINTF_MATCH
def is_position_based(self, string):
......@@ -253,7 +247,6 @@ class CFormatCheck(BaseFormatCheck):
check_id = 'c_format'
name = _('C format')
description = _('Format string does not match source')
flag = 'c-format'
regexp = C_PRINTF_MATCH
def is_position_based(self, string):
......@@ -267,7 +260,6 @@ class PythonBraceFormatCheck(BaseFormatCheck):
check_id = 'python_brace_format'
name = _('Python brace format')
description = _('Format string does not match source')
flag = 'python-brace-format'
regexp = PYTHON_BRACE_MATCH
def is_position_based(self, string):
......
......@@ -21,14 +21,10 @@ from django.core.exceptions import ValidationError
from django.utils.translation import ugettext as _, ugettext_lazy
from weblate.trans.checks import CHECKS
EXTRA_FLAGS = {v.enable_string: v.name for k, v in CHECKS.iteritems() \
if v.default_disabled}
EXTRA_FLAGS = {
'rst-text': ugettext_lazy('RST text'),
'python-format': ugettext_lazy('Python format string'),
'c-format': ugettext_lazy('C format string'),
'php-format': ugettext_lazy('PHP format string'),
'python-brace-format': ugettext_lazy('Python brace format string'),
}
EXTRA_FLAGS['rst-text'] = ugettext_lazy('RST text')
IGNORE_CHECK_FLAGS = set([CHECKS[x].ignore_string for x in CHECKS])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment