summaryrefslogtreecommitdiff
path: root/ale_linters
diff options
context:
space:
mode:
authorBartek thindil Jasicki <thindil@laeran.pl>2021-01-22 17:52:01 +0100
committerBartek thindil Jasicki <thindil@laeran.pl>2021-01-22 17:52:01 +0100
commit1ca780a08ad28a2c8264ec9292e9fbbf96930e06 (patch)
tree0240bd1da22673dfb21c885bf2852fbffd7540c5 /ale_linters
parent42bf5ca91110bac565d76263bd5d21ebb9b142a9 (diff)
parent1b010bbabb5b28cc2746ca967941ffdc9240960e (diff)
downloadale-1ca780a08ad28a2c8264ec9292e9fbbf96930e06.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'ale_linters')
-rw-r--r--ale_linters/dart/analysis_server.vim29
-rw-r--r--ale_linters/javascript/xo.vim23
-rw-r--r--ale_linters/openapi/ibm_validator.vim58
-rw-r--r--ale_linters/openapi/yamllint.vim9
-rw-r--r--ale_linters/typescript/xo.vim23
-rw-r--r--ale_linters/vala/vala_lint.vim66
-rw-r--r--ale_linters/yaml/yamllint.vim43
7 files changed, 170 insertions, 81 deletions
diff --git a/ale_linters/dart/analysis_server.vim b/ale_linters/dart/analysis_server.vim
new file mode 100644
index 00000000..a6870da9
--- /dev/null
+++ b/ale_linters/dart/analysis_server.vim
@@ -0,0 +1,29 @@
+" Author: Nelson Yeung <nelsyeung@gmail.com>
+" Description: Check Dart files with dart analysis server LSP
+
+call ale#Set('dart_analysis_server_executable', 'dart')
+
+function! ale_linters#dart#analysis_server#GetProjectRoot(buffer) abort
+ " Note: pub only looks for pubspec.yaml, there's no point in adding
+ " support for pubspec.yml
+ let l:pubspec = ale#path#FindNearestFile(a:buffer, 'pubspec.yaml')
+
+ return !empty(l:pubspec) ? fnamemodify(l:pubspec, ':h:h') : '.'
+endfunction
+
+function! ale_linters#dart#analysis_server#GetCommand(buffer) abort
+ let l:executable = ale#Var(a:buffer, 'dart_analysis_server_executable')
+ let l:dart = resolve(exepath(l:executable))
+
+ return '%e '
+ \ . fnamemodify(l:dart, ':h') . '/snapshots/analysis_server.dart.snapshot'
+ \ . ' --lsp'
+endfunction
+
+call ale#linter#Define('dart', {
+\ 'name': 'analysis_server',
+\ 'lsp': 'stdio',
+\ 'executable': {b -> ale#Var(b, 'dart_analysis_server_executable')},
+\ 'command': function('ale_linters#dart#analysis_server#GetCommand'),
+\ 'project_root': function('ale_linters#dart#analysis_server#GetProjectRoot'),
+\})
diff --git a/ale_linters/javascript/xo.vim b/ale_linters/javascript/xo.vim
index e24f4a82..5e04ad5c 100644
--- a/ale_linters/javascript/xo.vim
+++ b/ale_linters/javascript/xo.vim
@@ -1,26 +1,9 @@
" Author: Daniel Lupu <lupu.daniel.f@gmail.com>
" Description: xo for JavaScript files
-call ale#Set('javascript_xo_executable', 'xo')
-call ale#Set('javascript_xo_use_global', get(g:, 'ale_use_global_executables', 0))
-call ale#Set('javascript_xo_options', '')
-
-function! ale_linters#javascript#xo#GetExecutable(buffer) abort
- return ale#node#FindExecutable(a:buffer, 'javascript_xo', [
- \ 'node_modules/.bin/xo',
- \])
-endfunction
-
-function! ale_linters#javascript#xo#GetCommand(buffer) abort
- return ale#Escape(ale_linters#javascript#xo#GetExecutable(a:buffer))
- \ . ' ' . ale#Var(a:buffer, 'javascript_xo_options')
- \ . ' --reporter json --stdin --stdin-filename %s'
-endfunction
-
-" xo uses eslint and the output format is the same
call ale#linter#Define('javascript', {
\ 'name': 'xo',
-\ 'executable': function('ale_linters#javascript#xo#GetExecutable'),
-\ 'command': function('ale_linters#javascript#xo#GetCommand'),
-\ 'callback': 'ale#handlers#eslint#HandleJSON',
+\ 'executable': function('ale#handlers#xo#GetExecutable'),
+\ 'command': function('ale#handlers#xo#GetLintCommand'),
+\ 'callback': 'ale#handlers#xo#HandleJSON',
\})
diff --git a/ale_linters/openapi/ibm_validator.vim b/ale_linters/openapi/ibm_validator.vim
new file mode 100644
index 00000000..446931a2
--- /dev/null
+++ b/ale_linters/openapi/ibm_validator.vim
@@ -0,0 +1,58 @@
+" Author: Horacio Sanson <hsanson@gmail.com>
+
+call ale#Set('openapi_ibm_validator_executable', 'lint-openapi')
+call ale#Set('openapi_ibm_validator_options', '')
+
+function! ale_linters#openapi#ibm_validator#GetCommand(buffer) abort
+ return '%e' . ale#Pad(ale#Var(a:buffer, 'openapi_ibm_validator_options'))
+ \ . ' %t'
+endfunction
+
+function! ale_linters#openapi#ibm_validator#Handle(buffer, lines) abort
+ let l:output = []
+ let l:type = 'E'
+ let l:message = ''
+ let l:nr = -1
+
+ for l:line in a:lines
+ let l:match = matchlist(l:line, '^errors$')
+
+ if !empty(l:match)
+ let l:type = 'E'
+ endif
+
+ let l:match = matchlist(l:line, '^warnings$')
+
+ if !empty(l:match)
+ let l:type = 'W'
+ endif
+
+ let l:match = matchlist(l:line, '^ *Message : *\(.\+\)$')
+
+ if !empty(l:match)
+ let l:message = l:match[1]
+ endif
+
+ let l:match = matchlist(l:line, '^ *Line *: *\(\d\+\)$')
+
+ if !empty(l:match)
+ let l:nr = l:match[1]
+
+ call add(l:output, {
+ \ 'lnum': l:nr + 0,
+ \ 'col': 0,
+ \ 'text': l:message,
+ \ 'type': l:type,
+ \})
+ endif
+ endfor
+
+ return l:output
+endfunction
+
+call ale#linter#Define('openapi', {
+\ 'name': 'ibm_validator',
+\ 'executable': {b -> ale#Var(b, 'openapi_ibm_validator_executable')},
+\ 'command': function('ale_linters#openapi#ibm_validator#GetCommand'),
+\ 'callback': 'ale_linters#openapi#ibm_validator#Handle',
+\})
diff --git a/ale_linters/openapi/yamllint.vim b/ale_linters/openapi/yamllint.vim
new file mode 100644
index 00000000..2b8952cc
--- /dev/null
+++ b/ale_linters/openapi/yamllint.vim
@@ -0,0 +1,9 @@
+call ale#Set('yaml_yamllint_executable', 'yamllint')
+call ale#Set('yaml_yamllint_options', '')
+
+call ale#linter#Define('openapi', {
+\ 'name': 'yamllint',
+\ 'executable': {b -> ale#Var(b, 'yaml_yamllint_executable')},
+\ 'command': function('ale#handlers#yamllint#GetCommand'),
+\ 'callback': 'ale#handlers#yamllint#Handle',
+\})
diff --git a/ale_linters/typescript/xo.vim b/ale_linters/typescript/xo.vim
index 0a3a717b..6f4ee50c 100644
--- a/ale_linters/typescript/xo.vim
+++ b/ale_linters/typescript/xo.vim
@@ -1,23 +1,6 @@
-call ale#Set('typescript_xo_executable', 'xo')
-call ale#Set('typescript_xo_use_global', get(g:, 'ale_use_global_executables', 0))
-call ale#Set('typescript_xo_options', '')
-
-function! ale_linters#typescript#xo#GetExecutable(buffer) abort
- return ale#node#FindExecutable(a:buffer, 'typescript_xo', [
- \ 'node_modules/.bin/xo',
- \])
-endfunction
-
-function! ale_linters#typescript#xo#GetCommand(buffer) abort
- return ale#Escape(ale_linters#typescript#xo#GetExecutable(a:buffer))
- \ . ale#Pad(ale#Var(a:buffer, 'typescript_xo_options'))
- \ . ' --reporter json --stdin --stdin-filename %s'
-endfunction
-
-" xo uses eslint and the output format is the same
call ale#linter#Define('typescript', {
\ 'name': 'xo',
-\ 'executable': function('ale_linters#typescript#xo#GetExecutable'),
-\ 'command': function('ale_linters#typescript#xo#GetCommand'),
-\ 'callback': 'ale#handlers#eslint#HandleJSON',
+\ 'executable': function('ale#handlers#xo#GetExecutable'),
+\ 'command': function('ale#handlers#xo#GetLintCommand'),
+\ 'callback': 'ale#handlers#xo#HandleJSON',
\})
diff --git a/ale_linters/vala/vala_lint.vim b/ale_linters/vala/vala_lint.vim
new file mode 100644
index 00000000..7f8a566a
--- /dev/null
+++ b/ale_linters/vala/vala_lint.vim
@@ -0,0 +1,66 @@
+" Author: Atsuya Takagi <asoftonight@gmail.com>
+" Description: A linter for Vala using Vala-Lint.
+
+call ale#Set('vala_vala_lint_config_filename', 'vala-lint.conf')
+call ale#Set('vala_vala_lint_executable', 'io.elementary.vala-lint')
+
+function! ale_linters#vala#vala_lint#GetExecutable(buffer) abort
+ return ale#Var(a:buffer, 'vala_vala_lint_executable')
+endfunction
+
+function! ale_linters#vala#vala_lint#GetCommand(buffer) abort
+ let l:command = ale_linters#vala#vala_lint#GetExecutable(a:buffer)
+
+ let l:config_filename = ale#Var(a:buffer, 'vala_vala_lint_config_filename')
+ let l:config_path = ale#path#FindNearestFile(a:buffer, l:config_filename)
+
+ if !empty(l:config_path)
+ let l:command .= ' -c ' . l:config_path
+ endif
+
+ return l:command . ' %s'
+endfunction
+
+function! ale_linters#vala#vala_lint#Handle(buffer, lines) abort
+ let l:pattern = '^\s*\(\d\+\)\.\(\d\+\)\s\+\(error\|warn\)\s\+\(.\+\)\s\([A-Za-z0-9_\-]\+\)'
+ let l:output = []
+
+ for l:line in a:lines
+ " remove color escape sequences since vala-lint doesn't support
+ " output without colors
+ let l:cleaned_line = substitute(l:line, '\e\[[0-9;]\+[mK]', '', 'g')
+ let l:match = matchlist(l:cleaned_line, l:pattern)
+
+ if len(l:match) == 0
+ continue
+ endif
+
+ let l:refined_type = l:match[3] is# 'warn' ? 'W' : 'E'
+ let l:cleaned_text = substitute(l:match[4], '^\s*\(.\{-}\)\s*$', '\1', '')
+
+ let l:lnum = l:match[1] + 0
+ let l:column = l:match[2] + 0
+ let l:type = l:refined_type
+ let l:text = l:cleaned_text
+ let l:code = l:match[5]
+
+ call add(l:output, {
+ \ 'lnum': l:lnum,
+ \ 'col': l:column,
+ \ 'text': l:text,
+ \ 'type': l:type,
+ \ 'code': l:code,
+ \})
+ endfor
+
+ return l:output
+endfunction
+
+call ale#linter#Define('vala', {
+\ 'name': 'vala_lint',
+\ 'output_stream': 'stdout',
+\ 'executable': function('ale_linters#vala#vala_lint#GetExecutable'),
+\ 'command': function('ale_linters#vala#vala_lint#GetCommand'),
+\ 'callback': 'ale_linters#vala#vala_lint#Handle',
+\ 'lint_file': 1,
+\})
diff --git a/ale_linters/yaml/yamllint.vim b/ale_linters/yaml/yamllint.vim
index bedb7bf1..39011df1 100644
--- a/ale_linters/yaml/yamllint.vim
+++ b/ale_linters/yaml/yamllint.vim
@@ -3,48 +3,9 @@
call ale#Set('yaml_yamllint_executable', 'yamllint')
call ale#Set('yaml_yamllint_options', '')
-function! ale_linters#yaml#yamllint#GetCommand(buffer) abort
- return '%e' . ale#Pad(ale#Var(a:buffer, 'yaml_yamllint_options'))
- \ . ' -f parsable %t'
-endfunction
-
-function! ale_linters#yaml#yamllint#Handle(buffer, lines) abort
- " Matches patterns line the following:
- " something.yaml:1:1: [warning] missing document start "---" (document-start)
- " something.yml:2:1: [error] syntax error: expected the node content, but found '<stream end>'
- let l:pattern = '\v^.*:(\d+):(\d+): \[(error|warning)\] (.+)$'
- 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,
- \ 'text': l:match[4],
- \ 'type': l:match[3] is# 'error' ? 'E' : 'W',
- \}
-
- let l:code_match = matchlist(l:item.text, '\v^(.+) \(([^)]+)\)$')
-
- if !empty(l:code_match)
- if l:code_match[2] is# 'trailing-spaces'
- \&& !ale#Var(a:buffer, 'warn_about_trailing_whitespace')
- " Skip warnings for trailing whitespace if the option is off.
- continue
- endif
-
- let l:item.text = l:code_match[1]
- let l:item.code = l:code_match[2]
- endif
-
- call add(l:output, l:item)
- endfor
-
- return l:output
-endfunction
-
call ale#linter#Define('yaml', {
\ 'name': 'yamllint',
\ 'executable': {b -> ale#Var(b, 'yaml_yamllint_executable')},
-\ 'command': function('ale_linters#yaml#yamllint#GetCommand'),
-\ 'callback': 'ale_linters#yaml#yamllint#Handle',
+\ 'command': function('ale#handlers#yamllint#GetCommand'),
+\ 'callback': 'ale#handlers#yamllint#Handle',
\})