]> git.madduck.net Git - etc/vim.git/blob - ale_linters/markdown/pymarkdown.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / ale_linters / markdown / pymarkdown.vim
1
2 call ale#Set('markdown_pymarkdown_executable', 'pymarkdown')
3 call ale#Set('markdown_pymarkdown_options', '')
4 call ale#Set('markdown_pymarkdown_use_global', get(g:, 'ale_use_global_executables', 0))
5 call ale#Set('markdown_pymarkdown_auto_pipenv', 0)
6 call ale#Set('markdown_pymarkdown_auto_poetry', 0)
7 call ale#Set('markdown_pymarkdown_auto_uv', 0)
8
9 function! ale_linters#markdown#pymarkdown#GetExecutable(buffer) abort
10     if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'markdown_pymarkdown_auto_pipenv'))
11     \ && ale#python#PipenvPresent(a:buffer)
12         return 'pipenv'
13     endif
14
15     if (ale#Var(a:buffer, 'python_auto_poetry') || ale#Var(a:buffer, 'markdown_pymarkdown_auto_poetry'))
16     \ && ale#python#PoetryPresent(a:buffer)
17         return 'poetry'
18     endif
19
20     if (ale#Var(a:buffer, 'python_auto_uv') || ale#Var(a:buffer, 'markdown_pymarkdown_auto_uv'))
21     \ && ale#python#UvPresent(a:buffer)
22         return 'uv'
23     endif
24
25     return ale#python#FindExecutable(a:buffer, 'markdown_pymarkdown', ['pymarkdown'])
26 endfunction
27
28 function! ale_linters#markdown#pymarkdown#GetCommand(buffer) abort
29     let l:executable = ale_linters#markdown#pymarkdown#GetExecutable(a:buffer)
30
31     let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
32     \   ? ' run pymarkdown'
33     \   : ''
34
35     return ale#Escape(l:executable) . l:exec_args
36     \   . ' '
37     \   . ale#Var(a:buffer, 'markdown_pymarkdown_options')
38     \   . 'scan-stdin'
39 endfunction
40
41 function! ale_linters#markdown#pymarkdown#Handle(buffer, lines) abort
42     let l:pattern = '\v^(\S*):(\d+):(\d+): ([A-Z]+\d+): (.*)$'
43     let l:output = []
44     " lines are formatted as follows:
45     " sample.md:1:1: MD022: Headings should be surrounded by blank lines. [Expected: 1; Actual: 0; Below] (blanks-around-headings,blanks-around-headers)
46
47     for l:match in ale#util#GetMatches(a:lines, l:pattern)
48         if(l:match[4] is# 'MD009')
49         \&& !ale#Var(a:buffer, 'warn_about_trailing_whitespace')
50             " Skip warnings for trailing whitespace if the option is off.
51             continue
52         endif
53
54         let l:item = {
55         \   'lnum': l:match[2] + 0,
56         \   'col': l:match[3] + 0,
57         \   'type': l:match[4][0],
58         \   'text': l:match[5],
59         \   'code': l:match[4],
60         \}
61
62         call add(l:output, l:item)
63     endfor
64
65     return l:output
66 endfunction
67
68 call ale#linter#Define('markdown', {
69 \   'name': 'pymarkdown',
70 \   'executable': function('ale_linters#markdown#pymarkdown#GetExecutable'),
71 \   'command': function('ale_linters#markdown#pymarkdown#GetCommand'),
72 \   'callback': 'ale_linters#markdown#pymarkdown#Handle',
73 \})