Skip to content

Commit c59c0d1

Browse files
authored
feat(markdown): add rumdl server and fixer (dense-analysis#5115)
* feat: put in the main linter files * feat: add to registry * docs: add rumdl to docs * tests: vader tests * edit: actually split the options into two * style: make rumdl fixer test mimic markdownlint * fix: stupidity overwhelming * fix: actually let's look for pyproject too copied from tombi * i'm a buffoon fix wrong indentation * alignment ci is made for people like me * missed toc entry
1 parent 051d12c commit c59c0d1

9 files changed

Lines changed: 150 additions & 0 deletions

File tree

ale_linters/markdown/rumdl.vim

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
" Author: Evan Chen <evan@evanchen.cc>
2+
" Description: Fast Markdown linter and formatter written in Rust
3+
4+
5+
call ale#Set('markdown_rumdl_executable', 'rumdl')
6+
call ale#Set('markdown_rumdl_options', '')
7+
8+
function! ale_linters#markdown#rumdl#GetProjectRoot(buffer) abort
9+
let l:dotconfig = ale#path#FindNearestFile(a:buffer, '.rumdl.toml')
10+
let l:config = ale#path#FindNearestFile(a:buffer, 'rumdl.toml')
11+
12+
if !empty(l:dotconfig) && !empty(l:config)
13+
let l:nearest = len(l:dotconfig) >= len(l:config) ? l:dotconfig : l:config
14+
15+
return fnamemodify(l:nearest, ':h')
16+
elseif !empty(l:dotconfig)
17+
return fnamemodify(l:dotconfig, ':h')
18+
elseif !empty(l:config)
19+
return fnamemodify(l:config, ':h')
20+
endif
21+
22+
" Try to find nearest pyproject.toml
23+
let l:pyproject_file = ale#path#FindNearestFile(a:buffer, 'pyproject.toml')
24+
25+
if !empty(l:pyproject_file)
26+
return fnamemodify(l:pyproject_file . '/', ':p:h:h')
27+
endif
28+
29+
" Try to find nearest `git` directory
30+
let l:gitdir = ale#path#FindNearestFile(a:buffer, '.git')
31+
32+
if !empty(l:gitdir)
33+
return fnamemodify(l:gitdir . '/', ':p:h:h')
34+
endif
35+
36+
return fnamemodify(bufname(a:buffer), ':p:h')
37+
endfunction
38+
39+
call ale#linter#Define('markdown', {
40+
\ 'name': 'rumdl',
41+
\ 'lsp': 'stdio',
42+
\ 'executable': {b -> ale#Var(b, 'markdown_rumdl_executable')},
43+
\ 'command': {b -> ale#Escape(ale#Var(b, 'markdown_rumdl_executable'))
44+
\ . ' server --stdio'
45+
\ . ale#Pad(ale#Var(b, 'markdown_rumdl_options'))},
46+
\ 'project_root': function('ale_linters#markdown#rumdl#GetProjectRoot'),
47+
\ 'language': 'markdown',
48+
\})

autoload/ale/fix/registry.vim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,11 @@ let s:default_registry = {
767767
\ 'suggested_filetypes': ['markdown'],
768768
\ 'description': 'Fix markdown files with markdownlint.',
769769
\ },
770+
\ 'rumdl': {
771+
\ 'function': 'ale#fixers#rumdl#Fix',
772+
\ 'suggested_filetypes': ['markdown'],
773+
\ 'description': 'Fix markdown files with rumdl.',
774+
\ },
770775
\}
771776

772777
" Reset the function registry to the default entries.

autoload/ale/fixers/rumdl.vim

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
scriptencoding utf-8
2+
3+
" Author: Evan Chen <evan@evanchen.cc>
4+
" Description: Fast Markdown linter and formatter written in Rust
5+
6+
7+
call ale#Set('markdown_rumdl_executable', 'rumdl')
8+
call ale#Set('markdown_rumdl_fmt_options', '--silent')
9+
10+
function! ale#fixers#rumdl#Fix(buffer) abort
11+
let l:executable = ale#Var(a:buffer, 'markdown_rumdl_executable')
12+
let l:options = ale#Var(a:buffer, 'markdown_rumdl_fmt_options')
13+
14+
return {
15+
\ 'command': ale#Escape(l:executable) . ' fmt -'
16+
\ . ale#Pad(l:options),
17+
\}
18+
endfunction

doc/ale-markdown.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,40 @@ g:ale_markdown_remark_lint_use_global
244244
See |ale-integrations-local-executables|
245245

246246

247+
===============================================================================
248+
rumdl *ale-markdown-rumdl*
249+
250+
*ale-options.markdown_rumdl_executable*
251+
*g:ale_markdown_rumdl_executable*
252+
*b:ale_markdown_rumdl_executable*
253+
markdown_rumdl_executable
254+
g:ale_markdown_rumdl_executable
255+
Type: |String|
256+
Default: `'rumdl'`
257+
258+
Override the invoked `rumdl` binary.
259+
260+
*ale-options.markdown_rumdl_options*
261+
*g:ale_markdown_rumdl_options*
262+
*b:ale_markdown_rumdl_options*
263+
markdown_rumdl_options
264+
g:ale_markdown_rumdl_options
265+
Type: |String|
266+
Default: `''`
267+
268+
This variable can be set to pass additional options to `rumdl server`.
269+
270+
*ale-options.markdown_rumdl_fmt_options*
271+
*g:ale_markdown_rumdl_fmt_options*
272+
*b:ale_markdown_rumdl_fmt_options*
273+
markdown_rumdl_fmt_options
274+
g:ale_markdown_rumdl_fmt_options
275+
Type: |String|
276+
Default: `'--silent'`
277+
278+
This variable can be set to pass additional options to `rumdl fmt`.
279+
280+
247281
===============================================================================
248282
textlint *ale-markdown-textlint*
249283

doc/ale-supported-languages-and-tools.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ Notes:
417417
* `pymarkdown`
418418
* `redpen`
419419
* `remark-lint`
420+
* `rumdl`
420421
* `textlint`
421422
* `vale`
422423
* `write-good`

doc/ale.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3748,6 +3748,7 @@ documented in additional help files.
37483748
prettier..............................|ale-markdown-prettier|
37493749
pymarkdown............................|ale-markdown-pymarkdown|
37503750
remark-lint...........................|ale-markdown-remark-lint|
3751+
rumdl.................................|ale-markdown-rumdl|
37513752
textlint..............................|ale-markdown-textlint|
37523753
write-good............................|ale-markdown-write-good|
37533754
redpen................................|ale-markdown-redpen|

supported-tools.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ formatting.
427427
* [pymarkdown](https://github.com/jackdewinter/pymarkdown) :floppy_disk:
428428
* [redpen](http://redpen.cc/)
429429
* [remark-lint](https://github.com/wooorm/remark-lint)
430+
* [rumdl](https://github.com/rvben/rumdl/issues) :speech_balloon:
430431
* [textlint](https://textlint.github.io/)
431432
* [vale](https://github.com/ValeLint/vale)
432433
* [write-good](https://github.com/btford/write-good)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Before:
2+
call ale#assert#SetUpFixerTest('markdown', 'rumdl')
3+
4+
After:
5+
call ale#assert#TearDownFixerTest()
6+
7+
Execute:
8+
AssertFixer {
9+
\ 'command': ale#Escape('rumdl') . ' fmt - --silent',
10+
\}
11+
12+
Execute:
13+
let g:ale_markdown_rumdl_executable = 'rumdl_custom'
14+
15+
AssertFixer {
16+
\ 'command': ale#Escape('rumdl_custom') . ' fmt - --silent',
17+
\}
18+
19+
Execute:
20+
let g:ale_markdown_rumdl_fmt_options = ''
21+
22+
AssertFixer {
23+
\ 'command': ale#Escape('rumdl') . ' fmt -',
24+
\}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Before:
2+
call ale#assert#SetUpLinterTest('markdown', 'rumdl')
3+
4+
After:
5+
call ale#assert#TearDownLinterTest()
6+
7+
Execute(The default command should be correct):
8+
AssertLinter 'rumdl', ale#Escape('rumdl') . ' server --stdio'
9+
10+
Execute(The executable should be configurable):
11+
let b:ale_markdown_rumdl_executable = 'rumdl_custom'
12+
13+
AssertLinter 'rumdl_custom', ale#Escape('rumdl_custom') . ' server --stdio'
14+
15+
Execute(The server options should be configurable):
16+
let b:ale_markdown_rumdl_options = '--some-flag'
17+
18+
AssertLinter 'rumdl', ale#Escape('rumdl') . ' server --stdio --some-flag'

0 commit comments

Comments
 (0)