summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <w0rp@users.noreply.github.com>2019-11-14 14:35:31 +0000
committerGitHub <noreply@github.com>2019-11-14 14:35:31 +0000
commit66a8df081e57b18ab79b71c77d628c56aa4d8344 (patch)
treeb29e1b814fd17cd2f9085436ec8c4ed1f44c46b2
parentb76165abf634d365382ba213d8f754e8ca52a0e6 (diff)
parentabad8e474bf3f096dc96eb4020ab52d35908725d (diff)
downloadale-66a8df081e57b18ab79b71c77d628c56aa4d8344.zip
Merge pull request #2890 from nhanb/master
Add nimpretty fixer for nim-lang
-rw-r--r--autoload/ale/fix/registry.vim5
-rw-r--r--autoload/ale/fixers/nimpretty.vim21
-rw-r--r--test/fixers/test_nimpretty_fixer_callback.vader27
3 files changed, 53 insertions, 0 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index 5ec27a10..1b3ca1a8 100644
--- a/autoload/ale/fix/registry.vim
+++ b/autoload/ale/fix/registry.vim
@@ -54,6 +54,11 @@ let s:default_registry = {
\ 'description': 'Apply elm-format to a file.',
\ 'aliases': ['format'],
\ },
+\ 'nimpretty': {
+\ 'function': 'ale#fixers#nimpretty#Fix',
+\ 'suggested_filetypes': ['nim'],
+\ 'description': 'Apply nimpretty to a file.',
+\ },
\ 'eslint': {
\ 'function': 'ale#fixers#eslint#Fix',
\ 'suggested_filetypes': ['javascript', 'typescript'],
diff --git a/autoload/ale/fixers/nimpretty.vim b/autoload/ale/fixers/nimpretty.vim
new file mode 100644
index 00000000..be6df470
--- /dev/null
+++ b/autoload/ale/fixers/nimpretty.vim
@@ -0,0 +1,21 @@
+" Author: Nhan <hi@imnhan.com>
+" Description: Integration of nimpretty with ALE.
+
+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:options = ale#Var(a:buffer, 'nim_nimpretty_options')
+
+ return {
+ \ 'command': ale#Escape(ale#fixers#nimpretty#GetExecutable(a:buffer))
+ \ . ' %t'
+ \ . (empty(l:options) ? '' : ' ' . l:options),
+ \ 'read_temporary_file': 1,
+ \}
+endfunction
diff --git a/test/fixers/test_nimpretty_fixer_callback.vader b/test/fixers/test_nimpretty_fixer_callback.vader
new file mode 100644
index 00000000..b05139f0
--- /dev/null
+++ b/test/fixers/test_nimpretty_fixer_callback.vader
@@ -0,0 +1,27 @@
+Before:
+ call ale#assert#SetUpFixerTest('nim', 'nimpretty')
+
+After:
+ call ale#test#RestoreDirectory()
+
+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'
+ \ },
+ \ ale#fixers#nimpretty#Fix(bufnr(''))
+
+Execute(The nimpretty callback should include any additional options):
+ let g:ale_nim_nimpretty_options = '--some-option'
+
+ AssertEqual
+ \ {
+ \ 'read_temporary_file': 1,
+ \ 'command': ale#Escape(g:ale_nim_nimpretty_executable)
+ \ . ' %t'
+ \ . ' --some-option',
+ \ },
+ \ ale#fixers#nimpretty#Fix(bufnr(''))