mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-07 05:04:28 +08:00
Merge pull request #3261 from toastal/dhall
Enhanced Dhall fixer support
This commit is contained in:
24
autoload/ale/dhall.vim
Normal file
24
autoload/ale/dhall.vim
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
" Author: Pat Brisbin <pbrisbin@gmail.com>, toastal <toastal@protonmail.com>
|
||||||
|
" Description: Functions for working with Dhall’s executable
|
||||||
|
|
||||||
|
call ale#Set('dhall_executable', 'dhall')
|
||||||
|
call ale#Set('dhall_use_global', get(g:, 'ale_use_global_executables', 0))
|
||||||
|
call ale#Set('dhall_options', '')
|
||||||
|
|
||||||
|
function! ale#dhall#GetExecutable(buffer) abort
|
||||||
|
let l:executable = ale#Var(a:buffer, 'dhall_executable')
|
||||||
|
|
||||||
|
" Dhall is written in Haskell and commonly installed with Stack
|
||||||
|
return ale#handlers#haskell_stack#EscapeExecutable(l:executable, 'dhall')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! ale#dhall#GetExecutableWithOptions(buffer) abort
|
||||||
|
let l:executable = ale#dhall#GetExecutable(a:buffer)
|
||||||
|
|
||||||
|
return l:executable
|
||||||
|
\ . ale#Pad(ale#Var(a:buffer, 'dhall_options'))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! ale#dhall#GetCommand(buffer) abort
|
||||||
|
return '%e ' . ale#Pad(ale#Var(a:buffer, 'dhall_options'))
|
||||||
|
endfunction
|
||||||
@@ -37,6 +37,27 @@ let s:default_registry = {
|
|||||||
\ 'suggested_filetypes': ['d'],
|
\ 'suggested_filetypes': ['d'],
|
||||||
\ 'description': 'Fix D files with dfmt.',
|
\ 'description': 'Fix D files with dfmt.',
|
||||||
\ },
|
\ },
|
||||||
|
\ 'dhall': {
|
||||||
|
\ 'function': 'ale#fixers#dhall#Fix',
|
||||||
|
\ 'suggested_filetypes': ['dhall'],
|
||||||
|
\ 'description': 'Fix Dhall files with dhall-format.',
|
||||||
|
\ },
|
||||||
|
\ 'dhall-format': {
|
||||||
|
\ 'function': 'ale#fixers#dhall_format#Fix',
|
||||||
|
\ 'suggested_filetypes': ['dhall'],
|
||||||
|
\ 'description': 'Standard code formatter for the Dhall language',
|
||||||
|
\ 'aliases': ['dhall'],
|
||||||
|
\ },
|
||||||
|
\ 'dhall-freeze': {
|
||||||
|
\ 'function': 'ale#fixers#dhall_freeze#Freeze',
|
||||||
|
\ 'suggested_filetypes': ['dhall'],
|
||||||
|
\ 'description': 'Add integrity checks to remote import statements of an expression for the Dhall language',
|
||||||
|
\ },
|
||||||
|
\ 'dhall-lint': {
|
||||||
|
\ 'function': 'ale#fixers#dhall_lint#Fix',
|
||||||
|
\ 'suggested_filetypes': ['dhall'],
|
||||||
|
\ 'description': 'Standard code formatter for the Dhall language and removing dead code',
|
||||||
|
\ },
|
||||||
\ 'fecs': {
|
\ 'fecs': {
|
||||||
\ 'function': 'ale#fixers#fecs#Fix',
|
\ 'function': 'ale#fixers#fecs#Fix',
|
||||||
\ 'suggested_filetypes': ['javascript', 'css', 'html'],
|
\ 'suggested_filetypes': ['javascript', 'css', 'html'],
|
||||||
@@ -390,16 +411,11 @@ let s:default_registry = {
|
|||||||
\ 'suggested_filetypes': ['lua'],
|
\ 'suggested_filetypes': ['lua'],
|
||||||
\ 'description': 'Fix Lua files with luafmt.',
|
\ 'description': 'Fix Lua files with luafmt.',
|
||||||
\ },
|
\ },
|
||||||
\ 'dhall': {
|
|
||||||
\ 'function': 'ale#fixers#dhall#Fix',
|
|
||||||
\ 'suggested_filetypes': ['dhall'],
|
|
||||||
\ 'description': 'Fix Dhall files with dhall-format.',
|
|
||||||
\ },
|
|
||||||
\ 'ormolu': {
|
\ 'ormolu': {
|
||||||
\ 'function': 'ale#fixers#ormolu#Fix',
|
\ 'function': 'ale#fixers#ormolu#Fix',
|
||||||
\ 'suggested_filetypes': ['haskell'],
|
\ 'suggested_filetypes': ['haskell'],
|
||||||
\ 'description': 'A formatter for Haskell source code.',
|
\ 'description': 'A formatter for Haskell source code.',
|
||||||
\ },
|
\ }
|
||||||
\}
|
\}
|
||||||
|
|
||||||
" Reset the function registry to the default entries.
|
" Reset the function registry to the default entries.
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
" Author: Pat Brisbin <pbrisbin@gmail.com>
|
|
||||||
" Description: Integration of dhall-format with ALE.
|
|
||||||
|
|
||||||
call ale#Set('dhall_format_executable', 'dhall')
|
|
||||||
|
|
||||||
function! ale#fixers#dhall#GetExecutable(buffer) abort
|
|
||||||
let l:executable = ale#Var(a:buffer, 'dhall_format_executable')
|
|
||||||
|
|
||||||
" Dhall is written in Haskell and commonly installed with Stack
|
|
||||||
return ale#handlers#haskell_stack#EscapeExecutable(l:executable, 'dhall')
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! ale#fixers#dhall#Fix(buffer) abort
|
|
||||||
let l:executable = ale#fixers#dhall#GetExecutable(a:buffer)
|
|
||||||
|
|
||||||
return {
|
|
||||||
\ 'command': l:executable
|
|
||||||
\ . ' format'
|
|
||||||
\ . ' --inplace'
|
|
||||||
\ . ' %t',
|
|
||||||
\ 'read_temporary_file': 1,
|
|
||||||
\}
|
|
||||||
endfunction
|
|
||||||
14
autoload/ale/fixers/dhall_format.vim
Normal file
14
autoload/ale/fixers/dhall_format.vim
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
" Author: toastal <toastal@protonmail.com>
|
||||||
|
" Description: Dhall’s built-in formatter
|
||||||
|
"
|
||||||
|
function! ale#fixers#dhall_format#Fix(buffer) abort
|
||||||
|
let l:executable = ale#dhall#GetExecutableWithOptions(a:buffer)
|
||||||
|
let l:command = l:executable
|
||||||
|
\ . ' format'
|
||||||
|
\ . ' --inplace %t'
|
||||||
|
|
||||||
|
return {
|
||||||
|
\ 'command': l:command,
|
||||||
|
\ 'read_temporary_file': 1,
|
||||||
|
\}
|
||||||
|
endfunction
|
||||||
18
autoload/ale/fixers/dhall_freeze.vim
Normal file
18
autoload/ale/fixers/dhall_freeze.vim
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
" Author: toastal <toastal@protonmail.com>
|
||||||
|
" Description: Dhall’s package freezing
|
||||||
|
|
||||||
|
call ale#Set('dhall_freeze_options', '')
|
||||||
|
|
||||||
|
function! ale#fixers#dhall_freeze#Freeze(buffer) abort
|
||||||
|
let l:executable = ale#dhall#GetExecutableWithOptions(a:buffer)
|
||||||
|
let l:command = l:executable
|
||||||
|
\ . ' freeze'
|
||||||
|
\ . ale#Pad(ale#Var(a:buffer, 'dhall_freeze_options'))
|
||||||
|
\ . ' --inplace %t'
|
||||||
|
|
||||||
|
|
||||||
|
return {
|
||||||
|
\ 'command': l:command,
|
||||||
|
\ 'read_temporary_file': 1,
|
||||||
|
\}
|
||||||
|
endfunction
|
||||||
14
autoload/ale/fixers/dhall_lint.vim
Normal file
14
autoload/ale/fixers/dhall_lint.vim
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
" Author: toastal <toastal@protonmail.com>
|
||||||
|
" Description: Dhall’s built-in linter/formatter
|
||||||
|
|
||||||
|
function! ale#fixers#dhall_lint#Fix(buffer) abort
|
||||||
|
let l:executable = ale#dhall#GetExecutableWithOptions(a:buffer)
|
||||||
|
let l:command = l:executable
|
||||||
|
\ . ' lint'
|
||||||
|
\ . ' --inplace %t'
|
||||||
|
|
||||||
|
return {
|
||||||
|
\ 'command': l:command,
|
||||||
|
\ 'read_temporary_file': 1,
|
||||||
|
\}
|
||||||
|
endfunction
|
||||||
52
doc/ale-dhall.txt
Normal file
52
doc/ale-dhall.txt
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
===============================================================================
|
||||||
|
ALE Dhall Integration *ale-dhall-options*
|
||||||
|
|
||||||
|
g:ale_dhall_executable *g:ale_dhall_executable*
|
||||||
|
*b:ale_dhall_executable*
|
||||||
|
Type: |String|
|
||||||
|
Default: `'dhall'`
|
||||||
|
|
||||||
|
g:ale_dhall_options g:ale_dhall_options
|
||||||
|
b:ale_dhall_options
|
||||||
|
Type: |String|
|
||||||
|
Default: `''`
|
||||||
|
|
||||||
|
This variable can be set to pass additional options to the 'dhall` executable.
|
||||||
|
This is shared with `dhall-freeze` and `dhall-lint`.
|
||||||
|
>
|
||||||
|
let g:dhall_options = '--ascii'
|
||||||
|
<
|
||||||
|
|
||||||
|
===============================================================================
|
||||||
|
dhall-format *ale-dhall-format*
|
||||||
|
|
||||||
|
Dhall
|
||||||
|
(https://dhall-lang.org/)
|
||||||
|
|
||||||
|
|
||||||
|
===============================================================================
|
||||||
|
dhall-freeze *ale-dhall-freeze*
|
||||||
|
|
||||||
|
Dhall
|
||||||
|
(https://dhall-lang.org/)
|
||||||
|
|
||||||
|
g:ale_dhall_freeze_options g:ale_dhall_freeze_options
|
||||||
|
b:ale_dhall_freeze_options
|
||||||
|
Type: |String|
|
||||||
|
Default: `''`
|
||||||
|
|
||||||
|
This variable can be set to pass additional options to the 'dhall freeze`
|
||||||
|
executable.
|
||||||
|
>
|
||||||
|
let g:dhall_freeze_options = '--all'
|
||||||
|
<
|
||||||
|
|
||||||
|
===============================================================================
|
||||||
|
dhall-lint *ale-dhall-lint*
|
||||||
|
|
||||||
|
Dhall
|
||||||
|
(https://dhall-lang.org/)
|
||||||
|
|
||||||
|
|
||||||
|
===============================================================================
|
||||||
|
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
||||||
@@ -121,6 +121,8 @@ Notes:
|
|||||||
* `language_server`
|
* `language_server`
|
||||||
* Dhall
|
* Dhall
|
||||||
* `dhall-format`
|
* `dhall-format`
|
||||||
|
* `dhall-freeze`
|
||||||
|
* `dhall-lint`
|
||||||
* Dockerfile
|
* Dockerfile
|
||||||
* `dockerfile_lint`
|
* `dockerfile_lint`
|
||||||
* `hadolint`
|
* `hadolint`
|
||||||
|
|||||||
@@ -2666,6 +2666,10 @@ documented in additional help files.
|
|||||||
dart....................................|ale-dart-options|
|
dart....................................|ale-dart-options|
|
||||||
dartanalyzer..........................|ale-dart-dartanalyzer|
|
dartanalyzer..........................|ale-dart-dartanalyzer|
|
||||||
dartfmt...............................|ale-dart-dartfmt|
|
dartfmt...............................|ale-dart-dartfmt|
|
||||||
|
dhall...................................|ale-dhall-options|
|
||||||
|
dhall-format..........................|ale-dhall-format|
|
||||||
|
dhall-freeze..........................|ale-dhall-freeze|
|
||||||
|
dhall-lint............................|ale-dhall-lint|
|
||||||
dockerfile..............................|ale-dockerfile-options|
|
dockerfile..............................|ale-dockerfile-options|
|
||||||
dockerfile_lint.......................|ale-dockerfile-dockerfile_lint|
|
dockerfile_lint.......................|ale-dockerfile-dockerfile_lint|
|
||||||
hadolint..............................|ale-dockerfile-hadolint|
|
hadolint..............................|ale-dockerfile-hadolint|
|
||||||
|
|||||||
@@ -130,6 +130,8 @@ formatting.
|
|||||||
* [language_server](https://github.com/natebosch/dart_language_server)
|
* [language_server](https://github.com/natebosch/dart_language_server)
|
||||||
* Dhall
|
* Dhall
|
||||||
* [dhall-format](https://github.com/dhall-lang/dhall-lang)
|
* [dhall-format](https://github.com/dhall-lang/dhall-lang)
|
||||||
|
* [dhall-freeze](https://github.com/dhall-lang/dhall-lang)
|
||||||
|
* [dhall-lint](https://github.com/dhall-lang/dhall-lang)
|
||||||
* Dockerfile
|
* Dockerfile
|
||||||
* [dockerfile_lint](https://github.com/projectatomic/dockerfile_lint)
|
* [dockerfile_lint](https://github.com/projectatomic/dockerfile_lint)
|
||||||
* [hadolint](https://github.com/hadolint/hadolint)
|
* [hadolint](https://github.com/hadolint/hadolint)
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
Before:
|
|
||||||
call ale#assert#SetUpFixerTest('dhall', 'dhall')
|
|
||||||
|
|
||||||
After:
|
|
||||||
call ale#assert#TearDownFixerTest()
|
|
||||||
|
|
||||||
Execute(The default command should be correct):
|
|
||||||
AssertFixer
|
|
||||||
\ { 'read_temporary_file': 1,
|
|
||||||
\ 'command': ale#Escape('dhall') . ' format --inplace %t'
|
|
||||||
\ }
|
|
||||||
24
test/fixers/test_dhall_format_fixer_callback.vader
Normal file
24
test/fixers/test_dhall_format_fixer_callback.vader
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
Before:
|
||||||
|
Save g:ale_dhall_executable
|
||||||
|
Save g:ale_dhall_options
|
||||||
|
|
||||||
|
" Use an invalid global executable, so we don’t match it.
|
||||||
|
let g:ale_dhall_executable = 'odd-dhall'
|
||||||
|
let g:ale_dhall_options = '--ascii'
|
||||||
|
|
||||||
|
call ale#assert#SetUpFixerTest('dhall-format', 'dhall-format')
|
||||||
|
|
||||||
|
After:
|
||||||
|
call ale#assert#TearDownFixerTest()
|
||||||
|
|
||||||
|
Execute(The dhall-format callback should return the correct options):
|
||||||
|
call ale#test#SetFilename('../dhall_files/testfile.dhall')
|
||||||
|
|
||||||
|
AssertFixer
|
||||||
|
\ {
|
||||||
|
\ 'command': ale#Escape('odd-dhall')
|
||||||
|
\ . ' --ascii'
|
||||||
|
\ . ' format'
|
||||||
|
\ . ' --inplace %t',
|
||||||
|
\ 'read_temporary_file': 1,
|
||||||
|
\ }
|
||||||
24
test/fixers/test_dhall_freeze_fixer_callback.vader
Normal file
24
test/fixers/test_dhall_freeze_fixer_callback.vader
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
Before:
|
||||||
|
Save g:ale_dhall_executable
|
||||||
|
Save g:ale_dhall_options
|
||||||
|
|
||||||
|
" Use an invalid global executable, so we don’t match it.
|
||||||
|
let g:ale_dhall_executable = 'odd-dhall'
|
||||||
|
let g:ale_dhall_options = '--ascii'
|
||||||
|
let g:ale_dhall_freeze_options = '--all'
|
||||||
|
|
||||||
|
call ale#assert#SetUpFixerTest('dhall-freeze', 'dhall-freeze')
|
||||||
|
|
||||||
|
After:
|
||||||
|
call ale#assert#TearDownFixerTest()
|
||||||
|
|
||||||
|
Execute(The dhall-freeze callback should return the correct options):
|
||||||
|
AssertFixer
|
||||||
|
\ {
|
||||||
|
\ 'command': ale#Escape('odd-dhall')
|
||||||
|
\ . ' --ascii'
|
||||||
|
\ . ' freeze'
|
||||||
|
\ . ' --all'
|
||||||
|
\ . ' --inplace %t',
|
||||||
|
\ 'read_temporary_file': 1,
|
||||||
|
\ }
|
||||||
22
test/fixers/test_dhall_lint_fixer_callback.vader
Normal file
22
test/fixers/test_dhall_lint_fixer_callback.vader
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
Before:
|
||||||
|
Save g:ale_dhall_executable
|
||||||
|
Save g:ale_dhall_options
|
||||||
|
|
||||||
|
" Use an invalid global executable, so we don’t match it.
|
||||||
|
let g:ale_dhall_executable = 'odd-dhall'
|
||||||
|
let g:ale_dhall_options = '--ascii'
|
||||||
|
|
||||||
|
call ale#assert#SetUpFixerTest('dhall-lint', 'dhall-lint')
|
||||||
|
|
||||||
|
After:
|
||||||
|
call ale#assert#TearDownFixerTest()
|
||||||
|
|
||||||
|
Execute(The dhall-lint callback should return the correct options):
|
||||||
|
AssertFixer
|
||||||
|
\ {
|
||||||
|
\ 'command': ale#Escape('odd-dhall')
|
||||||
|
\ . ' --ascii'
|
||||||
|
\ . ' lint'
|
||||||
|
\ . ' --inplace %t',
|
||||||
|
\ 'read_temporary_file': 1,
|
||||||
|
\ }
|
||||||
Reference in New Issue
Block a user