Repository: asottile/yesqa

Issue:
yesqa fails with ValueError if show-source is enabled
When the `flake8` option `show-source` is set to `True`, `yesqa` fails with `ValueError`.

```
Traceback (most recent call last):
  File ".../bin/yesqa", line 10, in <module>
    sys.exit(main())
  File ".../lib/python3.7/site-packages/yesqa.py", line 158, in main
    retv |= fix_file(filename)
  File ".../lib/python3.7/site-packages/yesqa.py", line 123, in fix_file
    flake8_results = _run_flake8(tmpfile.name)
  File ".../lib/python3.7/site-packages/yesqa.py", line 30, in _run_flake8
    lineno, code = line.split('\t')
ValueError: not enough values to unpack (expected 2, got 1)
```

Setting `show-source` to `False` in the flake8 configuration (in my case, `setup.cfg`) fixes the issue.

Discussion:

Patch:
diff --git a/yesqa.py b/yesqa.py
index 431a8f8..860cb44 100644
--- a/yesqa.py
+++ b/yesqa.py
@@ -27,8 +27,13 @@ def _run_flake8(filename: str) -> Dict[int, Set[str]]:
     out, _ = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()
     ret: Dict[int, Set[str]] = collections.defaultdict(set)
     for line in out.decode().splitlines():
-        lineno, code = line.split('\t')
-        ret[int(lineno)].add(code)
+        # TODO: use --no-show-source when that is released instead
+        try:
+            lineno, code = line.split('\t')
+        except ValueError:
+            pass  # ignore additional output besides our --format
+        else:
+            ret[int(lineno)].add(code)
     return ret
 
 


Test patch:
diff --git a/tests/yesqa_test.py b/tests/yesqa_test.py
index 0cf703c..75d1081 100644
--- a/tests/yesqa_test.py
+++ b/tests/yesqa_test.py
@@ -107,3 +107,13 @@ def test_main(tmpdir, capsys):
     assert g.read() == 'x = 1\n'
     out, _ = capsys.readouterr()
     assert out == f'Rewriting {g}\n'
+
+
+def test_show_source_in_config(tmpdir, capsys):
+    f = tmpdir.join('f.py')
+    f.write('import os  # noqa\n')
+    tmpdir.join('tox.ini').write('[flake8]\nshow_source = true\n')
+    with tmpdir.as_cwd():
+        ret = yesqa.main((str(f),))
+    assert ret == 0
+    assert f.read() == 'import os  # noqa\n'