Merge py cli and js cli js-beautify definitions.
This commit is contained in:
parent
31c2de2398
commit
889665717c
@ -140,14 +140,10 @@ if !exists('g:formatdef_jsbeautify_javascript')
|
|||||||
elseif filereadable(expand('~/.jsbeautifyrc'))
|
elseif filereadable(expand('~/.jsbeautifyrc'))
|
||||||
let g:formatdef_jsbeautify_javascript = '"js-beautify"'
|
let g:formatdef_jsbeautify_javascript = '"js-beautify"'
|
||||||
else
|
else
|
||||||
let g:formatdef_jsbeautify_javascript = '"js-beautify -X -f - -".(&expandtab ? "s ".shiftwidth() : "t").(&textwidth ? " -w ".&textwidth : "")'
|
let g:formatdef_jsbeautify_javascript = '"js-beautify -X -".(&expandtab ? "s ".shiftwidth() : "t").(&textwidth ? " -w ".&textwidth : "")'
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !exists('g:formatdef_pyjsbeautify_javascript')
|
|
||||||
let g:formatdef_pyjsbeautify_javascript = '"js-beautify -X -".(&expandtab ? "s ".shiftwidth() : "t").(&textwidth ? " -w ".&textwidth : "")." -"'
|
|
||||||
endif
|
|
||||||
|
|
||||||
if !exists('g:formatdef_jscs')
|
if !exists('g:formatdef_jscs')
|
||||||
let g:formatdef_jscs = '"jscs -x"'
|
let g:formatdef_jscs = '"jscs -x"'
|
||||||
endif
|
endif
|
||||||
@ -164,50 +160,49 @@ endif
|
|||||||
" corresponding config is found they are used, otherwiese the formatter fails.
|
" corresponding config is found they are used, otherwiese the formatter fails.
|
||||||
" No windows support at the moment.
|
" No windows support at the moment.
|
||||||
if !exists('g:formatdef_eslint_local')
|
if !exists('g:formatdef_eslint_local')
|
||||||
function! g:BuildESLintLocalCmd()
|
function! g:BuildESLintLocalCmd()
|
||||||
let l:path = fnamemodify(expand('%'), ':p')
|
let l:path = fnamemodify(expand('%'), ':p')
|
||||||
let verbose = &verbose || g:autoformat_verbosemode == 1
|
let verbose = &verbose || g:autoformat_verbosemode == 1
|
||||||
if has('win32')
|
if has('win32')
|
||||||
return "(>&2 echo 'ESLint Local not supported on win32')"
|
return "(>&2 echo 'ESLint Local not supported on win32')"
|
||||||
endif
|
endif
|
||||||
" find formatter & config file
|
" find formatter & config file
|
||||||
let l:prog = findfile('node_modules/.bin/eslint', l:path.";")
|
let l:prog = findfile('node_modules/.bin/eslint', l:path.";")
|
||||||
let l:cfg = findfile('.eslintrc.js', l:path.";")
|
let l:cfg = findfile('.eslintrc.js', l:path.";")
|
||||||
if empty(l:cfg)
|
if empty(l:cfg)
|
||||||
let l:cfg = findfile('.eslintrc.yaml', l:path.";")
|
let l:cfg = findfile('.eslintrc.yaml', l:path.";")
|
||||||
endif
|
endif
|
||||||
if empty(l:cfg)
|
if empty(l:cfg)
|
||||||
let l:cfg = findfile('.eslintrc.yml', l:path.";")
|
let l:cfg = findfile('.eslintrc.yml', l:path.";")
|
||||||
endif
|
endif
|
||||||
if empty(l:cfg)
|
if empty(l:cfg)
|
||||||
let l:cfg = findfile('.eslintrc.json', l:path.";")
|
let l:cfg = findfile('.eslintrc.json', l:path.";")
|
||||||
endif
|
endif
|
||||||
if empty(l:cfg)
|
if empty(l:cfg)
|
||||||
let l:cfg = findfile('.eslintrc', l:path.";")
|
let l:cfg = findfile('.eslintrc', l:path.";")
|
||||||
endif
|
endif
|
||||||
if (empty(l:cfg) || empty(l:prog))
|
if (empty(l:cfg) || empty(l:prog))
|
||||||
if verbose
|
if verbose
|
||||||
return "(>&2 echo 'No local ESLint program and/or config found')"
|
return "(>&2 echo 'No local ESLint program and/or config found')"
|
||||||
endif
|
endif
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" This formatter uses a temporary file as ESLint has not option to print
|
" This formatter uses a temporary file as ESLint has not option to print
|
||||||
" the formatted source to stdout without modifieing the file.
|
" the formatted source to stdout without modifieing the file.
|
||||||
let l:eslint_js_tmp_file = fnameescape(tempname().".js")
|
let l:eslint_js_tmp_file = fnameescape(tempname().".js")
|
||||||
let content = getline('1', '$')
|
let content = getline('1', '$')
|
||||||
call writefile(content, l:eslint_js_tmp_file)
|
call writefile(content, l:eslint_js_tmp_file)
|
||||||
return l:prog." -c ".l:cfg." --fix ".l:eslint_js_tmp_file." 1> /dev/null; exit_code=$?
|
return l:prog." -c ".l:cfg." --fix ".l:eslint_js_tmp_file." 1> /dev/null; exit_code=$?
|
||||||
\ cat ".l:eslint_js_tmp_file."; rm -f ".l:eslint_js_tmp_file."; exit $exit_code"
|
\ cat ".l:eslint_js_tmp_file."; rm -f ".l:eslint_js_tmp_file."; exit $exit_code"
|
||||||
endfunction
|
endfunction
|
||||||
let g:formatdef_eslint_local = "g:BuildESLintLocalCmd()"
|
let g:formatdef_eslint_local = "g:BuildESLintLocalCmd()"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !exists('g:formatters_javascript')
|
if !exists('g:formatters_javascript')
|
||||||
let g:formatters_javascript = [
|
let g:formatters_javascript = [
|
||||||
\ 'eslint_local',
|
\ 'eslint_local',
|
||||||
\ 'jsbeautify_javascript',
|
\ 'jsbeautify_javascript',
|
||||||
\ 'pyjsbeautify_javascript',
|
|
||||||
\ 'jscs',
|
\ 'jscs',
|
||||||
\ 'standard_javascript',
|
\ 'standard_javascript',
|
||||||
\ 'xo_javascript'
|
\ 'xo_javascript'
|
||||||
@ -221,18 +216,14 @@ if !exists('g:formatdef_jsbeautify_json')
|
|||||||
elseif filereadable(expand('~/.jsbeautifyrc'))
|
elseif filereadable(expand('~/.jsbeautifyrc'))
|
||||||
let g:formatdef_jsbeautify_json = '"js-beautify"'
|
let g:formatdef_jsbeautify_json = '"js-beautify"'
|
||||||
else
|
else
|
||||||
let g:formatdef_jsbeautify_json = '"js-beautify -f - -".(&expandtab ? "s ".shiftwidth() : "t")'
|
let g:formatdef_jsbeautify_json = '"js-beautify -".(&expandtab ? "s ".shiftwidth() : "t")'
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !exists('g:formatdef_pyjsbeautify_json')
|
|
||||||
let g:formatdef_pyjsbeautify_json = '"js-beautify -".(&expandtab ? "s ".shiftwidth() : "t")." -"'
|
|
||||||
endif
|
|
||||||
|
|
||||||
if !exists('g:formatters_json')
|
if !exists('g:formatters_json')
|
||||||
let g:formatters_json = [
|
let g:formatters_json = [
|
||||||
\ 'jsbeautify_json',
|
\ 'jsbeautify_json',
|
||||||
\ 'pyjsbeautify_json',
|
|
||||||
\ ]
|
\ ]
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
4
samples/test.json
Normal file
4
samples/test.json
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"test": "test",
|
||||||
|
"test": [1, 2, 3]
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user