Commit 868bd544 authored by Philipp Wolfer's avatar Philipp Wolfer

This allows setting a default_disabled flag for checks.

This generalizes the current implementation for the format checks and allows custom checks that are disabled by default but can be explicitly enabled using the proper flag.
parent aeda76e3
......@@ -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
......
......@@ -105,16 +105,13 @@ class BaseFormatCheck(TargetCheck):
'''
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(
......
......@@ -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