All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
1 " Author: w0rp <devw0rp@gmail.com>
2 " Description: Generic fixer functions for Python.
4 " Add blank lines before control statements.
5 function! ale#fixers#generic_python#AddLinesBeforeControlStatements(buffer, lines) abort
7 let l:last_indent_size = 0
8 let l:last_line_is_blank = 0
12 let l:indent_size = len(matchstr(l:line, '^ *'))
15 " Make sure it is not just a single line docstring and then verify
16 " it's starting a new docstring
17 if match(l:line, '\v^ *("""|'''''').*("""|'''''')') == -1
18 \&& match(l:line, '\v^ *("""|'''''')') >= 0
19 let l:in_docstring = 1
22 if match(l:line, '\v^ *.*("""|'''''')') >= 0
23 let l:in_docstring = 0
27 if !l:last_line_is_blank
29 \&& l:indent_size <= l:last_indent_size
30 \&& match(l:line, '\v^ *(return|if|for|while|break|continue)(\(| |$)') >= 0
31 call add(l:new_lines, '')
34 call add(l:new_lines, l:line)
35 let l:last_indent_size = l:indent_size
36 let l:last_line_is_blank = empty(split(l:line))
42 " This function breaks up long lines so that autopep8 or other tools can
43 " fix the badly-indented code which is produced as a result.
44 function! ale#fixers#generic_python#BreakUpLongLines(buffer, lines) abort
45 " Default to a maximum line length of 79
46 let l:max_line_length = 79
47 let l:conf = ale#path#FindNearestFile(a:buffer, 'setup.cfg')
49 " Read the maximum line length from setup.cfg
51 for l:match in ale#util#GetMatches(
53 \ '\v^ *max-line-length *\= *(\d+)',
55 let l:max_line_length = str2nr(l:match[1])
62 if len(l:line) > l:max_line_length && l:line !~# '# *noqa'
63 let l:line = substitute(l:line, '\v([(,])([^)])', '\1\n\2', 'g')
64 let l:line = substitute(l:line, '\v([^(])([)])', '\1,\n\2', 'g')
66 for l:split_line in split(l:line, "\n")
67 call add(l:new_list, l:split_line)
70 call add(l:new_list, l:line)