mirror of https://github.com/dense-analysis/ale
Add dprint fixer (#4024)
* Add dprint fixer * Fix windows tests * dd dprint documentation
This commit is contained in:
parent
48f68598cb
commit
ac0495df6e
|
@ -496,6 +496,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'],
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
call ale#Set('dprint_executable', 'dprint')
|
||||
call ale#Set('dprint_executable_override', 0)
|
||||
call ale#Set('dprint_use_global', get(g:, 'ale_use_global_executables', 0))
|
||||
call ale#Set('dprint_options', '')
|
||||
call ale#Set('dprint_config', 'dprint.json')
|
||||
|
||||
function! ale#fixers#dprint#Fix(buffer) abort
|
||||
let l:executable = ale#path#FindExecutable(a:buffer, 'dprint', ['dprint'])
|
||||
let l:executable_override = ale#Var(a:buffer, 'dprint_executable_override')
|
||||
|
||||
if !executable(l:executable) && !l:executable_override
|
||||
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
|
|
@ -25,6 +25,12 @@ g:ale_dockerfile_dockerfile_lint_options
|
|||
the dockerfile lint invocation - like custom rule file definitions.
|
||||
|
||||
|
||||
===============================================================================
|
||||
dprint *ale-dockerfile-dprint*
|
||||
|
||||
See |ale-dprint-options| and https://dprint.dev/plugins/dockerfile
|
||||
|
||||
|
||||
===============================================================================
|
||||
hadolint *ale-dockerfile-hadolint*
|
||||
|
||||
|
|
|
@ -35,6 +35,12 @@ deno *ale-javascript-deno*
|
|||
Check the docs over at |ale-typescript-deno|.
|
||||
|
||||
|
||||
===============================================================================
|
||||
dprint *ale-javascript-dprint*
|
||||
|
||||
See |ale-dprint-options| and https://dprint.dev/plugins/typescript
|
||||
|
||||
|
||||
===============================================================================
|
||||
eslint *ale-javascript-eslint*
|
||||
|
||||
|
|
|
@ -8,6 +8,12 @@ cspell *ale-json-cspell*
|
|||
See |ale-cspell-options|
|
||||
|
||||
|
||||
===============================================================================
|
||||
dprint *ale-json-dprint*
|
||||
|
||||
See |ale-dprint-options| and https://dprint.dev/plugins/json
|
||||
|
||||
|
||||
===============================================================================
|
||||
eslint *ale-json-eslint*
|
||||
|
||||
|
|
|
@ -8,6 +8,12 @@ cspell *ale-markdown-cspell*
|
|||
See |ale-cspell-options|
|
||||
|
||||
|
||||
===============================================================================
|
||||
dprint *ale-markdown-dprint*
|
||||
|
||||
See |ale-dprint-options| and https://dprint.dev/plugins/markdown
|
||||
|
||||
|
||||
===============================================================================
|
||||
markdownlint *ale-markdown-markdownlint*
|
||||
|
||||
|
|
|
@ -2,6 +2,13 @@
|
|||
ALE SQL Integration *ale-sql-options*
|
||||
|
||||
|
||||
===============================================================================
|
||||
dprint *ale-sql-dprint*
|
||||
|
||||
See |ale-dprint-options|
|
||||
and https://github.com/dprint/dprint-plugin-sql/releases
|
||||
|
||||
|
||||
===============================================================================
|
||||
pgformatter *ale-sql-pgformatter*
|
||||
|
||||
|
|
|
@ -147,6 +147,7 @@ Notes:
|
|||
* `dhall-lint`
|
||||
* Dockerfile
|
||||
* `dockerfile_lint`
|
||||
* `dprint`
|
||||
* `hadolint`
|
||||
* Elixir
|
||||
* `credo`
|
||||
|
@ -267,6 +268,7 @@ Notes:
|
|||
* JavaScript
|
||||
* `cspell`
|
||||
* `deno`
|
||||
* `dprint`
|
||||
* `eslint`
|
||||
* `fecs`
|
||||
* `flow`
|
||||
|
@ -280,6 +282,7 @@ Notes:
|
|||
* `xo`
|
||||
* JSON
|
||||
* `cspell`
|
||||
* `dprint`
|
||||
* `eslint`
|
||||
* `fixjson`
|
||||
* `jq`
|
||||
|
@ -537,6 +540,7 @@ Notes:
|
|||
* `solhint`
|
||||
* `solium`
|
||||
* SQL
|
||||
* `dprint`
|
||||
* `pgformatter`
|
||||
* `sql-lint`
|
||||
* `sqlfmt`
|
||||
|
@ -583,9 +587,12 @@ Notes:
|
|||
* Thrift
|
||||
* `thrift`
|
||||
* `thriftcheck`
|
||||
* TOML
|
||||
* `dprint`
|
||||
* TypeScript
|
||||
* `cspell`
|
||||
* `deno`
|
||||
* `dprint`
|
||||
* `eslint`
|
||||
* `fecs`
|
||||
* `prettier`
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
===============================================================================
|
||||
ALE TOML Integration *ale-toml-options*
|
||||
|
||||
|
||||
===============================================================================
|
||||
dprint *ale-toml-dprint*
|
||||
|
||||
See |ale-dprint-options| and https://dprint.dev/plugins/toml
|
||||
|
||||
|
||||
===============================================================================
|
||||
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
|
@ -50,6 +50,12 @@ g:ale_deno_importMap *g:ale_deno_importMap*
|
|||
Specify the import map filename to load url maps in a deno project.
|
||||
|
||||
|
||||
===============================================================================
|
||||
dprint *ale-typescript-dprint*
|
||||
|
||||
See |ale-dprint-options| and https://dprint.dev/plugins/typescript
|
||||
|
||||
|
||||
===============================================================================
|
||||
eslint *ale-typescript-eslint*
|
||||
|
||||
|
|
57
doc/ale.txt
57
doc/ale.txt
|
@ -2597,7 +2597,50 @@ g:ale_cspell_use_global *g:ale_cspell_use_global*
|
|||
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
7.3. Options for languagetool *ale-languagetool-options*
|
||||
7.3. Options for dprint *ale-dprint-options*
|
||||
|
||||
`dprint` is a fixer for many file types, including: (java|type)script,
|
||||
json(c?), markdown, and more. See https://dprint.dev/plugins for an up-to-date
|
||||
list of supported plugins and their configuration options.
|
||||
|
||||
g:ale_dprint_executable *g:ale_dprint_executable*
|
||||
*b:ale_dprint_executable*
|
||||
Type: |String|
|
||||
Default: `'dprint'`
|
||||
|
||||
See |ale-integrations-local-executables|
|
||||
|
||||
|
||||
g:ale_dprint_config *g:ale_dprint_config*
|
||||
*b:ale_dprint_config*
|
||||
Type: |String|
|
||||
Default: `'dprint.json'`
|
||||
|
||||
This variable can be changed to provide a config file to `dprint`. The
|
||||
default is the nearest `dprint.json` searching upward from the current
|
||||
buffer.
|
||||
|
||||
See https://dprint.dev/config and https://plugins.dprint.dev
|
||||
|
||||
|
||||
g:ale_dprint_options *g:ale_dprint_options*
|
||||
*b:ale_dprint_options*
|
||||
Type: |String|
|
||||
Default: `''`
|
||||
|
||||
This variable can be set to pass additional options to `dprint`.
|
||||
|
||||
|
||||
g:ale_dprint_use_global *g:ale_dprint_use_global*
|
||||
*b:ale_dprint_use_global*
|
||||
Type: |Number|
|
||||
Default: `get(g: 'ale_use_global_executables', 0)`
|
||||
|
||||
See |ale-integrations-local-executables|
|
||||
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
7.4. Options for languagetool *ale-languagetool-options*
|
||||
|
||||
g:ale_languagetool_executable *g:ale_languagetool_executable*
|
||||
*b:ale_languagetool_executable*
|
||||
|
@ -2617,7 +2660,7 @@ g:ale_languagetool_options *g:ale_languagetool_options*
|
|||
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
7.4. Options for write-good *ale-write-good-options*
|
||||
7.5. Options for write-good *ale-write-good-options*
|
||||
|
||||
The options for `write-good` are shared between all filetypes, so options can
|
||||
be configured once.
|
||||
|
@ -2647,7 +2690,7 @@ g:ale_writegood_use_global *g:ale_writegood_use_global*
|
|||
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
7.5. Other Linter/Fixer Options *ale-other-integration-options*
|
||||
7.6. Other Linter/Fixer Options *ale-other-integration-options*
|
||||
|
||||
ALE supports a very wide variety of tools. Other linter or fixer options are
|
||||
documented in additional help files.
|
||||
|
@ -2752,6 +2795,7 @@ documented in additional help files.
|
|||
dhall-lint............................|ale-dhall-lint|
|
||||
dockerfile..............................|ale-dockerfile-options|
|
||||
dockerfile_lint.......................|ale-dockerfile-dockerfile_lint|
|
||||
dprint................................|ale-dockerfile-dprint|
|
||||
hadolint..............................|ale-dockerfile-hadolint|
|
||||
elixir..................................|ale-elixir-options|
|
||||
mix...................................|ale-elixir-mix|
|
||||
|
@ -2863,6 +2907,7 @@ documented in additional help files.
|
|||
javascript..............................|ale-javascript-options|
|
||||
cspell................................|ale-javascript-cspell|
|
||||
deno..................................|ale-javascript-deno|
|
||||
dprint................................|ale-javascript-dprint|
|
||||
eslint................................|ale-javascript-eslint|
|
||||
fecs..................................|ale-javascript-fecs|
|
||||
flow..................................|ale-javascript-flow|
|
||||
|
@ -2876,6 +2921,7 @@ documented in additional help files.
|
|||
xo....................................|ale-javascript-xo|
|
||||
json....................................|ale-json-options|
|
||||
cspell................................|ale-json-cspell|
|
||||
dprint................................|ale-json-dprint|
|
||||
eslint................................|ale-json-eslint|
|
||||
fixjson...............................|ale-json-fixjson|
|
||||
jsonlint..............................|ale-json-jsonlint|
|
||||
|
@ -2914,6 +2960,7 @@ documented in additional help files.
|
|||
stylua................................|ale-lua-stylua|
|
||||
markdown................................|ale-markdown-options|
|
||||
cspell................................|ale-markdown-cspell|
|
||||
dprint................................|ale-markdown-dprint|
|
||||
markdownlint..........................|ale-markdown-markdownlint|
|
||||
mdl...................................|ale-markdown-mdl|
|
||||
pandoc................................|ale-markdown-pandoc|
|
||||
|
@ -3095,6 +3142,7 @@ documented in additional help files.
|
|||
spec....................................|ale-spec-options|
|
||||
rpmlint...............................|ale-spec-rpmlint|
|
||||
sql.....................................|ale-sql-options|
|
||||
dprint................................|ale-sql-dprint|
|
||||
pgformatter...........................|ale-sql-pgformatter|
|
||||
sqlfmt................................|ale-sql-sqlfmt|
|
||||
sqlformat.............................|ale-sql-sqlformat|
|
||||
|
@ -3136,9 +3184,12 @@ documented in additional help files.
|
|||
thrift..................................|ale-thrift-options|
|
||||
thrift................................|ale-thrift-thrift|
|
||||
thriftcheck...........................|ale-thrift-thriftcheck|
|
||||
toml....................................|ale-toml-options|
|
||||
dprint................................|ale-toml-dprint|
|
||||
typescript..............................|ale-typescript-options|
|
||||
cspell................................|ale-typescript-cspell|
|
||||
deno..................................|ale-typescript-deno|
|
||||
dprint................................|ale-typescript-dprint|
|
||||
eslint................................|ale-typescript-eslint|
|
||||
prettier..............................|ale-typescript-prettier|
|
||||
standard..............................|ale-typescript-standard|
|
||||
|
|
|
@ -156,6 +156,7 @@ formatting.
|
|||
* [dhall-lint](https://github.com/dhall-lang/dhall-lang)
|
||||
* Dockerfile
|
||||
* [dockerfile_lint](https://github.com/projectatomic/dockerfile_lint)
|
||||
* [dprint](https://dprint.dev)
|
||||
* [hadolint](https://github.com/hadolint/hadolint)
|
||||
* Elixir
|
||||
* [credo](https://github.com/rrrene/credo)
|
||||
|
@ -276,6 +277,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/)
|
||||
|
@ -289,6 +291,7 @@ formatting.
|
|||
* [xo](https://github.com/sindresorhus/xo)
|
||||
* JSON
|
||||
* [cspell](https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell)
|
||||
* [dprint](https://dprint.dev)
|
||||
* [eslint](http://eslint.org/)
|
||||
* [fixjson](https://github.com/rhysd/fixjson)
|
||||
* [jq](https://stedolan.github.io/jq/)
|
||||
|
@ -546,6 +549,7 @@ formatting.
|
|||
* [solhint](https://github.com/protofire/solhint)
|
||||
* [solium](https://github.com/duaraghav8/Solium)
|
||||
* SQL
|
||||
* [dprint](https://dprint.dev)
|
||||
* [pgformatter](https://github.com/darold/pgFormatter)
|
||||
* [sql-lint](https://github.com/joereynolds/sql-lint)
|
||||
* [sqlfmt](https://github.com/jackc/sqlfmt)
|
||||
|
@ -592,9 +596,12 @@ formatting.
|
|||
* Thrift
|
||||
* [thrift](http://thrift.apache.org/)
|
||||
* [thriftcheck](https://github.com/pinterest/thriftcheck)
|
||||
* TOML
|
||||
* [dprint](https://dprint.dev)
|
||||
* 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)
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
Before:
|
||||
call ale#assert#SetUpFixerTest('typescript', 'dprint')
|
||||
call ale#test#SetFilename('../test-files/dprint/blank.ts')
|
||||
let g:ale_dprint_executable_override = 0
|
||||
let g:ale_dprint_executable = 'dprint'
|
||||
let g:ale_dprint_config = ''
|
||||
|
||||
After:
|
||||
Restore
|
||||
call ale#assert#TearDownFixerTest()
|
||||
|
||||
Execute(The dprint callback should return 0 for a non-existent executable):
|
||||
let g:ale_dprint_executable = 'foo'
|
||||
AssertFixer 0
|
||||
|
||||
Execute(The dprint callback should return the correct default values):
|
||||
let g:ale_dprint_executable_override = 1
|
||||
AssertFixer {
|
||||
\ 'command': ale#Escape('dprint')
|
||||
\ . ' fmt '
|
||||
\ . ' --stdin %s'
|
||||
\ }
|
||||
|
||||
Execute(The dprint callback should include config):
|
||||
let g:ale_dprint_executable_override = 1
|
||||
let g:ale_dprint_config = 'dprint.json'
|
||||
|
||||
AssertFixer {
|
||||
\ 'command': ale#Escape('dprint')
|
||||
\ . ' fmt '
|
||||
\ . ' -c '
|
||||
\ . ale#Escape((has('win32') ? 'C:\testplugin\test\test-files\dprint\dprint.json' : '/testplugin/test/test-files/dprint/dprint.json'))
|
||||
\ . ' --stdin %s'
|
||||
\ }
|
||||
|
||||
Execute(The dprint callback should include custom options):
|
||||
let g:ale_dprint_executable_override = 1
|
||||
let g:ale_dprint_options = '--verbose'
|
||||
|
||||
AssertFixer {
|
||||
\ 'command': ale#Escape('dprint')
|
||||
\ . ' fmt '
|
||||
\ . '--verbose' . ' --stdin %s'
|
||||
\ }
|
Loading…
Reference in New Issue