Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions autoload/ale/fix/registry.vim
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,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'],
Expand Down
46 changes: 46 additions & 0 deletions autoload/ale/fixers/pymarkdown.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
scriptencoding utf-8
" Author: Adrian Vollmer <[email protected]>
" 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
14 changes: 8 additions & 6 deletions doc/ale-markdown.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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|
Expand All @@ -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|
Expand All @@ -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|
Expand All @@ -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|
Expand All @@ -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|
Expand Down
2 changes: 1 addition & 1 deletion supported-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,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/)
Expand Down
81 changes: 81 additions & 0 deletions test/fixers/test_pymarkdown_fixer_callback.vader
Original file line number Diff line number Diff line change
@@ -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(''))