Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add yq support #4861

Merged
merged 13 commits into from
Dec 29, 2024
22 changes: 22 additions & 0 deletions ale_linters/yaml/yq.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
" Author: axhav <[email protected]>
call ale#Set('yaml_yq_executable', 'yq')
call ale#Set('yaml_yq_options', '')
call ale#Set('yaml_yq_filters', '.')

" Matches patterns like the following:
let s:pattern = '^Error\:.* line \(\d\+\)\: \(.\+\)$'

function! ale_linters#yaml#yq#Handle(buffer, lines) abort
return ale#util#MapMatches(a:lines, s:pattern, {match -> {
\ 'lnum': match[1] + 0,
\ 'text': match[2],
\}})
endfunction

call ale#linter#Define('yaml', {
\ 'name': 'yq',
\ 'executable': {b -> ale#Var(b, 'yaml_yq_executable')},
\ 'output_stream': 'stderr',
\ 'command': '%e',
\ 'callback': 'ale_linters#yaml#yq#Handle',
\})
5 changes: 5 additions & 0 deletions autoload/ale/fix/registry.vim
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['python'],
\ 'description': 'Fix Python files with yapf.',
\ },
\ 'yq': {
\ 'function': 'ale#fixers#yq#Fix',
\ 'suggested_filetypes': ['yaml'],
\ 'description': 'Fix YAML files with yq.',
\ },
\ 'rubocop': {
\ 'function': 'ale#fixers#rubocop#Fix',
\ 'suggested_filetypes': ['ruby'],
Expand Down
22 changes: 22 additions & 0 deletions autoload/ale/fixers/yq.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
call ale#Set('yaml_yq_executable', 'yq')
call ale#Set('yaml_yq_options', '')
call ale#Set('yaml_yq_filters', '.')

function! ale#fixers#yq#GetExecutable(buffer) abort
return ale#Var(a:buffer, 'yaml_yq_executable')
endfunction

function! ale#fixers#yq#Fix(buffer) abort
let l:options = ale#Var(a:buffer, 'yaml_yq_options')
let l:filters = ale#Var(a:buffer, 'yaml_yq_filters')

if empty(l:filters)
return 0
endif

return {
\ 'command': ale#Escape(ale#fixers#yq#GetExecutable(a:buffer))
\ . ' ' . l:filters . ' '
\ . l:options,
\}
endfunction
1 change: 1 addition & 0 deletions doc/ale-supported-languages-and-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,7 @@ Notes:
* `yamlfix`
* `yamlfmt`
* `yamllint`
* `yq`
* YANG
* `yang-lsp`
* Zeek
Expand Down
32 changes: 32 additions & 0 deletions doc/ale-yaml.txt
Original file line number Diff line number Diff line change
Expand Up @@ -366,5 +366,37 @@ g:ale_yaml_gitlablint_options *g:ale_yaml_gitlablint_options
This variable can be set to pass additional options to gll.


===============================================================================
yq *ale-yaml-yq*

Website: https://github.com/mikefarah/yq


Installation
-------------------------------------------------------------------------------

Install yq: >

wget https://github.com/mikefarah/yq/releases/download/${VERSION}/${BINARY}.tar.gz -O - | tar xz && mv ${BINARY} /usr/bin/yq

Options
-------------------------------------------------------------------------------

g:ale_yaml_yq_executable *g:ale_yaml_yq_executable*
*b:ale_yaml_yq_executable*
Type: |String|
Default: `'gll'`
axhav marked this conversation as resolved.
Show resolved Hide resolved

This variable can be set to change the path to gll.


g:ale_yaml_yq_options *g:ale_yaml_yq_options*
*b:ale_yaml_yq_options*
Type: |String|
Default: `''`

This variable can be set to pass additional options to gll.
axhav marked this conversation as resolved.
Show resolved Hide resolved


axhav marked this conversation as resolved.
Show resolved Hide resolved
===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
1 change: 1 addition & 0 deletions doc/ale.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3516,6 +3516,7 @@ documented in additional help files.
yamlfmt...............................|ale-yaml-yamlfmt|
yamllint..............................|ale-yaml-yamllint|
gitlablint............................|ale-yaml-gitlablint|
yq....................................|ale-yaml-yq|
yang....................................|ale-yang-options|
yang-lsp..............................|ale-yang-lsp|
zeek....................................|ale-zeek-options|
Expand Down
1 change: 1 addition & 0 deletions supported-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ formatting.
* [yamlfix](https://lyz-code.github.io/yamlfix)
* [yamlfmt](https://github.com/google/yamlfmt)
* [yamllint](https://yamllint.readthedocs.io/)
* [yq](https://github.com/mikefarah/yq)
* YANG
* [yang-lsp](https://github.com/theia-ide/yang-lsp)
* Zeek
Expand Down
8 changes: 8 additions & 0 deletions test/linter/test_yq.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Before:
call ale#assert#SetUpLinterTest('yaml', 'yq')

After:
call ale#assert#TearDownLinterTest()

Execute(The default command should be correct):
AssertLinter 'yq', ale#Escape('yq')