Move all functions for fixing things to autoload/ale/fixers, and only accept the lines of input where needed.

This commit is contained in:
w0rp
2017-06-07 14:02:29 +01:00
parent edddb1910b
commit 7517fd8226
15 changed files with 132 additions and 98 deletions
+1 -34
View File
@@ -1,5 +1,5 @@
" Author: w0rp <devw0rp@gmail.com>
" Description: eslint functions for handling and fixing errors.
" Description: Functions for working with eslint, for checking or fixing files.
call ale#Set('javascript_eslint_executable', 'eslint')
call ale#Set('javascript_eslint_use_global', 0)
@@ -11,36 +11,3 @@ function! ale#handlers#eslint#GetExecutable(buffer) abort
\ 'node_modules/.bin/eslint',
\])
endfunction
function! s:FindConfig(buffer) abort
for l:filename in [
\ '.eslintrc.js',
\ '.eslintrc.yaml',
\ '.eslintrc.yml',
\ '.eslintrc.json',
\ '.eslintrc',
\]
let l:config = ale#path#FindNearestFile(a:buffer, l:filename)
if !empty(l:config)
return l:config
endif
endfor
return ''
endfunction
function! ale#handlers#eslint#Fix(buffer, lines) abort
let l:config = s:FindConfig(a:buffer)
if empty(l:config)
return 0
endif
return {
\ 'command': ale#Escape(ale#handlers#eslint#GetExecutable(a:buffer))
\ . ' --config ' . ale#Escape(l:config)
\ . ' --fix %t',
\ 'read_temporary_file': 1,
\}
endfunction
-25
View File
@@ -1,25 +0,0 @@
" Author: tunnckoCore (Charlike Mike Reagent) <mameto2011@gmail.com>,
" w0rp <devw0rp@gmail.com>
" Description: Integration of Prettier with ALE.
call ale#Set('javascript_prettier_executable', 'prettier')
call ale#Set('javascript_prettier_use_global', 0)
function! ale#handlers#prettier#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'javascript_prettier', [
\ 'node_modules/prettier-cli/index.js',
\ 'node_modules/.bin/prettier',
\])
endfunction
function! ale#handlers#prettier#Fix(buffer, lines) abort
let l:options = ale#Var(a:buffer, 'javascript_prettier_options')
return {
\ 'command': ale#Escape(ale#handlers#prettier#GetExecutable(a:buffer))
\ . ' %t'
\ . ' ' . l:options
\ . ' --write',
\ 'read_temporary_file': 1,
\}
endfunction
-25
View File
@@ -1,25 +0,0 @@
" Author: tunnckoCore (Charlike Mike Reagent) <mameto2011@gmail.com>,
" w0rp <devw0rp@gmail.com>
" Description: Integration between Prettier and ESLint.
call ale#Set('javascript_prettier_eslint_executable', 'prettier-eslint')
call ale#Set('javascript_prettier_eslint_use_global', 0)
function! ale#handlers#prettier_eslint#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'javascript_prettier_eslint', [
\ 'node_modules/prettier-eslint-cli/index.js',
\ 'node_modules/.bin/prettier-eslint',
\])
endfunction
function! ale#handlers#prettier_eslint#Fix(buffer, lines) abort
let l:options = ale#Var(a:buffer, 'javascript_prettier_eslint_options')
return {
\ 'command': ale#Escape(ale#handlers#prettier_eslint#GetExecutable(a:buffer))
\ . ' %t'
\ . ' ' . l:options
\ . ' --write',
\ 'read_temporary_file': 1,
\}
endfunction
-48
View File
@@ -45,51 +45,3 @@ function! ale#handlers#python#HandlePEP8Format(buffer, lines) abort
return l:output
endfunction
" Add blank lines before control statements.
function! ale#handlers#python#AddLinesBeforeControlStatements(buffer, lines) abort
let l:new_lines = []
let l:last_indent_size = 0
for l:line in a:lines
let l:indent_size = len(matchstr(l:line, '^ *'))
if l:indent_size <= l:last_indent_size
\&& match(l:line, '\v^ *(return|if|for|while|break|continue)') >= 0
call add(l:new_lines, '')
endif
call add(l:new_lines, l:line)
let l:last_indent_size = l:indent_size
endfor
return l:new_lines
endfunction
function! ale#handlers#python#AutoPEP8(buffer, lines) abort
return {
\ 'command': 'autopep8 -'
\}
endfunction
function! ale#handlers#python#ISort(buffer, lines) abort
let l:config = ale#path#FindNearestFile(a:buffer, '.isort.cfg')
let l:config_options = !empty(l:config)
\ ? ' --settings-path ' . ale#Escape(l:config)
\ : ''
return {
\ 'command': 'isort' . l:config_options . ' -',
\}
endfunction
function! ale#handlers#python#YAPF(buffer, lines) abort
let l:config = ale#path#FindNearestFile(a:buffer, '.style.yapf')
let l:config_options = !empty(l:config)
\ ? ' --style ' . ale#Escape(l:config)
\ : ''
return {
\ 'command': 'yapf --no-local-style' . l:config_options,
\}
endfunction