Skip to content

Commit c208aa3

Browse files
committed
Add dprint fixer
1 parent dcec4b3 commit c208aa3

File tree

5 files changed

+69
-0
lines changed

5 files changed

+69
-0
lines changed

autoload/ale/fix/registry.vim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,11 @@ let s:default_registry = {
491491
\ 'suggested_filetypes': ['lua'],
492492
\ 'description': 'Fix Lua files with luafmt.',
493493
\ },
494+
\ 'dprint': {
495+
\ 'function': 'ale#fixers#dprint#Fix',
496+
\ 'suggested_filetypes': ['javascript', 'typescript', 'json', 'markdown'],
497+
\ 'description': 'Pluggable and configurable code formatting platform',
498+
\ },
494499
\ 'stylua': {
495500
\ 'function': 'ale#fixers#stylua#Fix',
496501
\ 'suggested_filetypes': ['lua'],

autoload/ale/fixers/dprint.vim

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
call ale#Set('dprint_executable', 'dprint')
2+
call ale#Set('dprint_options', '')
3+
call ale#Set('dprint_config', 'dprint.json')
4+
5+
function! ale#fixers#dprint#Fix(buffer) abort
6+
let l:executable = ale#Var(a:buffer, 'dprint_executable')
7+
8+
if !executable(l:executable)
9+
return 0
10+
endif
11+
12+
let l:options = ale#Var(a:buffer, 'dprint_options')
13+
let l:config = ale#path#FindNearestFile(a:buffer, ale#Var(a:buffer, 'dprint_config'))
14+
15+
if !empty(l:config)
16+
let l:options = l:options . ' -c ' . ale#Escape(l:config)
17+
endif
18+
19+
let l:options = l:options . ' --stdin %s'
20+
21+
return {
22+
\ 'command': ale#Escape(l:executable)
23+
\ . ' fmt '
24+
\ . l:options,
25+
\}
26+
endfunction

doc/ale-supported-languages-and-tools.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ Notes:
267267
* JavaScript
268268
* `cspell`
269269
* `deno`
270+
* `dprint`
270271
* `eslint`
271272
* `fecs`
272273
* `flow`
@@ -586,6 +587,7 @@ Notes:
586587
* TypeScript
587588
* `cspell`
588589
* `deno`
590+
* `dprint`
589591
* `eslint`
590592
* `fecs`
591593
* `prettier`

supported-tools.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ formatting.
276276
* JavaScript
277277
* [cspell](https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell)
278278
* [deno](https://deno.land/)
279+
* [dprint](https://dprint.dev/)
279280
* [eslint](http://eslint.org/)
280281
* [fecs](http://fecs.baidu.com/)
281282
* [flow](https://flowtype.org/)
@@ -595,6 +596,7 @@ formatting.
595596
* TypeScript
596597
* [cspell](https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell)
597598
* [deno](https://deno.land/)
599+
* [dprint](https://dprint.dev/)
598600
* [eslint](http://eslint.org/)
599601
* [fecs](http://fecs.baidu.com/)
600602
* [prettier](https://github.com/prettier/prettier)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Before:
2+
call ale#assert#SetUpFixerTest('typescript', 'dprint')
3+
4+
After:
5+
Restore
6+
call ale#assert#TearDownFixerTest()
7+
8+
Execute(The dprint callback should return the correct default values):
9+
AssertFixer
10+
\ {
11+
\ 'command': ale#Escape('dprint')
12+
\ . ' fmt '
13+
\ . '--stdin %s',
14+
\ }
15+
16+
Execute(The dprint callback should include config):
17+
let g:ale_typescript_dprint_config = 'dprint.json'
18+
19+
AssertFixer
20+
\ {
21+
\ 'command': ale#Escape('dprint')
22+
\ . ' fmt '
23+
\ . ' -c ' . ale#Escape('dprint.json') . ' --stdin %s',
24+
\ }
25+
26+
Execute(The dprint callback should include custom options):
27+
let g:ale_typescript_dprint_options = '--verbose'
28+
29+
AssertFixer
30+
\ {
31+
\ 'command': ale#Escape('dprint')
32+
\ . ' fmt '
33+
\ . '--verbose --stdin %s',
34+
\ }

0 commit comments

Comments
 (0)