summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ale_linters/asciidoc/alex.vim9
-rw-r--r--ale_linters/help/alex.vim9
-rw-r--r--ale_linters/html/alex.vim9
-rw-r--r--ale_linters/mail/alex.vim11
-rw-r--r--ale_linters/markdown/alex.vim9
-rw-r--r--ale_linters/nroff/alex.vim9
-rw-r--r--ale_linters/po/alex.vim9
-rw-r--r--ale_linters/pod/alex.vim9
-rw-r--r--ale_linters/rst/alex.vim9
-rw-r--r--ale_linters/tex/alex.vim9
-rw-r--r--ale_linters/texinfo/alex.vim9
-rw-r--r--ale_linters/text/alex.vim9
-rw-r--r--ale_linters/xhtml/alex.vim9
-rw-r--r--autoload/ale/handlers/alex.vim33
-rw-r--r--doc/ale.txt27
-rw-r--r--test/command_callback/alex-node-modules-2/node_modules/alex/cli.js0
-rw-r--r--test/command_callback/alex-node-modules/node_modules/.bin/alex0
-rw-r--r--test/command_callback/test_alex_command_callback.vader34
18 files changed, 105 insertions, 108 deletions
diff --git a/ale_linters/asciidoc/alex.vim b/ale_linters/asciidoc/alex.vim
index 79b04fc3..97976b2c 100644
--- a/ale_linters/asciidoc/alex.vim
+++ b/ale_linters/asciidoc/alex.vim
@@ -1,11 +1,4 @@
" Author: Johannes Wienke <languitar@semipol.de>
" Description: alex for asciidoc files
-call ale#linter#Define('help', {
-\ 'name': 'alex',
-\ 'executable': 'alex',
-\ 'command': 'alex %s -t',
-\ 'output_stream': 'stderr',
-\ 'callback': 'ale#handlers#alex#Handle',
-\ 'lint_file': 1,
-\})
+call ale#handlers#alex#DefineLinter('asciidoc', '--text')
diff --git a/ale_linters/help/alex.vim b/ale_linters/help/alex.vim
index 21b23b4f..9be00a82 100644
--- a/ale_linters/help/alex.vim
+++ b/ale_linters/help/alex.vim
@@ -1,11 +1,4 @@
" Author: Johannes Wienke <languitar@semipol.de>
" Description: alex for help files
-call ale#linter#Define('help', {
-\ 'name': 'alex',
-\ 'executable': 'alex',
-\ 'command': 'alex %s -t',
-\ 'output_stream': 'stderr',
-\ 'callback': 'ale#handlers#alex#Handle',
-\ 'lint_file': 1,
-\})
+call ale#handlers#alex#DefineLinter('help', '--text')
diff --git a/ale_linters/html/alex.vim b/ale_linters/html/alex.vim
index 5a1f61e9..97756753 100644
--- a/ale_linters/html/alex.vim
+++ b/ale_linters/html/alex.vim
@@ -1,11 +1,4 @@
" Author: Johannes Wienke <languitar@semipol.de>
" Description: alex for HTML files
-call ale#linter#Define('html', {
-\ 'name': 'alex',
-\ 'executable': 'alex',
-\ 'command': 'alex %s -t',
-\ 'output_stream': 'stderr',
-\ 'callback': 'ale#handlers#alex#Handle',
-\ 'lint_file': 1,
-\})
+call ale#handlers#alex#DefineLinter('html', '--html')
diff --git a/ale_linters/mail/alex.vim b/ale_linters/mail/alex.vim
index b0651ccd..0fceea7b 100644
--- a/ale_linters/mail/alex.vim
+++ b/ale_linters/mail/alex.vim
@@ -1,11 +1,4 @@
" Author: Johannes Wienke <languitar@semipol.de>
-" Description: alex for HTML files
+" Description: alex for mail files
-call ale#linter#Define('mail', {
-\ 'name': 'alex',
-\ 'executable': 'alex',
-\ 'command': 'alex %s -t',
-\ 'output_stream': 'stderr',
-\ 'callback': 'ale#handlers#alex#Handle',
-\ 'lint_file': 1,
-\})
+call ale#handlers#alex#DefineLinter('mail', '--text')
diff --git a/ale_linters/markdown/alex.vim b/ale_linters/markdown/alex.vim
index 29306141..63769b5e 100644
--- a/ale_linters/markdown/alex.vim
+++ b/ale_linters/markdown/alex.vim
@@ -1,11 +1,4 @@
" Author: Johannes Wienke <languitar@semipol.de>
" Description: alex for markdown files
-call ale#linter#Define('markdown', {
-\ 'name': 'alex',
-\ 'executable': 'alex',
-\ 'command': 'alex %s -t',
-\ 'output_stream': 'stderr',
-\ 'callback': 'ale#handlers#alex#Handle',
-\ 'lint_file': 1,
-\})
+call ale#handlers#alex#DefineLinter('markdown', '')
diff --git a/ale_linters/nroff/alex.vim b/ale_linters/nroff/alex.vim
index a10db2dd..3f06af26 100644
--- a/ale_linters/nroff/alex.vim
+++ b/ale_linters/nroff/alex.vim
@@ -1,11 +1,4 @@
" Author: Johannes Wienke <languitar@semipol.de>
" Description: alex for nroff files
-call ale#linter#Define('nroff', {
-\ 'name': 'alex',
-\ 'executable': 'alex',
-\ 'command': 'alex %s -t',
-\ 'output_stream': 'stderr',
-\ 'callback': 'ale#handlers#alex#Handle',
-\ 'lint_file': 1,
-\})
+call ale#handlers#alex#DefineLinter('nroff', '--text')
diff --git a/ale_linters/po/alex.vim b/ale_linters/po/alex.vim
index 411d835b..05c67f15 100644
--- a/ale_linters/po/alex.vim
+++ b/ale_linters/po/alex.vim
@@ -1,11 +1,4 @@
" Author: Cian Butler https://github.com/butlerx
" Description: alex for PO files
-call ale#linter#Define('po', {
-\ 'name': 'alex',
-\ 'executable': 'alex',
-\ 'command': 'alex %s -t',
-\ 'output_stream': 'stderr',
-\ 'callback': 'ale#handlers#alex#Handle',
-\ 'lint_file': 1,
-\})
+call ale#handlers#alex#DefineLinter('po', '--text')
diff --git a/ale_linters/pod/alex.vim b/ale_linters/pod/alex.vim
index 5c09befb..c89f8330 100644
--- a/ale_linters/pod/alex.vim
+++ b/ale_linters/pod/alex.vim
@@ -1,11 +1,4 @@
" Author: Johannes Wienke <languitar@semipol.de>
" Description: alex for pod files
-call ale#linter#Define('pod', {
-\ 'name': 'alex',
-\ 'executable': 'alex',
-\ 'command': 'alex %s -t',
-\ 'output_stream': 'stderr',
-\ 'callback': 'ale#handlers#alex#Handle',
-\ 'lint_file': 1,
-\})
+call ale#handlers#alex#DefineLinter('pod', '--text')
diff --git a/ale_linters/rst/alex.vim b/ale_linters/rst/alex.vim
index e637eae7..e7ca6fa0 100644
--- a/ale_linters/rst/alex.vim
+++ b/ale_linters/rst/alex.vim
@@ -1,11 +1,4 @@
" Author: Johannes Wienke <languitar@semipol.de>
" Description: alex for rst files
-call ale#linter#Define('rst', {
-\ 'name': 'alex',
-\ 'executable': 'alex',
-\ 'command': 'alex %s -t',
-\ 'output_stream': 'stderr',
-\ 'callback': 'ale#handlers#alex#Handle',
-\ 'lint_file': 1,
-\})
+call ale#handlers#alex#DefineLinter('rst', '--text')
diff --git a/ale_linters/tex/alex.vim b/ale_linters/tex/alex.vim
index 78c530f7..5d9aec66 100644
--- a/ale_linters/tex/alex.vim
+++ b/ale_linters/tex/alex.vim
@@ -1,11 +1,4 @@
" Author: Johannes Wienke <languitar@semipol.de>
" Description: alex for TeX files
-call ale#linter#Define('tex', {
-\ 'name': 'alex',
-\ 'executable': 'alex',
-\ 'command': 'alex %s -t',
-\ 'output_stream': 'stderr',
-\ 'callback': 'ale#handlers#alex#Handle',
-\ 'lint_file': 1,
-\})
+call ale#handlers#alex#DefineLinter('tex', '--text')
diff --git a/ale_linters/texinfo/alex.vim b/ale_linters/texinfo/alex.vim
index 4a884579..4d245524 100644
--- a/ale_linters/texinfo/alex.vim
+++ b/ale_linters/texinfo/alex.vim
@@ -1,11 +1,4 @@
" Author: Johannes Wienke <languitar@semipol.de>
" Description: alex for texinfo files
-call ale#linter#Define('texinfo', {
-\ 'name': 'alex',
-\ 'executable': 'alex',
-\ 'command': 'alex %s -t',
-\ 'output_stream': 'stderr',
-\ 'callback': 'ale#handlers#alex#Handle',
-\ 'lint_file': 1,
-\})
+call ale#handlers#alex#DefineLinter('texinfo', '--text')
diff --git a/ale_linters/text/alex.vim b/ale_linters/text/alex.vim
index c696367b..d87ed915 100644
--- a/ale_linters/text/alex.vim
+++ b/ale_linters/text/alex.vim
@@ -1,11 +1,4 @@
" Author: Johannes Wienke <languitar@semipol.de>
" Description: alex for text files
-call ale#linter#Define('text', {
-\ 'name': 'alex',
-\ 'executable': 'alex',
-\ 'command': 'alex %s -t',
-\ 'output_stream': 'stderr',
-\ 'callback': 'ale#handlers#alex#Handle',
-\ 'lint_file': 1,
-\})
+call ale#handlers#alex#DefineLinter('text', '--text')
diff --git a/ale_linters/xhtml/alex.vim b/ale_linters/xhtml/alex.vim
index 60a9a7c9..97f3b59a 100644
--- a/ale_linters/xhtml/alex.vim
+++ b/ale_linters/xhtml/alex.vim
@@ -1,11 +1,4 @@
" Author: Johannes Wienke <languitar@semipol.de>
" Description: alex for XHTML files
-call ale#linter#Define('xhtml', {
-\ 'name': 'alex',
-\ 'executable': 'alex',
-\ 'command': 'alex %s -t',
-\ 'output_stream': 'stderr',
-\ 'callback': 'ale#handlers#alex#Handle',
-\ 'lint_file': 1,
-\})
+call ale#handlers#alex#DefineLinter('xhtml', '--text')
diff --git a/autoload/ale/handlers/alex.vim b/autoload/ale/handlers/alex.vim
index 853d3137..9cb546ec 100644
--- a/autoload/ale/handlers/alex.vim
+++ b/autoload/ale/handlers/alex.vim
@@ -1,10 +1,23 @@
" Author: Johannes Wienke <languitar@semipol.de>
" Description: Error handling for errors in alex output format
+function! ale#handlers#alex#GetExecutable(buffer) abort
+ return ale#node#FindExecutable(a:buffer, 'alex', [
+ \ 'node_modules/.bin/alex',
+ \ 'node_modules/alex/cli.js',
+ \])
+endfunction
+
+function! ale#handlers#alex#CreateCommandCallback(flags) abort
+ return {b -> ale#node#Executable(b, ale#handlers#alex#GetExecutable(b))
+ \ . ' %s '
+ \ . a:flags}
+endfunction
+
function! ale#handlers#alex#Handle(buffer, lines) abort
" Example output:
" 6:256-6:262 warning Be careful with “killed”, it’s profane in some cases killed retext-profanities
- let l:pattern = '^ *\(\d\+\):\(\d\+\)-\(\d\+\):\(\d\+\) \+warning \+\(.\{-\}\) \+\(.\{-\}\) \+\(.\{-\}\)$'
+ let l:pattern = '\v^ *(\d+):(\d+)-(\d+):(\d+) +warning +(.{-}) +(.{-}) +(.{-})$'
let l:output = []
for l:match in ale#util#GetMatches(a:lines, l:pattern)
@@ -20,3 +33,21 @@ function! ale#handlers#alex#Handle(buffer, lines) abort
return l:output
endfunction
+
+" Define a linter for a specific filetype. Accept flags to adapt to the filetype.
+" no flags treat input as markdown
+" --html treat input as HTML
+" --text treat input as plaintext
+function! ale#handlers#alex#DefineLinter(filetype, flags) abort
+ call ale#Set('alex_executable', 'alex')
+ call ale#Set('alex_use_global', get(g:, 'ale_use_global_executables', 0))
+
+ call ale#linter#Define(a:filetype, {
+ \ 'name': 'alex',
+ \ 'executable_callback': 'ale#handlers#alex#GetExecutable',
+ \ 'command_callback': ale#handlers#alex#CreateCommandCallback(a:flags),
+ \ 'output_stream': 'stderr',
+ \ 'callback': 'ale#handlers#alex#Handle',
+ \ 'lint_file': 1,
+ \})
+endfunction
diff --git a/doc/ale.txt b/doc/ale.txt
index 006928ef..0ca64af9 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -20,7 +20,8 @@ CONTENTS *ale-contents*
5.6 Symbol Search.....................|ale-symbol-search|
6. Global Options.......................|ale-options|
6.1 Highlights........................|ale-highlights|
- 6.2 Options for write-good Linter.....|ale-write-good-options|
+ 6.2 Options for alex Linter...........|ale-alex-options|
+ 6.3 Options for write-good Linter.....|ale-write-good-options|
7. Integration Documentation............|ale-integrations|
ada...................................|ale-ada-options|
gcc.................................|ale-ada-gcc|
@@ -2219,7 +2220,29 @@ ALEWarningSign *ALEWarningSign*
-------------------------------------------------------------------------------
-6.2. Options for write-good *ale-write-good-options*
+6.2. Options for alex *ale-alex-options*
+
+The options for the alex linter are global because it does not make sense to
+have them specified on a per-language basis.
+
+g:ale_alex_executable *g:ale_alex_executable*
+ *b:ale_alex_executable*
+ Type: |String|
+ Default: `'alex'`
+
+ See |ale-integrations-local-executables|
+
+
+g:ale_alex_use_global *g:ale_alex_use_global*
+ *b:ale_alex_use_global*
+ Type: |Number|
+ Default: `get(g:, 'ale_use_global_executables', 0)`
+
+ See |ale-integrations-local-executables|
+
+
+-------------------------------------------------------------------------------
+6.3. Options for write-good *ale-write-good-options*
The options for the write-good linter are global because it does not make
sense to have them specified on a per-language basis.
diff --git a/test/command_callback/alex-node-modules-2/node_modules/alex/cli.js b/test/command_callback/alex-node-modules-2/node_modules/alex/cli.js
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/command_callback/alex-node-modules-2/node_modules/alex/cli.js
diff --git a/test/command_callback/alex-node-modules/node_modules/.bin/alex b/test/command_callback/alex-node-modules/node_modules/.bin/alex
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/command_callback/alex-node-modules/node_modules/.bin/alex
diff --git a/test/command_callback/test_alex_command_callback.vader b/test/command_callback/test_alex_command_callback.vader
new file mode 100644
index 00000000..98769e0b
--- /dev/null
+++ b/test/command_callback/test_alex_command_callback.vader
@@ -0,0 +1,34 @@
+Before:
+ call ale#assert#SetUpLinterTest('tex', 'alex')
+ call ale#test#SetFilename('test_file.tex')
+
+After:
+ call ale#assert#TearDownLinterTest()
+
+Execute(The global executable should be used when the local one cannot be found):
+ AssertLinter 'alex',
+ \ ale#Escape('alex') . ' %s --text',
+
+Execute(Should use the node_modules/.bin executable, if available):
+ call ale#test#SetFilename('alex-node-modules/test_file.tex')
+
+ AssertLinter ale#path#Simplify(g:dir . '/alex-node-modules/node_modules/.bin/alex'),
+ \ ale#Escape(ale#path#Simplify(g:dir . '/alex-node-modules/node_modules/.bin/alex'))
+ \ . ' %s --text',
+
+Execute(Should use the node_modules/alex executable, if available):
+ call ale#test#SetFilename('alex-node-modules-2/test_file.tex')
+
+ AssertLinter ale#path#Simplify(g:dir . '/alex-node-modules-2/node_modules/alex/cli.js'),
+ \ (has('win32') ? 'node.exe ' : '')
+ \ . ale#Escape(ale#path#Simplify(g:dir . '/alex-node-modules-2/node_modules/alex/cli.js'))
+ \ . ' %s --text',
+
+Execute(Should let users configure a global executable and override local paths):
+ call ale#test#SetFilename('write-good-node-modules-2/test_file.tex')
+
+ let g:ale_alex_executable = '/path/to/custom/alex'
+ let g:ale_alex_use_global = 1
+
+ AssertLinter '/path/to/custom/alex',
+ \ ale#Escape('/path/to/custom/alex') . ' %s --text'