Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fixer for toml using taplo #4720

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions autoload/ale/fix/registry.vim
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['javascript', 'typescript'],
\ 'description': 'Apply biome (ex. rome) check to a file.',
\ },
\ 'taplo': {
\ 'function': 'ale#fixers#taplo#Fix',
\ 'suggested_filetypes': ['toml'],
\ 'description': 'Fix TOML files using taplo.',
\ },
\}

" Reset the function registry to the default entries.
Expand Down
10 changes: 10 additions & 0 deletions autoload/ale/fixers/taplo.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
" Author: Jeremy Cantrell <[email protected]>
" Description: A versatile, feature-rich TOML toolkit

function! ale#fixers#taplo#Fix(buffer) abort
let l:executable = ale#handlers#taplo#GetExecutable(a:buffer)

return {
\ 'command': ale#Escape(l:executable) . ' format -'
\}
endfunction
8 changes: 8 additions & 0 deletions autoload/ale/handlers/taplo.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
" Author: Jeremy Cantrell <[email protected]>
" Description: A versatile, feature-rich TOML toolkit

call ale#Set('taplo_executable', 'taplo')

function! ale#handlers#taplo#GetExecutable(buffer) abort
return ale#Var(a:buffer, 'taplo_executable')
endfunction
1 change: 1 addition & 0 deletions doc/ale-supported-languages-and-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ Notes:
* `thriftcheck`
* TOML
* `dprint`
* `taplo`
* TypeScript
* `biome`
* `cspell`
Expand Down
6 changes: 6 additions & 0 deletions doc/ale-toml.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,11 @@ dprint *ale-toml-dprint*
See |ale-dprint-options| and https://dprint.dev/plugins/toml


===============================================================================
taplo *ale-toml-taplo*

See https://taplo.tamasfe.dev/


===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
1 change: 1 addition & 0 deletions doc/ale.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3440,6 +3440,7 @@ documented in additional help files.
thriftcheck...........................|ale-thrift-thriftcheck|
toml....................................|ale-toml-options|
dprint................................|ale-toml-dprint|
taplo.................................|ale-toml-taplo|
typescript..............................|ale-typescript-options|
biome.................................|ale-typescript-biome|
cspell................................|ale-typescript-cspell|
Expand Down
1 change: 1 addition & 0 deletions supported-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@ formatting.
* [thriftcheck](https://github.com/pinterest/thriftcheck)
* TOML
* [dprint](https://dprint.dev)
* [taplo](https://taplo.tamasfe.dev)
* TypeScript
* [biome](http://biomejs.dev)
* [cspell](https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell)
Expand Down
12 changes: 12 additions & 0 deletions test/fixers/test_taplo_fixer.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Before:
Save g:ale_taplo_executable

After:
Restore

Execute(The taplo fixer should use the options you set):
let g:ale_taplo_executable = 'foo'

AssertEqual
\ {'command': ale#Escape('foo') . ' format -'},
\ ale#fixers#taplo#Fix(bufnr(''))