vim-isort icon indicating copy to clipboard operation
vim-isort copied to clipboard

vim-isort as a static syntax checker

Open krzysztof opened this issue 9 years ago • 7 comments

Has anyone tried to add Isort/vim-isort as a syntax checker to syntastic ? All I could find was this issue: https://github.com/scrooloose/syntastic/issues/895

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

krzysztof avatar Nov 26 '15 12:11 krzysztof

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.

johntyree avatar Nov 26 '15 16:11 johntyree

@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?

fisadev avatar Nov 26 '15 17:11 fisadev

@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.

johntyree avatar Nov 26 '15 17:11 johntyree

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.

krzysztof avatar Nov 28 '15 01:11 krzysztof

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.

johntyree avatar Dec 07 '15 17:12 johntyree

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.

krzysztof avatar Dec 07 '15 17:12 krzysztof

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

Chronial avatar Dec 24 '16 23:12 Chronial