Merge branch 'master' of https://github.com/theanimal666/vim-autoformat into theanimal666-master

This commit is contained in:
Chiel ten Brinke 2017-04-12 15:49:55 +02:00
commit fc99fb38ab
2 changed files with 42 additions and 2 deletions

View File

@ -158,6 +158,12 @@ Here is a list of formatprograms that are supported by default, and thus will be
It can be installed by running `npm install -g standard` (`nodejs` is required). No more configuration needed. It can be installed by running `npm install -g standard` (`nodejs` is required). No more configuration needed.
More information about the style guide can be found here: http://standardjs.com/. More information about the style guide can be found here: http://standardjs.com/.
* `ESlint (local)` for __Javascript__. http://eslint.org/
It can be installed by running `npm install eslint`. The linter is then installed locally at ```node_modules/.bin/eslint```
When running formatter vim will walk up from the current file to search for such local installation and a
ESLint configuration file (either .eslintrc or eslintrc.json). When both are found eslint is executed with the --fix argument.
Currently only working on *nix like OS (Linux, MacOS etc.) requires OS to provide sh like shell syntax
* `xo` for __Javascript__. * `xo` for __Javascript__.
It can be installed by running `npm install -g xo` (`nodejs` is required). It can be installed by running `npm install -g xo` (`nodejs` is required).
Here is the link to the repository: https://github.com/sindresorhus/xo. Here is the link to the repository: https://github.com/sindresorhus/xo.
@ -213,7 +219,7 @@ Here is a list of formatprograms that are supported by default, and thus will be
It can be installed using [`cabal`](https://www.haskell.org/cabal/) build tool. Installation instructions are available at https://github.com/jaspervdj/stylish-haskell#installation It can be installed using [`cabal`](https://www.haskell.org/cabal/) build tool. Installation instructions are available at https://github.com/jaspervdj/stylish-haskell#installation
* `remark` for __Markdown__. * `remark` for __Markdown__.
A Javascript based markdown processor that can be installed with `npm install -g remark`. More info is available at https://github.com/wooorm/remark. A Javascript based markdown processor that can be installed with `npm install -g remark-cli`. More info is available at https://github.com/wooorm/remark.
* `fprettify` for modern __Fortran__. * `fprettify` for modern __Fortran__.
Download from [official repository](https://github.com/pseewald/fprettify). Install with `./setup.py install` or `./setup.py install --user`. Download from [official repository](https://github.com/pseewald/fprettify). Install with `./setup.py install` or `./setup.py install --user`.

View File

@ -160,8 +160,43 @@ if !exists('g:formatdef_xo_javascript')
let g:formatdef_xo_javascript = '"xo --fix --stdin"' let g:formatdef_xo_javascript = '"xo --fix --stdin"'
endif endif
" Setup ESLint local. Setup is done on formatter execution if ESLint and
" corresponding config is found they are used, otherwiese the formatter fails.
" No windows support at the moment.
if !exists('g:formatdef_eslint_local')
function! g:BuildESLintLocalCmd()
let l:path = fnamemodify(expand('%'), ':p')
let verbose = &verbose || g:autoformat_verbosemode == 1
if has('win32')
return "(>&2 echo 'ESLint Local not supported on win32')"
endif
" find formatter & config file
let l:prog = findfile('node_modules/.bin/eslint', l:path.";")
let l:cfg = findfile('.eslintrc.json', l:path.";")
if empty(l:cfg)
let l:cfg = findfile('.eslintrc', l:path.";")
endif
if (empty(l:cfg) || empty(l:prog))
if verbose
return "(>&2 echo 'No local ESLint program and/or config found')"
endif
return
endif
" This formatter uses a temporary file as ESLint has not option to print
" the formatted source to stdout without modifieing the file.
let l:eslint_js_tmp_file = fnameescape(tempname().".js")
let content = getline('1', '$')
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=$?
\ cat ".l:eslint_js_tmp_file."; rm -f ".l:eslint_js_tmp_file."; exit $exit_code"
endfunction
let g:formatdef_eslint_local = "g:BuildESLintLocalCmd()"
endif
if !exists('g:formatters_javascript') if !exists('g:formatters_javascript')
let g:formatters_javascript = [ let g:formatters_javascript = [
\ 'eslint_local',
\ 'jsbeautify_javascript', \ 'jsbeautify_javascript',
\ 'pyjsbeautify_javascript', \ 'pyjsbeautify_javascript',
\ 'jscs', \ 'jscs',
@ -170,7 +205,6 @@ if !exists('g:formatters_javascript')
\ ] \ ]
endif endif
" JSON " JSON
if !exists('g:formatdef_jsbeautify_json') if !exists('g:formatdef_jsbeautify_json')
if filereadable('.jsbeautifyrc') if filereadable('.jsbeautifyrc')