mirror of
https://github.com/dense-analysis/ale
synced 2025-01-03 04:22:03 +00:00
Add shfmt fixer for sh files (#1083)
* Add shfmt fixer for sh files * Add tests for shfmt fixer
This commit is contained in:
parent
7086586b17
commit
716b22d524
@ -74,8 +74,8 @@ formatting.
|
|||||||
| Ansible | [ansible-lint](https://github.com/willthames/ansible-lint) |
|
| Ansible | [ansible-lint](https://github.com/willthames/ansible-lint) |
|
||||||
| AsciiDoc | [proselint](http://proselint.com/), [write-good](https://github.com/btford/write-good)|
|
| AsciiDoc | [proselint](http://proselint.com/), [write-good](https://github.com/btford/write-good)|
|
||||||
| Awk | [gawk](https://www.gnu.org/software/gawk/)|
|
| Awk | [gawk](https://www.gnu.org/software/gawk/)|
|
||||||
| Bash | shell [-n flag](https://www.gnu.org/software/bash/manual/bash.html#index-set), [shellcheck](https://www.shellcheck.net/) |
|
| Bash | shell [-n flag](https://www.gnu.org/software/bash/manual/bash.html#index-set), [shellcheck](https://www.shellcheck.net/), [shfmt](https://github.com/mvdan/sh) |
|
||||||
| Bourne Shell | shell [-n flag](http://linux.die.net/man/1/sh), [shellcheck](https://www.shellcheck.net/) |
|
| Bourne Shell | shell [-n flag](http://linux.die.net/man/1/sh), [shellcheck](https://www.shellcheck.net/), [shfmt](https://github.com/mvdan/sh) |
|
||||||
| C | [cppcheck](http://cppcheck.sourceforge.net), [cpplint](https://github.com/google/styleguide/tree/gh-pages/cpplint), [gcc](https://gcc.gnu.org/), [clang](http://clang.llvm.org/), [clangtidy](http://clang.llvm.org/extra/clang-tidy/) !!, [clang-format](https://clang.llvm.org/docs/ClangFormat.html)|
|
| C | [cppcheck](http://cppcheck.sourceforge.net), [cpplint](https://github.com/google/styleguide/tree/gh-pages/cpplint), [gcc](https://gcc.gnu.org/), [clang](http://clang.llvm.org/), [clangtidy](http://clang.llvm.org/extra/clang-tidy/) !!, [clang-format](https://clang.llvm.org/docs/ClangFormat.html)|
|
||||||
| C++ (filetype cpp) | [clang](http://clang.llvm.org/), [clangcheck](http://clang.llvm.org/docs/ClangCheck.html) !!, [clangtidy](http://clang.llvm.org/extra/clang-tidy/) !!, [cppcheck](http://cppcheck.sourceforge.net), [cpplint](https://github.com/google/styleguide/tree/gh-pages/cpplint) !!, [gcc](https://gcc.gnu.org/), [clang-format](https://clang.llvm.org/docs/ClangFormat.html)|
|
| C++ (filetype cpp) | [clang](http://clang.llvm.org/), [clangcheck](http://clang.llvm.org/docs/ClangCheck.html) !!, [clangtidy](http://clang.llvm.org/extra/clang-tidy/) !!, [cppcheck](http://cppcheck.sourceforge.net), [cpplint](https://github.com/google/styleguide/tree/gh-pages/cpplint) !!, [gcc](https://gcc.gnu.org/), [clang-format](https://clang.llvm.org/docs/ClangFormat.html)|
|
||||||
| CUDA | [nvcc](http://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html) |
|
| CUDA | [nvcc](http://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html) |
|
||||||
|
@ -132,6 +132,11 @@ let s:default_registry = {
|
|||||||
\ 'suggested_filetypes': ['reason'],
|
\ 'suggested_filetypes': ['reason'],
|
||||||
\ 'description': 'Fix ReasonML files with refmt.',
|
\ 'description': 'Fix ReasonML files with refmt.',
|
||||||
\ },
|
\ },
|
||||||
|
\ 'shfmt': {
|
||||||
|
\ 'function': 'ale#fixers#shfmt#Fix',
|
||||||
|
\ 'suggested_filetypes': ['sh'],
|
||||||
|
\ 'description': 'Fix sh files with shfmt.',
|
||||||
|
\ },
|
||||||
\}
|
\}
|
||||||
|
|
||||||
" Reset the function registry to the default entries.
|
" Reset the function registry to the default entries.
|
||||||
|
17
autoload/ale/fixers/shfmt.vim
Normal file
17
autoload/ale/fixers/shfmt.vim
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
scriptencoding utf-8
|
||||||
|
" Author: Simon Bugert <simon.bugert@gmail.com>
|
||||||
|
" Description: Fix sh files with shfmt.
|
||||||
|
|
||||||
|
call ale#Set('sh_shfmt_executable', 'shfmt')
|
||||||
|
call ale#Set('sh_shfmt_options', '')
|
||||||
|
|
||||||
|
function! ale#fixers#shfmt#Fix(buffer) abort
|
||||||
|
let l:executable = ale#Var(a:buffer, 'sh_shfmt_executable')
|
||||||
|
let l:options = ale#Var(a:buffer, 'sh_shfmt_options')
|
||||||
|
|
||||||
|
return {
|
||||||
|
\ 'command': ale#Escape(l:executable)
|
||||||
|
\ . (empty(l:options) ? '' : ' ' . l:options)
|
||||||
|
\}
|
||||||
|
|
||||||
|
endfunction
|
@ -57,5 +57,16 @@ g:ale_sh_shellcheck_exclusions *g:ale_sh_shellcheck_exclusions*
|
|||||||
\ let b:ale_sh_shellcheck_exclusions = 'SC2034,SC2154,SC2164'
|
\ let b:ale_sh_shellcheck_exclusions = 'SC2034,SC2154,SC2164'
|
||||||
<
|
<
|
||||||
|
|
||||||
|
===============================================================================
|
||||||
|
shfmt *ale-sh-shfmt*
|
||||||
|
|
||||||
|
g:ale_sh_shfmt_options *g:ale_sh_shfmt_options*
|
||||||
|
*b:ale_sh_shfmt_options*
|
||||||
|
Type: |String|
|
||||||
|
Default: `''`
|
||||||
|
|
||||||
|
This variable can be set to pass additional options to the shfmt fixer.
|
||||||
|
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
||||||
|
@ -173,6 +173,7 @@ CONTENTS *ale-contents*
|
|||||||
sh....................................|ale-sh-options|
|
sh....................................|ale-sh-options|
|
||||||
shell...............................|ale-sh-shell|
|
shell...............................|ale-sh-shell|
|
||||||
shellcheck..........................|ale-sh-shellcheck|
|
shellcheck..........................|ale-sh-shellcheck|
|
||||||
|
shfmt...............................|ale-sh-shfmt|
|
||||||
sml...................................|ale-sml-options|
|
sml...................................|ale-sml-options|
|
||||||
smlnj...............................|ale-sml-smlnj|
|
smlnj...............................|ale-sml-smlnj|
|
||||||
solidity..............................|ale-solidity-options|
|
solidity..............................|ale-solidity-options|
|
||||||
@ -256,8 +257,8 @@ Notes:
|
|||||||
* Ansible: `ansible-lint`
|
* Ansible: `ansible-lint`
|
||||||
* AsciiDoc: `proselint`, `write-good`
|
* AsciiDoc: `proselint`, `write-good`
|
||||||
* Awk: `gawk`
|
* Awk: `gawk`
|
||||||
* Bash: `shell` (-n flag), `shellcheck`
|
* Bash: `shell` (-n flag), `shellcheck`, `shfmt`
|
||||||
* Bourne Shell: `shell` (-n flag), `shellcheck`
|
* Bourne Shell: `shell` (-n flag), `shellcheck`, `shfmt`
|
||||||
* C: `cppcheck`, `cpplint`!!, `gcc`, `clang`, `clangtidy`!!, `clang-format`
|
* C: `cppcheck`, `cpplint`!!, `gcc`, `clang`, `clangtidy`!!, `clang-format`
|
||||||
* C++ (filetype cpp): `clang`, `clangcheck`!!, `clangtidy`!!, `cppcheck`, `cpplint`!!, `gcc`, `clang-format`
|
* C++ (filetype cpp): `clang`, `clangcheck`!!, `clangtidy`!!, `cppcheck`, `cpplint`!!, `gcc`, `clang-format`
|
||||||
* CUDA: `nvcc`!!
|
* CUDA: `nvcc`!!
|
||||||
|
24
test/fixers/test_shfmt_fixer_callback.vader
Normal file
24
test/fixers/test_shfmt_fixer_callback.vader
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
Before:
|
||||||
|
Save g:ale_sh_shfmt_executable
|
||||||
|
Save g:ale_sh_shfmt_options
|
||||||
|
|
||||||
|
" Use an invalid global executable, so we don't match it.
|
||||||
|
let g:ale_sh_shfmt_executable = 'xxxinvalid'
|
||||||
|
let g:ale_sh_shfmt_options = ''
|
||||||
|
|
||||||
|
Execute(The shfmt callback should return the correct default values):
|
||||||
|
AssertEqual
|
||||||
|
\ {
|
||||||
|
\ 'command': ale#Escape('xxxinvalid'),
|
||||||
|
\ },
|
||||||
|
\ ale#fixers#shfmt#Fix(bufnr(''))
|
||||||
|
|
||||||
|
Execute(The shfmt callback should include custom shfmt options):
|
||||||
|
let g:ale_sh_shfmt_options = '--some-option'
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ {
|
||||||
|
\ 'command': ale#Escape(g:ale_sh_shfmt_executable)
|
||||||
|
\ . ' --some-option',
|
||||||
|
\ },
|
||||||
|
\ ale#fixers#shfmt#Fix(bufnr(''))
|
Loading…
Reference in New Issue
Block a user