summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/fix/registry.vim2
-rw-r--r--autoload/ale/fixers/prettier.vim1
-rw-r--r--autoload/ale/fixers/xo.vim37
-rw-r--r--autoload/ale/handlers/xo.vim44
-rw-r--r--autoload/ale/handlers/yamllint.vim39
5 files changed, 110 insertions, 13 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index f514466e..4564954b 100644
--- a/autoload/ale/fix/registry.vim
+++ b/autoload/ale/fix/registry.vim
@@ -102,7 +102,7 @@ let s:default_registry = {
\ },
\ 'prettier': {
\ 'function': 'ale#fixers#prettier#Fix',
-\ 'suggested_filetypes': ['javascript', 'typescript', 'css', 'less', 'scss', 'json', 'json5', 'graphql', 'markdown', 'vue', 'html', 'yaml'],
+\ 'suggested_filetypes': ['javascript', 'typescript', 'css', 'less', 'scss', 'json', 'json5', 'graphql', 'markdown', 'vue', 'html', 'yaml', 'openapi'],
\ 'description': 'Apply prettier to a file.',
\ },
\ 'prettier_eslint': {
diff --git a/autoload/ale/fixers/prettier.vim b/autoload/ale/fixers/prettier.vim
index e0f4972e..12c018af 100644
--- a/autoload/ale/fixers/prettier.vim
+++ b/autoload/ale/fixers/prettier.vim
@@ -83,6 +83,7 @@ function! ale#fixers#prettier#ApplyFixForVersion(buffer, version) abort
\ 'markdown': 'markdown',
\ 'vue': 'vue',
\ 'yaml': 'yaml',
+ \ 'openapi': 'yaml',
\ 'html': 'html',
\}
diff --git a/autoload/ale/fixers/xo.vim b/autoload/ale/fixers/xo.vim
index 882350be..dcf4c737 100644
--- a/autoload/ale/fixers/xo.vim
+++ b/autoload/ale/fixers/xo.vim
@@ -1,23 +1,36 @@
" Author: Albert Marquez - https://github.com/a-marquez
" Description: Fixing files with XO.
-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#fixers#xo#Fix(buffer) abort
+ let l:executable = ale#handlers#xo#GetExecutable(a:buffer)
+ let l:options = ale#handlers#xo#GetOptions(a:buffer)
-function! ale#fixers#xo#GetExecutable(buffer) abort
- return ale#node#FindExecutable(a:buffer, 'javascript_xo', [
- \ 'node_modules/xo/cli.js',
- \ 'node_modules/.bin/xo',
- \])
+ return ale#semver#RunWithVersionCheck(
+ \ a:buffer,
+ \ l:executable,
+ \ '%e --version',
+ \ {b, v -> ale#fixers#xo#ApplyFixForVersion(b, v, l:executable, l:options)}
+ \)
endfunction
-function! ale#fixers#xo#Fix(buffer) abort
- let l:executable = ale#fixers#xo#GetExecutable(a:buffer)
+function! ale#fixers#xo#ApplyFixForVersion(buffer, version, executable, options) abort
+ let l:executable = ale#node#Executable(a:buffer, a:executable)
+ let l:options = ale#Pad(a:options)
+
+ " 0.30.0 is the first version with a working --stdin --fix
+ if ale#semver#GTE(a:version, [0, 30, 0])
+ return {
+ \ 'command': l:executable
+ \ . ' --stdin --stdin-filename %s'
+ \ . ' --fix'
+ \ . l:options,
+ \}
+ endif
return {
- \ 'command': ale#node#Executable(a:buffer, l:executable)
- \ . ' --fix %t',
+ \ 'command': l:executable
+ \ . ' --fix %t'
+ \ . l:options,
\ 'read_temporary_file': 1,
\}
endfunction
diff --git a/autoload/ale/handlers/xo.vim b/autoload/ale/handlers/xo.vim
new file mode 100644
index 00000000..c63278c0
--- /dev/null
+++ b/autoload/ale/handlers/xo.vim
@@ -0,0 +1,44 @@
+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', '')
+
+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#handlers#xo#GetExecutable(buffer) abort
+ let l:type = ale#handlers#xo#GetType(a:buffer)
+
+ return ale#node#FindExecutable(a:buffer, l:type . '_xo', [
+ \ 'node_modules/xo/cli.js',
+ \ 'node_modules/.bin/xo',
+ \])
+endfunction
+
+function! ale#handlers#xo#GetLintCommand(buffer) abort
+ return ale#Escape(ale#handlers#xo#GetExecutable(a:buffer))
+ \ . ale#Pad(ale#handlers#xo#GetOptions(a:buffer))
+ \ . ' --reporter json --stdin --stdin-filename %s'
+endfunction
+
+function! ale#handlers#xo#GetOptions(buffer) abort
+ let l:type = ale#handlers#xo#GetType(a:buffer)
+
+ return ale#Var(a:buffer, l:type . '_xo_options')
+endfunction
+
+" xo uses eslint and the output format is the same
+function! ale#handlers#xo#HandleJSON(buffer, lines) abort
+ return ale#handlers#eslint#HandleJSON(a:buffer, a:lines)
+endfunction
+
+function! ale#handlers#xo#GetType(buffer) abort
+ let l:filetype = getbufvar(a:buffer, '&filetype')
+ let l:type = 'javascript'
+
+ if l:filetype =~# 'typescript'
+ let l:type = 'typescript'
+ endif
+
+ return l:type
+endfunction
diff --git a/autoload/ale/handlers/yamllint.vim b/autoload/ale/handlers/yamllint.vim
new file mode 100644
index 00000000..5e04577d
--- /dev/null
+++ b/autoload/ale/handlers/yamllint.vim
@@ -0,0 +1,39 @@
+function! ale#handlers#yamllint#GetCommand(buffer) abort
+ return '%e' . ale#Pad(ale#Var(a:buffer, 'yaml_yamllint_options'))
+ \ . ' -f parsable %t'
+endfunction
+
+function! ale#handlers#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
+