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

vim-isort as a static syntax checker #10

Open
krzysztof opened this issue Nov 26, 2015 · 7 comments
Open

vim-isort as a static syntax checker #10

krzysztof opened this issue Nov 26, 2015 · 7 comments

Comments

@krzysztof
Copy link

Has anyone tried to add Isort/vim-isort as a syntax checker to syntastic ?
All I could find was this issue: vim-syntastic/syntastic#895

I would rather be informed of missorts rather than have them sorted automatically after executing the Isort command.

@johntyree
Copy link

Hi. No progress on this that I know of. I more or less gave up, particularly since most of time is spent on larger projects now where cosmetic changes are frowned upon.

@fisadev
Copy link
Owner

fisadev commented Nov 26, 2015

@krzysztof good point. Don't know if Isort is able to "tell" you which imports are not correctly ordered.

@johntyree are you talking about syntastic?

@johntyree
Copy link

@fisadev yes sorry. @krzysztof emailed me asking about it and I thought responding in public would be more useful.

All we really need is for isort to output the line containing unsorted imports, not which imports are out of order. If we were willing to write a dirty hack we could make use of a temp file and diff, but at that point it's honestly probably easier to just contribute upstream or write some VimL to do it.

@krzysztof
Copy link
Author

After skimming through the isort code I think it's going to be quite tricky to get just the line numbers, as isort doesn't seem to detect the imports missortings explicitly, but instead proceeds with sorting the import section according to some predefined rules and then compares the result with the original input (hence the natural orientation towards the diff and "apply changes" features).

I think that analyzing the diff message could still work although as @johntyree said, it will be quite a dirty job to get it right.

@johntyree
Copy link

Patching upstream to support just outputting line numbers or writing something ourselves is probably the only real way to make use of this as a linter. Outputting a diff and doing something with it is going to be really fragile and ugly.

@krzysztof
Copy link
Author

I have to agree with @johntyree on that, although it seems like it will require substantial effort to implement something like this within isort. The way isort seems to be working is to detect the import blocks, sort them according to predefined rules and generate a diff. The concept of line number is not really there at any point. I have forwarded this issue to @timothycrosley.

Parsing a diff is ugly and fragile, but with enough care it should at least produce stable and deterministic output.

@Chronial
Copy link

This can be accomplished via https://pypi.org/project/flake8-isort/

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

No branches or pull requests

4 participants