Hook removes blank lines not related to imports at all
See original GitHub issueFantastic tool, however below is probably a bug.
Hook removes blank lines, that are not related to imports at all.
Example python script (notice blank lines around docstring):
$ cat test.py
#!/usr/bin/env python3
"""
Here goes synopsis
"""
import os
import random
import time
print("asdf")
Here is my pre-commit config:
$ cat .pre-commit-config.yaml
repos:
- repo: https://github.com/asottile/reorder_python_imports
rev: v1.3.5
hooks:
- id: reorder-python-imports
language_version: python3
Here is the run of the hook:
$ pre-commit run reorder-python-imports
Reorder python imports...................................................Failed
hookid: reorder-python-imports
Files were modified by this hook. Additional output:
Reordering imports in test.py
And the result:
$ cat test.py
#!/usr/bin/env python3
"""
Here goes synopsis
"""
import os
import random
import time
print("asdf")
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (7 by maintainers)
Top Results From Across the Web
Organize imports should remove blank lines within imports
I agree that the current behavior of moving blank lines to the end of the imports is not helpful. But removing them in...
Read more >How to remove blank cells in Excel - Ablebits
The tutorial will teach you how to remove blank spaces in Excel to give your worksheets a clear and professional look. Empty cells...
Read more >Quick fix "Remove unused imports" removes blank lines - Bugs
Using the Quick fix "Remove unusued imports" removes blank lines around the affected import. This is likely not intended, because when organizing imports, ......
Read more >Git Hooks | Atlassian Git Tutorial
Git Hooks are scripts that run automatically every time a particular event occurs in a Git repository. Learn what they do and how...
Read more >How To Manage State with Hooks on React Components
Since you are no longer using the useState Hook, you removed it from the import. Save the file. When you do, the page...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@asottile would you consider a pull request for this (as stated in Feb 2019), or did you change your mind (as implied in the Aug 2019 comment)?
I would like
reorder_python_imports
to preserve all lines before the first import, just like it preserves all lines after the imports. I was about to log a duplicate issue until GitHub pointed me here.Example input (with
import sys
beforeimport os
):Example output from v1.5.1 (import order fixed, but also less blank lines):
I’ve seen enough real world Python code from other people to want to leave any blank lines before the first import alone. They can be purely cosmetic as in this example, but I have often seen loads of script documentation done as comment lines where blank lines were deliberate aids to readability.
I mean, I have my doubts that a simple patch can accomplish that – and I don’t want an option – and in your example the copyright / mit license lines aren’t necessary (that’s what the
LICENSE
file is for, MIT does not require a header – but sure you’d do that for apache2)there has to be “one correct way” and currently that’s to remove it all