tox-dev / tox-ini-fmt

Formats your tox.ini files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

last trailing comma in an envlist gets turned into three trailing whitespaces

jugmac00 opened this issue · comments

I swapped the whitespaces for numbers to make them visible.

 [tox]
 envlist =
-    py36,
-    py37,
-    py38,
-    pre-commit,
-    mypy,
+    py38
+    py37
+    py36
+    pre-commit
+    mypy
+123

Can you post a reproducible example 🤔

e.g.
https://github.com/jugmac00/flask-reuploaded/blob/master/tox.ini

The problem is reproducible for me for different tox.ini files, when the last env in the envlist has a trailing comma.

I would have a look myself tomorrow as the envlist parsing seems to be related to the flake8 e.g. ignore entry.

Found it. I will create a PR tomorrow.

With a envlist like

[tox]
envlist =
    py38,
    py39,
    pre-commit,
    mypy,

to_list_of_env_values wrongly outputs
'\npy39\npy38\npy37\npy36\npre-commit\nmypy\n'
(note the trailing newline), which results in
'[tox]\nenvlist = \n\tpy39\n\tpy38\n\tpy37\n\tpy36\n\tpre-commit\n\tmypy\n\t\n\n[pytest]\npython_classes = Test[A-Z]*\n\n'.

The tabs get replaced by 4 spaces (result = result.replace("\t", INDENTATION)) and then result = result.replace(" \n", "\n") removes one of them, leading to the at first confusing 3 spaces :-)

This only matters when there is more than one key/value pair - otherwise result = output.getvalue().strip() "fixes" the additional tabs and newlines.