Clean up the nimpretty code

This commit is contained in:
w0rp 2019-11-14 14:50:16 +00:00
parent 7665559d0e
commit 9005a62dc2
No known key found for this signature in database
GPG key ID: 0FC1ECAA8C81CD83
6 changed files with 28 additions and 15 deletions

View file

@ -3,19 +3,13 @@
call ale#Set('nim_nimpretty_executable', 'nimpretty')
call ale#Set('nim_nimpretty_options', '--maxLineLen:80')
call ale#Set('nim_nimpretty_use_global', get(g:, 'ale_use_global_executables', 0))
function! ale#fixers#nimpretty#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'nim_nimpretty', ['nimpretty'])
endfunction
function! ale#fixers#nimpretty#Fix(buffer) abort
let l:executable = ale#Var(a:buffer, 'nim_nimpretty_executable')
let l:options = ale#Var(a:buffer, 'nim_nimpretty_options')
return {
\ 'command': ale#Escape(ale#fixers#nimpretty#GetExecutable(a:buffer))
\ . ' %t'
\ . (empty(l:options) ? '' : ' ' . l:options),
\ 'command': ale#Escape(l:executable) . ' %t' . ale#Pad(l:options),
\ 'read_temporary_file': 1,
\}
endfunction

View file

@ -21,5 +21,25 @@ g:nim_nimlsp_nim_sources *g:nim_nimlsp_nim_sources*
command.
===============================================================================
nimpretty *ale-nim-nimpretty*
g:ale_nim_nimpretty_executable *g:ale_nim_nimpretty_executable*
*b:ale_nim_nimpretty_executable*
Type: |String|
Default: `'nimpretty'`
This variable can be changed to use a different executable for nimpretty.
g:ale_nim_nimpretty_options *g:ale_nim_nimpretty_options*
*b:ale_nim_nimpretty_options*
Type: |String|
Default: `'--maxLineLen:80'`
This variable can be changed to modify flags given to nimpretty.
===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View file

@ -284,6 +284,7 @@ Notes:
* Nim
* `nim check`!!
* `nimlsp`
* `nimpretty`
* nix
* `nix-instantiate`
* `nixpkgs-fmt`

View file

@ -2361,6 +2361,7 @@ documented in additional help files.
nim.....................................|ale-nim-options|
nimcheck..............................|ale-nim-nimcheck|
nimlsp................................|ale-nim-nimlsp|
nimpretty.............................|ale-nim-nimpretty|
nix.....................................|ale-nix-options|
nixpkgs-fmt...........................|ale-nix-nixpkgs-fmt|
nroff...................................|ale-nroff-options|

View file

@ -293,6 +293,7 @@ formatting.
* Nim
* [nim check](https://nim-lang.org/docs/nimc.html) :floppy_disk:
* [nimlsp](https://github.com/PMunch/nimlsp)
* nimpretty
* nix
* [nix-instantiate](http://nixos.org/nix/manual/#sec-nix-instantiate)
* [nixpkgs-fmt](https://github.com/nix-community/nixpkgs-fmt)

View file

@ -2,15 +2,13 @@ Before:
call ale#assert#SetUpFixerTest('nim', 'nimpretty')
After:
call ale#test#RestoreDirectory()
call ale#assert#TearDownFixerTest()
Execute(The nimpretty callback should return the correct default values):
AssertEqual
\ {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape(g:ale_nim_nimpretty_executable)
\ . ' %t --maxLineLen:80'
\ 'command': ale#Escape('nimpretty') . ' %t --maxLineLen:80'
\ },
\ ale#fixers#nimpretty#Fix(bufnr(''))
@ -20,8 +18,6 @@ Execute(The nimpretty callback should include any additional options):
AssertEqual
\ {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape(g:ale_nim_nimpretty_executable)
\ . ' %t'
\ . ' --some-option',
\ 'command': ale#Escape('nimpretty') . ' %t --some-option'
\ },
\ ale#fixers#nimpretty#Fix(bufnr(''))