Open Konstantin-Glukhov opened 2 years ago
Implement something similar to the following code:
ftplugin/json.vim:
let b:ale_fixers = ['json_python_fixer] let b:ale_json_python_fixer_options = '--indent 2'
autoload/ale/fixers/json_python_fixer.vim:
" Description: Fix JSON files with "python -m json.tool" call ale#Set('json_python_fixer_options', '') function! ale#fixers#json_python_fixer#Fix(buffer) abort let l:command = 'python' if !executable(l:command) echo 'ALEFix: ' . l:command . ' executable not found' return {'command': 'REM'} endif let l:command .= ' -m json.tool' let l:options = ale#Var(a:buffer, 'json_python_fixer_options') if len(l:options) let l:command .= ' ' . l:options endif return { 'command': l:command . ' -'} endfunction
A big advantage of json.tool over alternatives like jsbeautify is that you can sort the keys:
let g:ale_json_python_fixer_options = '--sort-keys'
Implement something similar to the following code:
ftplugin/json.vim:
let b:ale_fixers = ['json_python_fixer] let b:ale_json_python_fixer_options = '--indent 2'
autoload/ale/fixers/json_python_fixer.vim: