Skip to content

Commit

Permalink
Add dprint fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
myobie committed Dec 26, 2021
1 parent dcec4b3 commit f20971a
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
5 changes: 5 additions & 0 deletions autoload/ale/fix/registry.vim
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['lua'],
\ 'description': 'Fix Lua files with luafmt.',
\ },
\ 'dprint': {
\ 'function': 'ale#fixers#dprint#Fix',
\ 'suggested_filetypes': ['javascript', 'typescript', 'json', 'markdown'],
\ 'description': 'Pluggable and configurable code formatting platform',
\ },
\ 'stylua': {
\ 'function': 'ale#fixers#stylua#Fix',
\ 'suggested_filetypes': ['lua'],
Expand Down
24 changes: 24 additions & 0 deletions autoload/ale/fixers/dprint.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
call ale#Set('dprint_executable', 'dprint')
call ale#Set('dprint_options', '')
call ale#Set('dprint_config', 'dprint.json')

function! ale#fixers#dprint#Fix(buffer) abort
let l:executable = ale#Var(a:buffer, 'dprint_executable')

if !executable(l:executable)
return 0
endif

let l:options = ale#Var(a:buffer, 'dprint_options')
let l:config = ale#path#FindNearestFile(a:buffer, ale#Var(a:buffer, 'dprint_config'))

if !empty(l:config)
let l:options = l:options . ' -c ' . ale#Escape(l:config)
endif

let l:options = l:options . ' --stdin %s'

return {
\ 'command': ale#Escape(l:executable) . ' fmt ' . l:options,
\}
endfunction
2 changes: 2 additions & 0 deletions doc/ale-supported-languages-and-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ Notes:
* JavaScript
* `cspell`
* `deno`
* `dprint`
* `eslint`
* `fecs`
* `flow`
Expand Down Expand Up @@ -586,6 +587,7 @@ Notes:
* TypeScript
* `cspell`
* `deno`
* `dprint`
* `eslint`
* `fecs`
* `prettier`
Expand Down
2 changes: 2 additions & 0 deletions supported-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ formatting.
* JavaScript
* [cspell](https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell)
* [deno](https://deno.land/)
* [dprint](https://dprint.dev/)
* [eslint](http://eslint.org/)
* [fecs](http://fecs.baidu.com/)
* [flow](https://flowtype.org/)
Expand Down Expand Up @@ -595,6 +596,7 @@ formatting.
* TypeScript
* [cspell](https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell)
* [deno](https://deno.land/)
* [dprint](https://dprint.dev/)
* [eslint](http://eslint.org/)
* [fecs](http://fecs.baidu.com/)
* [prettier](https://github.com/prettier/prettier)
Expand Down
28 changes: 28 additions & 0 deletions test/fixers/test_dprint_fixer_callback.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Before:
call ale#assert#SetUpFixerTest('typescript', 'dprint')

After:
Restore
call ale#assert#TearDownFixerTest()

Execute(The dprint callback should return the correct default values):
AssertFixer
\ {
\ 'read_temporary_file': 1,
\ 'command':
\ ale#Escape('dprint')
\ . ' ' . ale#Escape('')
\ . ' %t',
\ }

Execute(The dprint callback should include custom options):
let g:ale_typescript_dprint_options = '-c dprint.json'

AssertFixer
\ {
\ 'read_temporary_file': 1,
\ 'command':
\ ale#Escape('dprint')
\ . ' ' . ale#Escape('-c dprint.json')
\ . ' %t',
\ }

0 comments on commit f20971a

Please sign in to comment.