Skip to content

Commit 8b4c071

Browse files
twmrPCManticore
authored andcommitted
Comma separated values in the configuration file appear one item per line
This change makes list-like output in all sections more readable (one item per line).
1 parent d3e30fc commit 8b4c071

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

pylint/test/test_self.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from pylint.reporters.text import *
2222
from pylint.reporters.json import JSONReporter
2323
import pytest
24+
from pylint import utils
2425

2526
HERE = abspath(dirname(__file__))
2627

@@ -159,7 +160,7 @@ def test_generate_config_disable_symbolic_names(self):
159160
out = six.StringIO(output[master.start():])
160161
parser = six.moves.configparser.RawConfigParser()
161162
parser.readfp(out)
162-
messages = parser.get('MESSAGES CONTROL', 'disable').split(",")
163+
messages = utils._splitstrip(parser.get('MESSAGES CONTROL', 'disable'))
163164
assert 'suppressed-message' in messages
164165

165166
def test_generate_rcfile_no_obsolete_methods(self):

pylint/utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,8 @@ def _splitstrip(string, sep=','):
10601060
['a', 'b', 'c', '4']
10611061
>>> _splitstrip('a')
10621062
['a']
1063-
>>>
1063+
>>> _splitstrip('a,\nb,\nc,')
1064+
['a', 'b', 'c']
10641065
10651066
:type string: str or unicode
10661067
:param string: a csv line
@@ -1168,6 +1169,12 @@ def _ini_format(stream, options, encoding):
11681169
print('#%s=' % optname, file=stream)
11691170
else:
11701171
value = _encode(value, encoding).strip()
1172+
if re.match(r'^([\w-]+,)+[\w-]+$', str(value)):
1173+
separator = '\n ' + ' ' * len(optname)
1174+
value = separator.join(
1175+
x + ',' for x in str(value).split(','))
1176+
# remove trailing ',' from last element of the list
1177+
value = value[:-1]
11711178
print('%s=%s' % (optname, value), file=stream)
11721179

11731180
format_section = _ini_format_section

0 commit comments

Comments
 (0)