summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--pylint/checkers/format.py2
-rw-r--r--pylint/config.py13
-rw-r--r--pylint/test/test_self.py7
4 files changed, 22 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index dcc7f15cd..edbbbfc69 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,7 +2,9 @@ ChangeLog for Pylint
--------------------
--
-
+
+ * empty indent strings are rejected.
+
* Suppress reporting 'unneeded-not' inside `__ne__` methods
Closes issue #749.
diff --git a/pylint/checkers/format.py b/pylint/checkers/format.py
index 7930074d7..2bf79dd11 100644
--- a/pylint/checkers/format.py
+++ b/pylint/checkers/format.py
@@ -453,7 +453,7 @@ class FormatChecker(BaseTokenChecker):
'help': 'Maximum number of lines in a module'}
),
('indent-string',
- {'default' : ' ', 'type' : "string", 'metavar' : '<string>',
+ {'default' : ' ', 'type' : "non_empty_string", 'metavar' : '<string>',
'help' : 'String used as indentation unit. This is usually '
'" " (4 spaces) or "\\t" (1 tab).'}),
('indent-after-paren',
diff --git a/pylint/config.py b/pylint/config.py
index ba4e86559..ee6b7a364 100644
--- a/pylint/config.py
+++ b/pylint/config.py
@@ -174,6 +174,13 @@ def _yn_validator(opt, _, value):
raise optparse.OptionValueError(msg % (opt, value))
+def _non_empty_string_validator(opt, _, value):
+ if not len(value):
+ msg = "indent string can't be empty."
+ raise optparse.OptionValueError(msg)
+ return value
+
+
VALIDATORS = {
'string': utils._unquote,
'int': int,
@@ -182,6 +189,7 @@ VALIDATORS = {
'yn': _yn_validator,
'choice': _choice_validator,
'multiple_choice': _multiple_choice_validator,
+ 'non_empty_string': _non_empty_string_validator,
}
def _call_validator(opttype, optdict, option, value):
@@ -250,13 +258,16 @@ def _patch_optparse():
class Option(optparse.Option):
- TYPES = optparse.Option.TYPES + ('regexp', 'csv', 'yn', 'multiple_choice')
+ TYPES = optparse.Option.TYPES + ('regexp', 'csv', 'yn',
+ 'multiple_choice',
+ 'non_empty_string')
ATTRS = optparse.Option.ATTRS + ['hide', 'level']
TYPE_CHECKER = copy.copy(optparse.Option.TYPE_CHECKER)
TYPE_CHECKER['regexp'] = _regexp_validator
TYPE_CHECKER['csv'] = _csv_validator
TYPE_CHECKER['yn'] = _yn_validator
TYPE_CHECKER['multiple_choice'] = _multiple_choice_validator
+ TYPE_CHECKER['non_empty_string'] = _non_empty_string_validator
def __init__(self, *opts, **attrs):
optparse.Option.__init__(self, *opts, **attrs)
diff --git a/pylint/test/test_self.py b/pylint/test/test_self.py
index 0ec186840..831cdb990 100644
--- a/pylint/test/test_self.py
+++ b/pylint/test/test_self.py
@@ -290,7 +290,12 @@ class RunTC(unittest.TestCase):
package = join(HERE, 'regrtest_data', 'dummy')
self._test_output([package, '--disable=locally-disabled', '-rn'],
expected_output=expected)
-
+
+ def test_reject_empty_indent_strings(self):
+ expected = "indent string can't be empty"
+ module = join(HERE, 'data', 'clientmodule_test.py')
+ self._test_output([module, '--indent-string='],
+ expected_output=expected)
if __name__ == '__main__':