mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-22 20:11:26 +08:00
Add pymarkdown fixer (#5045)
Some checks are pending
CI / build_image (push) Waiting to run
CI / test_ale (--linters-only) (push) Blocked by required conditions
CI / test_ale (--lua-only) (push) Blocked by required conditions
CI / test_ale (--neovim-07-only) (push) Blocked by required conditions
CI / test_ale (--neovim-08-only) (push) Blocked by required conditions
CI / test_ale (--vim-80-only) (push) Blocked by required conditions
CI / test_ale (--vim-90-only) (push) Blocked by required conditions
Some checks are pending
CI / build_image (push) Waiting to run
CI / test_ale (--linters-only) (push) Blocked by required conditions
CI / test_ale (--lua-only) (push) Blocked by required conditions
CI / test_ale (--neovim-07-only) (push) Blocked by required conditions
CI / test_ale (--neovim-08-only) (push) Blocked by required conditions
CI / test_ale (--vim-80-only) (push) Blocked by required conditions
CI / test_ale (--vim-90-only) (push) Blocked by required conditions
This commit is contained in:
@@ -457,6 +457,11 @@ let s:default_registry = {
|
|||||||
\ 'suggested_filetypes': ['markdown'],
|
\ 'suggested_filetypes': ['markdown'],
|
||||||
\ 'description': 'Fix markdown files with pandoc.',
|
\ 'description': 'Fix markdown files with pandoc.',
|
||||||
\ },
|
\ },
|
||||||
|
\ 'pymarkdown': {
|
||||||
|
\ 'function': 'ale#fixers#pymarkdown#Fix',
|
||||||
|
\ 'suggested_filetypes': ['markdown'],
|
||||||
|
\ 'description': 'Fix markdown files with pymarkdown.',
|
||||||
|
\ },
|
||||||
\ 'shfmt': {
|
\ 'shfmt': {
|
||||||
\ 'function': 'ale#fixers#shfmt#Fix',
|
\ 'function': 'ale#fixers#shfmt#Fix',
|
||||||
\ 'suggested_filetypes': ['sh'],
|
\ 'suggested_filetypes': ['sh'],
|
||||||
|
|||||||
46
autoload/ale/fixers/pymarkdown.vim
Normal file
46
autoload/ale/fixers/pymarkdown.vim
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
scriptencoding utf-8
|
||||||
|
" Author: Adrian Vollmer <adrian.vollmer@syss.de>
|
||||||
|
" Description: Fix markdown files with pymarkdown.
|
||||||
|
|
||||||
|
call ale#Set('markdown_pymarkdown_executable', 'pymarkdown')
|
||||||
|
call ale#Set('markdown_pymarkdown_options', '')
|
||||||
|
call ale#Set('markdown_pymarkdown_use_global', get(g:, 'ale_use_global_executables', 0))
|
||||||
|
call ale#Set('markdown_pymarkdown_auto_pipenv', 0)
|
||||||
|
call ale#Set('markdown_pymarkdown_auto_poetry', 0)
|
||||||
|
call ale#Set('markdown_pymarkdown_auto_uv', 0)
|
||||||
|
|
||||||
|
function! ale#fixers#pymarkdown#GetExecutable(buffer) abort
|
||||||
|
if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'markdown_pymarkdown_auto_pipenv'))
|
||||||
|
\ && ale#python#PipenvPresent(a:buffer)
|
||||||
|
return 'pipenv'
|
||||||
|
endif
|
||||||
|
|
||||||
|
if (ale#Var(a:buffer, 'python_auto_poetry') || ale#Var(a:buffer, 'markdown_pymarkdown_auto_poetry'))
|
||||||
|
\ && ale#python#PoetryPresent(a:buffer)
|
||||||
|
return 'poetry'
|
||||||
|
endif
|
||||||
|
|
||||||
|
if (ale#Var(a:buffer, 'python_auto_uv') || ale#Var(a:buffer, 'markdown_pymarkdown_auto_uv'))
|
||||||
|
\ && ale#python#UvPresent(a:buffer)
|
||||||
|
return 'uv'
|
||||||
|
endif
|
||||||
|
|
||||||
|
return ale#python#FindExecutable(a:buffer, 'markdown_pymarkdown', ['pymarkdown'])
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! ale#fixers#pymarkdown#Fix(buffer) abort
|
||||||
|
let l:executable = ale#fixers#pymarkdown#GetExecutable(a:buffer)
|
||||||
|
let l:options = ale#Var(a:buffer, 'markdown_pymarkdown_options')
|
||||||
|
|
||||||
|
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
|
||||||
|
\ ? ' run pymarkdown'
|
||||||
|
\ : ''
|
||||||
|
|
||||||
|
return {
|
||||||
|
\ 'command': ale#Escape(l:executable) . l:exec_args
|
||||||
|
\ . ' fix'
|
||||||
|
\ . (!empty(l:options) ? ' ' . l:options : '')
|
||||||
|
\ . ' %t',
|
||||||
|
\ 'read_temporary_file': 1,
|
||||||
|
\}
|
||||||
|
endfunction
|
||||||
@@ -111,6 +111,8 @@ See |ale-javascript-prettier| for information about the available options.
|
|||||||
===============================================================================
|
===============================================================================
|
||||||
pymarkdown *ale-markdown-pymarkdown*
|
pymarkdown *ale-markdown-pymarkdown*
|
||||||
|
|
||||||
|
pymarkdown can be used both as a linter and a fixer for Markdown files.
|
||||||
|
|
||||||
*ale-options.markdown_pymarkdown_executable*
|
*ale-options.markdown_pymarkdown_executable*
|
||||||
*g:ale_markdown_pymarkdown_executable*
|
*g:ale_markdown_pymarkdown_executable*
|
||||||
*b:ale_markdown_pymarkdown_executable*
|
*b:ale_markdown_pymarkdown_executable*
|
||||||
|
|||||||
@@ -421,7 +421,7 @@ formatting.
|
|||||||
* [pandoc](https://pandoc.org)
|
* [pandoc](https://pandoc.org)
|
||||||
* [prettier](https://github.com/prettier/prettier)
|
* [prettier](https://github.com/prettier/prettier)
|
||||||
* [proselint](http://proselint.com/)
|
* [proselint](http://proselint.com/)
|
||||||
* [pymarkdown](https://github.com/jackdewinter/pymarkdown)
|
* [pymarkdown](https://github.com/jackdewinter/pymarkdown) :floppy_disk:
|
||||||
* [redpen](http://redpen.cc/)
|
* [redpen](http://redpen.cc/)
|
||||||
* [remark-lint](https://github.com/wooorm/remark-lint)
|
* [remark-lint](https://github.com/wooorm/remark-lint)
|
||||||
* [textlint](https://textlint.github.io/)
|
* [textlint](https://textlint.github.io/)
|
||||||
|
|||||||
81
test/fixers/test_pymarkdown_fixer_callback.vader
Normal file
81
test/fixers/test_pymarkdown_fixer_callback.vader
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
Before:
|
||||||
|
Save g:ale_markdown_pymarkdown_executable
|
||||||
|
Save g:ale_markdown_pymarkdown_options
|
||||||
|
Save g:ale_markdown_pymarkdown_auto_pipenv
|
||||||
|
Save g:ale_markdown_pymarkdown_auto_poetry
|
||||||
|
Save g:ale_markdown_pymarkdown_auto_uv
|
||||||
|
|
||||||
|
After:
|
||||||
|
Restore
|
||||||
|
|
||||||
|
Execute(The pymarkdown callback should return 'pymarkdown' as default command):
|
||||||
|
AssertEqual
|
||||||
|
\ {
|
||||||
|
\ 'command': ale#Escape('pymarkdown') . ' fix %t',
|
||||||
|
\ 'read_temporary_file': 1,
|
||||||
|
\ },
|
||||||
|
\ ale#fixers#pymarkdown#Fix(bufnr(''))
|
||||||
|
|
||||||
|
Execute(The pymarkdown executable and options should be configurable):
|
||||||
|
let g:ale_markdown_pymarkdown_executable = 'foobar'
|
||||||
|
let g:ale_markdown_pymarkdown_options = '--some-option'
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ {
|
||||||
|
\ 'command': ale#Escape('foobar') . ' fix --some-option %t',
|
||||||
|
\ 'read_temporary_file': 1,
|
||||||
|
\ },
|
||||||
|
\ ale#fixers#pymarkdown#Fix(bufnr(''))
|
||||||
|
|
||||||
|
Execute(Setting executable to 'pipenv' appends 'run pymarkdown'):
|
||||||
|
let g:ale_markdown_pymarkdown_executable = 'path/to/pipenv'
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ {
|
||||||
|
\ 'command': ale#Escape('path/to/pipenv') . ' run pymarkdown fix %t',
|
||||||
|
\ 'read_temporary_file': 1,
|
||||||
|
\ },
|
||||||
|
\ ale#fixers#pymarkdown#Fix(bufnr(''))
|
||||||
|
|
||||||
|
Execute(Pipenv is detected when markdown_pymarkdown_auto_pipenv is set):
|
||||||
|
let g:ale_markdown_pymarkdown_auto_pipenv = 1
|
||||||
|
call ale#test#SetFilename('../test-files/python/pipenv/whatever.py')
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ {
|
||||||
|
\ 'command': ale#Escape('pipenv') . ' run pymarkdown fix %t',
|
||||||
|
\ 'read_temporary_file': 1,
|
||||||
|
\ },
|
||||||
|
\ ale#fixers#pymarkdown#Fix(bufnr(''))
|
||||||
|
|
||||||
|
Execute(Setting executable to 'poetry' appends 'run pymarkdown'):
|
||||||
|
let g:ale_markdown_pymarkdown_executable = 'path/to/poetry'
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ {
|
||||||
|
\ 'command': ale#Escape('path/to/poetry') . ' run pymarkdown fix %t',
|
||||||
|
\ 'read_temporary_file': 1,
|
||||||
|
\ },
|
||||||
|
\ ale#fixers#pymarkdown#Fix(bufnr(''))
|
||||||
|
|
||||||
|
Execute(Poetry is detected when markdown_pymarkdown_auto_poetry is set):
|
||||||
|
let g:ale_markdown_pymarkdown_auto_poetry = 1
|
||||||
|
call ale#test#SetFilename('../test-files/python/poetry/whatever.py')
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ {
|
||||||
|
\ 'command': ale#Escape('poetry') . ' run pymarkdown fix %t',
|
||||||
|
\ 'read_temporary_file': 1,
|
||||||
|
\ },
|
||||||
|
\ ale#fixers#pymarkdown#Fix(bufnr(''))
|
||||||
|
|
||||||
|
Execute(uv is detected when markdown_pymarkdown_auto_uv is set):
|
||||||
|
let g:ale_markdown_pymarkdown_auto_uv = 1
|
||||||
|
call ale#test#SetFilename('../test-files/python/uv/whatever.py')
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ {
|
||||||
|
\ 'command': ale#Escape('uv') . ' run pymarkdown fix %t',
|
||||||
|
\ 'read_temporary_file': 1,
|
||||||
|
\ },
|
||||||
|
\ ale#fixers#pymarkdown#Fix(bufnr(''))
|
||||||
Reference in New Issue
Block a user