mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-22 12:01:25 +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'],
|
||||
\ 'description': 'Fix markdown files with pandoc.',
|
||||
\ },
|
||||
\ 'pymarkdown': {
|
||||
\ 'function': 'ale#fixers#pymarkdown#Fix',
|
||||
\ 'suggested_filetypes': ['markdown'],
|
||||
\ 'description': 'Fix markdown files with pymarkdown.',
|
||||
\ },
|
||||
\ 'shfmt': {
|
||||
\ 'function': 'ale#fixers#shfmt#Fix',
|
||||
\ '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,9 +111,11 @@ See |ale-javascript-prettier| for information about the available options.
|
||||
===============================================================================
|
||||
pymarkdown *ale-markdown-pymarkdown*
|
||||
|
||||
pymarkdown can be used both as a linter and a fixer for Markdown files.
|
||||
|
||||
*ale-options.markdown_pymarkdown_executable*
|
||||
*g:ale_markdown_pymarkdown_executable*
|
||||
*b:ale_markdown_pymarkdown_executable*
|
||||
*b:ale_markdown_pymarkdown_executable*
|
||||
markdown_pymarkdown_executable
|
||||
g:ale_markdown_pymarkdown_executable
|
||||
Type: |String|
|
||||
@@ -126,7 +128,7 @@ g:ale_markdown_pymarkdown_executable
|
||||
|
||||
*ale-options.markdown_pymarkdown_options*
|
||||
*g:ale_markdown_pymarkdown_options*
|
||||
*b:ale_markdown_pymarkdown_options*
|
||||
*b:ale_markdown_pymarkdown_options*
|
||||
markdown_pymarkdown_options
|
||||
g:ale_markdown_pymarkdown_options
|
||||
Type: |String|
|
||||
@@ -137,7 +139,7 @@ g:ale_markdown_pymarkdown_options
|
||||
|
||||
*ale-options.markdown_pymarkdown_use_global*
|
||||
*g:ale_markdown_pymarkdown_use_global*
|
||||
*b:ale_markdown_pymarkdown_use_global*
|
||||
*b:ale_markdown_pymarkdown_use_global*
|
||||
markdown_pymarkdown_use_global
|
||||
g:ale_markdown_pymarkdown_use_global
|
||||
Type: |Number|
|
||||
@@ -147,7 +149,7 @@ g:ale_markdown_pymarkdown_use_global
|
||||
|
||||
*ale-options.markdown_pymarkdown_auto_pipenv*
|
||||
*g:ale_markdown_pymarkdown_auto_pipenv*
|
||||
*b:ale_markdown_pymarkdown_auto_pipenv*
|
||||
*b:ale_markdown_pymarkdown_auto_pipenv*
|
||||
markdown_pymarkdown_auto_pipenv
|
||||
g:ale_markdown_pymarkdown_auto_pipenv
|
||||
Type: |Number|
|
||||
@@ -158,7 +160,7 @@ g:ale_markdown_pymarkdown_auto_pipenv
|
||||
|
||||
*ale-options.markdown_pymarkdown_auto_poetry*
|
||||
*g:ale_markdown_pymarkdown_auto_poetry*
|
||||
*b:ale_markdown_pymarkdown_auto_poetry*
|
||||
*b:ale_markdown_pymarkdown_auto_poetry*
|
||||
markdown_pymarkdown_auto_poetry
|
||||
g:ale_markdown_pymarkdown_auto_poetry
|
||||
Type: |Number|
|
||||
@@ -169,7 +171,7 @@ g:ale_markdown_pymarkdown_auto_poetry
|
||||
|
||||
*ale-options.markdown_pymarkdown_auto_uv*
|
||||
*g:ale_markdown_pymarkdown_auto_uv*
|
||||
*b:ale_markdown_pymarkdown_auto_uv*
|
||||
*b:ale_markdown_pymarkdown_auto_uv*
|
||||
markdown_pymarkdown_auto_uv
|
||||
g:ale_markdown_pymarkdown_auto_uv
|
||||
Type: |Number|
|
||||
|
||||
@@ -421,7 +421,7 @@ formatting.
|
||||
* [pandoc](https://pandoc.org)
|
||||
* [prettier](https://github.com/prettier/prettier)
|
||||
* [proselint](http://proselint.com/)
|
||||
* [pymarkdown](https://github.com/jackdewinter/pymarkdown)
|
||||
* [pymarkdown](https://github.com/jackdewinter/pymarkdown) :floppy_disk:
|
||||
* [redpen](http://redpen.cc/)
|
||||
* [remark-lint](https://github.com/wooorm/remark-lint)
|
||||
* [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