mirror of
https://github.com/dense-analysis/ale.git
synced 2026-08-12 19:06:53 +08:00
5151 add mdformat support (#5152)
* fix(tests): fix ale_c_build_dir_names being unset in tests (#5109) - Use ale#Set() to set the ale_c_build_dir_names variable. - Ensure SetUpLinterTest() is called before any Save commands in tests. - Add c.vim to runtime before non-linter tests are executed. - Remove workarounds in c.vim. * feat: Load Prettier from cjs also * Add support for mdformat --------- Co-authored-by: w0rp <devw0rp@gmail.com>
This commit is contained in:
@@ -462,6 +462,11 @@ let s:default_registry = {
|
|||||||
\ 'suggested_filetypes': ['markdown'],
|
\ 'suggested_filetypes': ['markdown'],
|
||||||
\ 'description': 'Fix markdown files with pandoc.',
|
\ 'description': 'Fix markdown files with pandoc.',
|
||||||
\ },
|
\ },
|
||||||
|
\ 'mdformat': {
|
||||||
|
\ 'function': 'ale#fixers#mdformat#Fix',
|
||||||
|
\ 'suggested_filetypes': ['markdown'],
|
||||||
|
\ 'description': 'Fix Markdown files with mdformat.',
|
||||||
|
\ },
|
||||||
\ 'pymarkdown': {
|
\ 'pymarkdown': {
|
||||||
\ 'function': 'ale#fixers#pymarkdown#Fix',
|
\ 'function': 'ale#fixers#pymarkdown#Fix',
|
||||||
\ 'suggested_filetypes': ['markdown'],
|
\ 'suggested_filetypes': ['markdown'],
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
" Author: Horacio
|
||||||
|
" Description: Fix Markdown files with mdformat.
|
||||||
|
|
||||||
|
call ale#Set('markdown_mdformat_executable', 'mdformat')
|
||||||
|
call ale#Set('markdown_mdformat_options', '')
|
||||||
|
call ale#Set('markdown_mdformat_use_global', get(g:, 'ale_use_global_executables', 0))
|
||||||
|
call ale#Set('markdown_mdformat_auto_pipenv', 0)
|
||||||
|
call ale#Set('markdown_mdformat_auto_poetry', 0)
|
||||||
|
call ale#Set('markdown_mdformat_auto_uv', 0)
|
||||||
|
|
||||||
|
function! ale#fixers#mdformat#GetExecutable(buffer) abort
|
||||||
|
if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'markdown_mdformat_auto_pipenv'))
|
||||||
|
\ && ale#python#PipenvPresent(a:buffer)
|
||||||
|
return 'pipenv'
|
||||||
|
endif
|
||||||
|
|
||||||
|
if (ale#Var(a:buffer, 'python_auto_poetry') || ale#Var(a:buffer, 'markdown_mdformat_auto_poetry'))
|
||||||
|
\ && ale#python#PoetryPresent(a:buffer)
|
||||||
|
return 'poetry'
|
||||||
|
endif
|
||||||
|
|
||||||
|
if (ale#Var(a:buffer, 'python_auto_uv') || ale#Var(a:buffer, 'markdown_mdformat_auto_uv'))
|
||||||
|
\ && ale#python#UvPresent(a:buffer)
|
||||||
|
return 'uv'
|
||||||
|
endif
|
||||||
|
|
||||||
|
return ale#python#FindExecutable(a:buffer, 'markdown_mdformat', ['mdformat'])
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! ale#fixers#mdformat#Fix(buffer) abort
|
||||||
|
let l:executable = ale#fixers#mdformat#GetExecutable(a:buffer)
|
||||||
|
let l:command = ale#Escape(l:executable)
|
||||||
|
|
||||||
|
if l:executable =~? '\(pipenv\|poetry\|uv\)$'
|
||||||
|
let l:command .= ' run mdformat'
|
||||||
|
endif
|
||||||
|
|
||||||
|
return {
|
||||||
|
\ 'command': l:command
|
||||||
|
\ . ale#Pad(ale#Var(a:buffer, 'markdown_mdformat_options'))
|
||||||
|
\ . ' -',
|
||||||
|
\}
|
||||||
|
endfunction
|
||||||
@@ -82,6 +82,77 @@ g:ale_markdown_marksman_executable
|
|||||||
Override the invoked `marksman` binary.
|
Override the invoked `marksman` binary.
|
||||||
|
|
||||||
|
|
||||||
|
===============================================================================
|
||||||
|
mdformat *ale-markdown-mdformat*
|
||||||
|
|
||||||
|
*ale-options.markdown_mdformat_executable*
|
||||||
|
*g:ale_markdown_mdformat_executable*
|
||||||
|
*b:ale_markdown_mdformat_executable*
|
||||||
|
markdown_mdformat_executable
|
||||||
|
g:ale_markdown_mdformat_executable
|
||||||
|
Type: |String|
|
||||||
|
Default: `'mdformat'`
|
||||||
|
|
||||||
|
See |ale-integrations-local-executables|
|
||||||
|
|
||||||
|
Set this to `'pipenv'` to invoke `pipenv run mdformat`.
|
||||||
|
Set this to `'poetry'` to invoke `poetry run mdformat`.
|
||||||
|
Set this to `'uv'` to invoke `uv run mdformat`.
|
||||||
|
|
||||||
|
*ale-options.markdown_mdformat_options*
|
||||||
|
*g:ale_markdown_mdformat_options*
|
||||||
|
*b:ale_markdown_mdformat_options*
|
||||||
|
markdown_mdformat_options
|
||||||
|
g:ale_markdown_mdformat_options
|
||||||
|
Type: |String|
|
||||||
|
Default: `''`
|
||||||
|
|
||||||
|
This variable can be changed to add command-line arguments to mdformat.
|
||||||
|
|
||||||
|
*ale-options.markdown_mdformat_use_global*
|
||||||
|
*g:ale_markdown_mdformat_use_global*
|
||||||
|
*b:ale_markdown_mdformat_use_global*
|
||||||
|
markdown_mdformat_use_global
|
||||||
|
g:ale_markdown_mdformat_use_global
|
||||||
|
Type: |Number|
|
||||||
|
Default: `get(g:, 'ale_use_global_executables', 0)`
|
||||||
|
|
||||||
|
See |ale-integrations-local-executables|
|
||||||
|
|
||||||
|
*ale-options.markdown_mdformat_auto_pipenv*
|
||||||
|
*g:ale_markdown_mdformat_auto_pipenv*
|
||||||
|
*b:ale_markdown_mdformat_auto_pipenv*
|
||||||
|
markdown_mdformat_auto_pipenv
|
||||||
|
g:ale_markdown_mdformat_auto_pipenv
|
||||||
|
Type: |Number|
|
||||||
|
Default: `0`
|
||||||
|
|
||||||
|
Detect whether the file is inside a pipenv, and set the executable to
|
||||||
|
`pipenv` if true. This is overridden by a manually-set executable.
|
||||||
|
|
||||||
|
*ale-options.markdown_mdformat_auto_poetry*
|
||||||
|
*g:ale_markdown_mdformat_auto_poetry*
|
||||||
|
*b:ale_markdown_mdformat_auto_poetry*
|
||||||
|
markdown_mdformat_auto_poetry
|
||||||
|
g:ale_markdown_mdformat_auto_poetry
|
||||||
|
Type: |Number|
|
||||||
|
Default: `0`
|
||||||
|
|
||||||
|
Detect whether the file is inside a Poetry project, and set the executable
|
||||||
|
to `poetry` if true. This is overridden by a manually-set executable.
|
||||||
|
|
||||||
|
*ale-options.markdown_mdformat_auto_uv*
|
||||||
|
*g:ale_markdown_mdformat_auto_uv*
|
||||||
|
*b:ale_markdown_mdformat_auto_uv*
|
||||||
|
markdown_mdformat_auto_uv
|
||||||
|
g:ale_markdown_mdformat_auto_uv
|
||||||
|
Type: |Number|
|
||||||
|
Default: `0`
|
||||||
|
|
||||||
|
Detect whether the file is inside a uv project, and set the executable to
|
||||||
|
`uv` if true. This is overridden by a manually-set executable.
|
||||||
|
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
mdl *ale-markdown-mdl*
|
mdl *ale-markdown-mdl*
|
||||||
|
|
||||||
|
|||||||
@@ -436,6 +436,7 @@ Notes:
|
|||||||
* `languagetool`!!
|
* `languagetool`!!
|
||||||
* `markdownlint`!!
|
* `markdownlint`!!
|
||||||
* `marksman`
|
* `marksman`
|
||||||
|
* `mdformat`
|
||||||
* `mdl`
|
* `mdl`
|
||||||
* `pandoc`
|
* `pandoc`
|
||||||
* `prettier`
|
* `prettier`
|
||||||
|
|||||||
@@ -3779,6 +3779,7 @@ documented in additional help files.
|
|||||||
harper................................|ale-markdown-harper|
|
harper................................|ale-markdown-harper|
|
||||||
markdownlint..........................|ale-markdown-markdownlint|
|
markdownlint..........................|ale-markdown-markdownlint|
|
||||||
marksman..............................|ale-markdown-marksman|
|
marksman..............................|ale-markdown-marksman|
|
||||||
|
mdformat..............................|ale-markdown-mdformat|
|
||||||
mdl...................................|ale-markdown-mdl|
|
mdl...................................|ale-markdown-mdl|
|
||||||
pandoc................................|ale-markdown-pandoc|
|
pandoc................................|ale-markdown-pandoc|
|
||||||
prettier..............................|ale-markdown-prettier|
|
prettier..............................|ale-markdown-prettier|
|
||||||
|
|||||||
@@ -446,6 +446,7 @@ formatting.
|
|||||||
* [languagetool](https://languagetool.org/) :floppy_disk: :speech_balloon:
|
* [languagetool](https://languagetool.org/) :floppy_disk: :speech_balloon:
|
||||||
* [markdownlint](https://github.com/DavidAnson/markdownlint) :floppy_disk:
|
* [markdownlint](https://github.com/DavidAnson/markdownlint) :floppy_disk:
|
||||||
* [marksman](https://github.com/artempyanykh/marksman) :speech_balloon:
|
* [marksman](https://github.com/artempyanykh/marksman) :speech_balloon:
|
||||||
|
* [mdformat](https://github.com/hukkin/mdformat)
|
||||||
* [mdl](https://github.com/mivok/markdownlint)
|
* [mdl](https://github.com/mivok/markdownlint)
|
||||||
* [pandoc](https://pandoc.org)
|
* [pandoc](https://pandoc.org)
|
||||||
* [prettier](https://github.com/prettier/prettier)
|
* [prettier](https://github.com/prettier/prettier)
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
Before:
|
||||||
|
call ale#assert#SetUpFixerTest('markdown', 'mdformat')
|
||||||
|
|
||||||
|
After:
|
||||||
|
call ale#assert#TearDownFixerTest()
|
||||||
|
|
||||||
|
Execute(The mdformat callback should return the default command):
|
||||||
|
AssertFixer
|
||||||
|
\ {
|
||||||
|
\ 'command': ale#Escape('mdformat') . ' -',
|
||||||
|
\ }
|
||||||
|
|
||||||
|
Execute(The mdformat executable and options should be configurable):
|
||||||
|
let g:ale_markdown_mdformat_executable = 'foobar'
|
||||||
|
let g:ale_markdown_mdformat_options = '--wrap 80'
|
||||||
|
|
||||||
|
AssertFixer
|
||||||
|
\ {
|
||||||
|
\ 'command': ale#Escape('foobar') . ' --wrap 80 -',
|
||||||
|
\ }
|
||||||
|
|
||||||
|
Execute(Setting executable to pipenv should append run mdformat):
|
||||||
|
let g:ale_markdown_mdformat_executable = 'path/to/pipenv'
|
||||||
|
|
||||||
|
AssertFixer
|
||||||
|
\ {
|
||||||
|
\ 'command': ale#Escape('path/to/pipenv') . ' run mdformat -',
|
||||||
|
\ }
|
||||||
|
|
||||||
|
Execute(Poetry should be detected when auto_poetry is set):
|
||||||
|
let g:ale_markdown_mdformat_auto_poetry = 1
|
||||||
|
call ale#test#SetFilename('../test-files/python/poetry/whatever.py')
|
||||||
|
|
||||||
|
AssertFixer
|
||||||
|
\ {
|
||||||
|
\ 'command': ale#Escape('poetry') . ' run mdformat -',
|
||||||
|
\ }
|
||||||
|
|
||||||
|
Execute(uv should be detected when auto_uv is set):
|
||||||
|
let g:ale_markdown_mdformat_auto_uv = 1
|
||||||
|
call ale#test#SetFilename('../test-files/python/uv/whatever.py')
|
||||||
|
|
||||||
|
AssertFixer
|
||||||
|
\ {
|
||||||
|
\ 'command': ale#Escape('uv') . ' run mdformat -',
|
||||||
|
\ }
|
||||||
Reference in New Issue
Block a user