Skip to content

Instantly share code, notes, and snippets.

@watagashi
Created July 9, 2018 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save watagashi/f1518b5af1895987f5aa8149f6b706da to your computer and use it in GitHub Desktop.
Save watagashi/f1518b5af1895987f5aa8149f6b706da to your computer and use it in GitHub Desktop.
diff --git a/ale_linters/markdown/remark_lint.vim b/ale_linters/markdown/remark_lint.vim
index 98dd0d7..c7fd0ab 100644
--- a/ale_linters/markdown/remark_lint.vim
+++ b/ale_linters/markdown/remark_lint.vim
@@ -1,34 +1,11 @@
" Author rhysd https://rhysd.github.io/, Dirk Roorda (dirkroorda), Adrián González Rus (@adrigzr)
" Description: remark-lint for Markdown files
-function! ale_linters#markdown#remark_lint#Handle(buffer, lines) abort
- " matches: ' 1:4 warning Incorrect list-item indent: add 1 space list-item-indent remark-lint'
- " matches: ' 18:71-19:1 error Missing new line after list item list-item-spacing remark-lint',
- let l:pattern = '^ \+\(\d\+\):\(\d\+\)\(-\(\d\+\):\(\d\+\)\)\? \(warning\|error\) \(.\+\)$'
- let l:output = []
-
- for l:match in ale#util#GetMatches(a:lines, l:pattern)
- let l:item = {
- \ 'lnum': l:match[1] + 0,
- \ 'col': l:match[2] + 0,
- \ 'type': l:match[6] is# 'error' ? 'E' : 'W',
- \ 'text': l:match[7],
- \}
- if l:match[3] isnot# ''
- let l:item.end_lnum = l:match[4] + 0
- let l:item.end_col = l:match[5] + 0
- endif
- call add(l:output, l:item)
- endfor
-
- return l:output
-endfunction
-
call ale#linter#Define('markdown', {
\ 'name': 'remark-lint',
-\ 'executable': 'remark',
-\ 'command': 'remark --no-stdout --no-color %s',
-\ 'callback': 'ale_linters#markdown#remark_lint#Handle',
+\ 'executable_callback': 'ale#handlers#remark_lint#GetExecutable',
+\ 'command_callback': 'ale#handlers#remark_lint#GetCommand',
+\ 'callback': 'ale#handlers#remark_lint#Handle',
\ 'lint_file': 1,
\ 'output_stream': 'stderr',
\})
diff --git a/autoload/ale/handlers/remark_lint.vim b/autoload/ale/handlers/remark_lint.vim
new file mode 100644
index 0000000..652205a
--- /dev/null
+++ b/autoload/ale/handlers/remark_lint.vim
@@ -0,0 +1,41 @@
+call ale#Set('remark_lint_executable', 'remark')
+call ale#Set('remark_lint_use_global', get(g:, 'ale_use_global_executables', 0))
+call ale#Set('remark_lint_options', '')
+
+function! ale#handlers#remark_lint#GetExecutable(buffer) abort
+ return ale#node#FindExecutable(a:buffer, 'remark_lint', [
+ \ 'node_modules/.bin/remark',
+ \])
+endfunction
+
+function! ale#handlers#remark_lint#GetCommand(buffer) abort
+ let l:executable = ale#handlers#remark_lint#GetExecutable(a:buffer)
+ let l:options = ale#Var(a:buffer, 'remark_lint_options')
+
+ return ale#node#Executable(a:buffer, l:executable)
+ \ . (!empty(l:options) ? ' ' . l:options : '')
+ \ . ' --no-stdout --no-color %s'
+endfunction
+
+function! ale#handlers#remark_lint#Handle(buffer, lines) abort
+ " matches: ' 1:4 warning Incorrect list-item indent: add 1 space list-item-indent remark-lint'
+ " matches: ' 18:71-19:1 error Missing new line after list item list-item-spacing remark-lint',
+ let l:pattern = '^ \+\(\d\+\):\(\d\+\)\(-\(\d\+\):\(\d\+\)\)\? \(warning\|error\) \(.\+\)$'
+ let l:output = []
+
+ for l:match in ale#util#GetMatches(a:lines, l:pattern)
+ let l:item = {
+ \ 'lnum': l:match[1] + 0,
+ \ 'col': l:match[2] + 0,
+ \ 'type': l:match[6] is# 'error' ? 'E' : 'W',
+ \ 'text': l:match[7],
+ \}
+ if l:match[3] isnot# ''
+ let l:item.end_lnum = l:match[4] + 0
+ let l:item.end_col = l:match[5] + 0
+ endif
+ call add(l:output, l:item)
+ endfor
+
+ return l:output
+endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment