Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds isort output to each warning #61

Merged
merged 3 commits into from Dec 1, 2018
Merged

Adds isort output to each warning #61

merged 3 commits into from Dec 1, 2018

Conversation

sobolevn
Copy link
Contributor

This PR introduces new warning output style.
It now includes isort diff with how to fix your warning.

Works the same way as pytest-isort.

Problem (multiple spaces):

import   os

Old warning:

flake8_isort.py:7:1: I001 isort found an import in the wrong position
flake8_isort.py:7:7: E271 multiple spaces after keyword

New warning:

flake8_isort.py:7:1: I001 isort found an import in the wrong position

 from os.path import expanduser
 from testfixtures import OutputCapture
 
-import   os
+import os
 
 
 try:

flake8_isort.py:7:7: E271 multiple spaces after keyword

Closes #60

@sobolevn
Copy link
Contributor Author

@gforcada tests show different behavior locally and inside CI.

@gforcada
Copy link
Owner

@sobolevn hi! 👋

Thanks for this pull request! I'm a bit hesitant to merge this right away... as far as I've seen all flake8 errors are a single line long without extra lines, and this clearly breaks it, and given that, at least I'm not aware of it, no other flake8 plugins provide error messages that spans more than a line.

Would you mind if we gate this new output by a configuration parameter (--extended-output or the sorts)?

If other flake8 plugins do provide multiline output, then I would be totally fine with it.

@gforcada
Copy link
Owner

@sobolevn regarding the difference between locally and in CI: you probably have some generic configuration files on your home folder, right? I could reproduce the same errors as you mentioned, but forcing (with pdb) the settings file to not be found, on that specific test that fails locally, it made the test pass.

@sobolevn
Copy link
Contributor Author

@gforcada hm, never thought about flake8 and single line outputs.
I have made this plugin that shows pretty much the same sized diff: https://github.com/sobolevn/flake8-eradicate

I have also checked the flake8 docs to mention that, with no success: http://flake8.pycqa.org/en/latest/plugin-development/formatters.html

Considering making it optional: yes, that's a good thing. I can implement this option. But, the question is: should be turned on or off by default?

@gforcada
Copy link
Owner

@sobolevn nice plugin, I will add it to my list of flake8 plugins! 💯

As for the configuration option... I would say to keep it off by default and maybe raise a question on flake8 itself for directives regarding the output format? If there is consensus on multiline output we can then change it to on by default.

Does that sound acceptable for you? 🤔

Thanks for your patience! 🙇‍♂️

@sobolevn
Copy link
Contributor Author

@gforcada sure, let's make it off by default. I will update my PR soon.
Thank you for guidance!

@sobolevn
Copy link
Contributor Author

sobolevn commented Dec 1, 2018

@gforcada sorry that it took me so long.

I have been busy working on this project: https://github.com/wemake-services/wemake-python-styleguide Which uses flake8-isort as a dependency.

Now, this is my top level priority. 🙂

@sobolevn
Copy link
Contributor Author

sobolevn commented Dec 1, 2018

Just for the reference. We still have this flaky test:

______________________ TestFlake8Isort.test_isortcfg_not_found _______________________

self = <run_tests.TestFlake8Isort testMethod=test_isortcfg_not_found>

    def test_isortcfg_not_found(self):
        (file_path, lines) = self._given_a_file_in_test_dir(
            'from sys import pid\n'
            'import threading',
            isort_config='force_single_line=True'
        )
        # remove the .isort.cfg file
        isortcfg_path = file_path.split('/')[: -1]
        isortcfg_path = '{0}/.isort.cfg'.format('/'.join(isortcfg_path))
        os.remove(isortcfg_path)

        with OutputCapture():
            checker = Flake8Isort(None, file_path, lines, search_current=False)
            checker.config_file = True
            ret = list(checker.run())
            self.assertEqual(len(ret), 1)
>           self.assertEqual(ret[0][0], 0)
E           AssertionError: 2 != 0

run_tests.py:242: AssertionError
======================== 1 failed, 17 passed in 0.63 seconds =========================

It fails locally and passes in travis.

@gforcada
Copy link
Owner

gforcada commented Dec 1, 2018

@sobolevn I guess that this one fails locally because you probably have some configuration file in your home or up in the folder hierarchy where this test is. If travis is always happy about it, then I would not refactor it.

@gforcada gforcada merged commit 3b26e5a into gforcada:master Dec 1, 2018
@gforcada
Copy link
Owner

gforcada commented Dec 1, 2018

@sobolevn flake8-isort 2.6.0 is out 🚀 🎆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improving output
2 participants