From 9005a62dc2080327a0f2164d765f837e90e963dc Mon Sep 17 00:00:00 2001 From: w0rp Date: Thu, 14 Nov 2019 14:50:16 +0000 Subject: [PATCH] Clean up the nimpretty code --- autoload/ale/fixers/nimpretty.vim | 10 ++-------- doc/ale-nim.txt | 20 +++++++++++++++++++ doc/ale-supported-languages-and-tools.txt | 1 + doc/ale.txt | 1 + supported-tools.md | 1 + .../test_nimpretty_fixer_callback.vader | 10 +++------- 6 files changed, 28 insertions(+), 15 deletions(-) diff --git a/autoload/ale/fixers/nimpretty.vim b/autoload/ale/fixers/nimpretty.vim index be6df470..fe2e7136 100644 --- a/autoload/ale/fixers/nimpretty.vim +++ b/autoload/ale/fixers/nimpretty.vim @@ -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 diff --git a/doc/ale-nim.txt b/doc/ale-nim.txt index ad7aa686..8985aeb8 100644 --- a/doc/ale-nim.txt +++ b/doc/ale-nim.txt @@ -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: diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index de1be1a2..29dabab7 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -284,6 +284,7 @@ Notes: * Nim * `nim check`!! * `nimlsp` + * `nimpretty` * nix * `nix-instantiate` * `nixpkgs-fmt` diff --git a/doc/ale.txt b/doc/ale.txt index 515c5f2c..593aae11 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -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| diff --git a/supported-tools.md b/supported-tools.md index 5a3376d4..0abc6b75 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -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) diff --git a/test/fixers/test_nimpretty_fixer_callback.vader b/test/fixers/test_nimpretty_fixer_callback.vader index b05139f0..a26f649a 100644 --- a/test/fixers/test_nimpretty_fixer_callback.vader +++ b/test/fixers/test_nimpretty_fixer_callback.vader @@ -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(''))