summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorblyoa <blyoa@users.noreply.github.com>2020-08-17 18:14:38 +0900
committerGitHub <noreply@github.com>2020-08-17 10:14:38 +0100
commitd5c1d842307a4c916905d5160544cfe152a16ee0 (patch)
tree85bc13692b7dadda74d54c9a409043ddc16d3a5a
parent5c778e1ae752163a849609318ace6c3c6a37d6f7 (diff)
downloadale-d5c1d842307a4c916905d5160544cfe152a16ee0.zip
Add remark-lint for a markdown fixer (#2836)
-rw-r--r--autoload/ale/fix/registry.vim5
-rw-r--r--autoload/ale/fixers/remark_lint.vim24
-rw-r--r--test/fixers/test_remark_lint_fixer_callback.vader24
3 files changed, 53 insertions, 0 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index 02b02699..94476ca9 100644
--- a/autoload/ale/fix/registry.vim
+++ b/autoload/ale/fix/registry.vim
@@ -365,6 +365,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['nix'],
\ 'description': 'A formatter for Nix code',
\ },
+\ 'remark-lint': {
+\ 'function': 'ale#fixers#remark_lint#Fix',
+\ 'suggested_filetypes': ['markdown'],
+\ 'description': 'Fix markdown files with remark-lint',
+\ },
\ 'html-beautify': {
\ 'function': 'ale#fixers#html_beautify#Fix',
\ 'suggested_filetypes': ['html', 'htmldjango'],
diff --git a/autoload/ale/fixers/remark_lint.vim b/autoload/ale/fixers/remark_lint.vim
new file mode 100644
index 00000000..3ce442f3
--- /dev/null
+++ b/autoload/ale/fixers/remark_lint.vim
@@ -0,0 +1,24 @@
+" Author: blyoa <blyoa110@gmail.com>
+" Description: Fixing files with remark-lint.
+
+call ale#Set('markdown_remark_lint_executable', 'remark')
+call ale#Set('markdown_remark_lint_use_global', get(g:, 'ale_use_global_executables', 0))
+call ale#Set('markdown_remark_lint_options', '')
+
+function! ale#fixers#remark_lint#GetExecutable(buffer) abort
+ return ale#node#FindExecutable(a:buffer, 'markdown_remark_lint', [
+ \ 'node_modules/remark-cli/cli.js',
+ \ 'node_modules/.bin/remark',
+ \])
+endfunction
+
+function! ale#fixers#remark_lint#Fix(buffer) abort
+ let l:executable = ale#fixers#remark_lint#GetExecutable(a:buffer)
+ let l:options = ale#Var(a:buffer, 'markdown_remark_lint_options')
+
+ return {
+ \ 'command': ale#Escape(l:executable)
+ \ . (!empty(l:options) ? ' ' . l:options : ''),
+ \}
+endfunction
+
diff --git a/test/fixers/test_remark_lint_fixer_callback.vader b/test/fixers/test_remark_lint_fixer_callback.vader
new file mode 100644
index 00000000..5e2e342d
--- /dev/null
+++ b/test/fixers/test_remark_lint_fixer_callback.vader
@@ -0,0 +1,24 @@
+Before:
+ Save g:ale_markdown_remark_lint_executable
+ Save g:ale_markdown_remark_lint_options
+
+After:
+ Restore
+
+Execute(The remark callback should return the correct default values):
+ AssertEqual
+ \ {
+ \ 'command': ale#Escape('remark')
+ \ },
+ \ ale#fixers#remark_lint#Fix(bufnr(''))
+
+Execute(The remark executable and options should be configurable):
+ let g:ale_markdown_remark_lint_executable = '/path/to/remark'
+ let g:ale_markdown_remark_lint_options = '-h'
+
+ AssertEqual
+ \ {
+ \ 'command': ale#Escape('/path/to/remark')
+ \ . ' -h',
+ \ },
+ \ ale#fixers#remark_lint#Fix(bufnr(''))