mirror of
https://github.com/dense-analysis/ale
synced 2025-02-27 09:51:02 +00:00
Fix #667 - Do not add extra blank lines for add_blank_lines_for_python_control_statements
This commit is contained in:
parent
b44bd4e24f
commit
b96f5845ed
@ -5,17 +5,20 @@
|
|||||||
function! ale#fixers#generic_python#AddLinesBeforeControlStatements(buffer, lines) abort
|
function! ale#fixers#generic_python#AddLinesBeforeControlStatements(buffer, lines) abort
|
||||||
let l:new_lines = []
|
let l:new_lines = []
|
||||||
let l:last_indent_size = 0
|
let l:last_indent_size = 0
|
||||||
|
let l:last_line_is_blank = 0
|
||||||
|
|
||||||
for l:line in a:lines
|
for l:line in a:lines
|
||||||
let l:indent_size = len(matchstr(l:line, '^ *'))
|
let l:indent_size = len(matchstr(l:line, '^ *'))
|
||||||
|
|
||||||
if l:indent_size <= l:last_indent_size
|
if !l:last_line_is_blank
|
||||||
|
\&& l:indent_size <= l:last_indent_size
|
||||||
\&& match(l:line, '\v^ *(return|if|for|while|break|continue)') >= 0
|
\&& match(l:line, '\v^ *(return|if|for|while|break|continue)') >= 0
|
||||||
call add(l:new_lines, '')
|
call add(l:new_lines, '')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
call add(l:new_lines, l:line)
|
call add(l:new_lines, l:line)
|
||||||
let l:last_indent_size = l:indent_size
|
let l:last_indent_size = l:indent_size
|
||||||
|
let l:last_line_is_blank = empty(split(l:line))
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
return l:new_lines
|
return l:new_lines
|
||||||
|
@ -83,3 +83,29 @@ Expect python(Newlines should be added):
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Given python(A file with a main block):
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
print('hello')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|
||||||
|
Execute(Fix the file):
|
||||||
|
let g:ale_fixers = {'python': ['add_blank_lines_for_python_control_statements']}
|
||||||
|
ALEFix
|
||||||
|
|
||||||
|
Expect python(extra newlines shouldn't be added to the main block):
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
print('hello')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user