Skip to content

Commit e82fd24

Browse files
axhavkwalter94casens5beahuesbenjos1234
authored
Add yq support (#4861)
* Added jq support Cleaned up yq.vim file * Updated docs * Updated supported-tools.md * Added yq tests * Fix python linting/formatting error when in virtual environment (#4865) Python fixers and linters were failing when vim is running in a virtual environment that's located in a path containing text `poetry`. The cause of this was the regular expression `poetry\|pipenv\|uv$` which matches `poetry` and `pipenv` if they appear anywhere in the virtualenv path. * Add cljfmt fixer for clojure files (#4860) * When using `actionlint` look for & use a config file (#4858) Actionlint supports a config file and it lives in a very searchable path, as the only files it acts on are in the `.github` directory already. Look for an `actionlint.yml` and `.yaml` in that path, and use the config if its there. * Fix linting with jq (#4765) (#4862) With the 1.6 version of jq the error message start with "parse error". With the last version of jq the error message start with "jq: parse error". Fix it by using a regular expression that works in both cases. * Properly handle optional end_line_no/end_line_pos in sqlfluff (#4867) end_line_no/end_line_pos are optional. Example SQL: `SELECT NULL FROM {{ a_jinja_templated_table }};` `sqlfluff lint --dialect ansi --format json` gives the following error among others: ``` {"start_line_no": 1, "start_line_pos": 21, "code": "TMP", "description": "Undefined jinja template variable: 'a_jinja_templated_table'", "name": "", "warning": false} ``` As one can see there is no end_line_no/end_line_pos. * Add golangci-lint fixer (#4853) Closes #4616 * Fixed copy-paste misstakes and added filter to docs * Added test vader file for yq * Fixed and updated the test case --------- Co-authored-by: Walter Kaunda <[email protected]> Co-authored-by: rudolf ordoyne <[email protected]> Co-authored-by: Bea Hughes <[email protected]> Co-authored-by: benjos1234 <[email protected]> Co-authored-by: Coacher <[email protected]> Co-authored-by: Ian Stapleton Cordasco <[email protected]>
1 parent 5b2e69a commit e82fd24

File tree

9 files changed

+117
-0
lines changed

9 files changed

+117
-0
lines changed

ale_linters/yaml/yq.vim

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
" Author: axhav <[email protected]>
2+
call ale#Set('yaml_yq_executable', 'yq')
3+
call ale#Set('yaml_yq_options', '')
4+
call ale#Set('yaml_yq_filters', '.')
5+
6+
" Matches patterns like the following:
7+
let s:pattern = '^Error\:.* line \(\d\+\)\: \(.\+\)$'
8+
9+
function! ale_linters#yaml#yq#Handle(buffer, lines) abort
10+
return ale#util#MapMatches(a:lines, s:pattern, {match -> {
11+
\ 'lnum': match[1] + 0,
12+
\ 'text': match[2],
13+
\}})
14+
endfunction
15+
16+
call ale#linter#Define('yaml', {
17+
\ 'name': 'yq',
18+
\ 'executable': {b -> ale#Var(b, 'yaml_yq_executable')},
19+
\ 'output_stream': 'stderr',
20+
\ 'command': '%e',
21+
\ 'callback': 'ale_linters#yaml#yq#Handle',
22+
\})

autoload/ale/fix/registry.vim

+5
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ let s:default_registry = {
207207
\ 'suggested_filetypes': ['python'],
208208
\ 'description': 'Fix Python files with yapf.',
209209
\ },
210+
\ 'yq': {
211+
\ 'function': 'ale#fixers#yq#Fix',
212+
\ 'suggested_filetypes': ['yaml'],
213+
\ 'description': 'Fix YAML files with yq.',
214+
\ },
210215
\ 'rubocop': {
211216
\ 'function': 'ale#fixers#rubocop#Fix',
212217
\ 'suggested_filetypes': ['ruby'],

autoload/ale/fixers/yq.vim

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
call ale#Set('yaml_yq_executable', 'yq')
2+
call ale#Set('yaml_yq_options', '')
3+
call ale#Set('yaml_yq_filters', '.')
4+
5+
function! ale#fixers#yq#GetExecutable(buffer) abort
6+
return ale#Var(a:buffer, 'yaml_yq_executable')
7+
endfunction
8+
9+
function! ale#fixers#yq#Fix(buffer) abort
10+
let l:options = ale#Var(a:buffer, 'yaml_yq_options')
11+
let l:filters = ale#Var(a:buffer, 'yaml_yq_filters')
12+
13+
if empty(l:filters)
14+
return 0
15+
endif
16+
17+
return {
18+
\ 'command': ale#Escape(ale#fixers#yq#GetExecutable(a:buffer))
19+
\ . ' ' . l:filters . ' '
20+
\ . l:options,
21+
\}
22+
endfunction

doc/ale-supported-languages-and-tools.txt

+1
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,7 @@ Notes:
729729
* `yamlfix`
730730
* `yamlfmt`
731731
* `yamllint`
732+
* `yq`
732733
* YANG
733734
* `yang-lsp`
734735
* Zeek

doc/ale-yaml.txt

+38
Original file line numberDiff line numberDiff line change
@@ -366,5 +366,43 @@ g:ale_yaml_gitlablint_options *g:ale_yaml_gitlablint_options
366366
This variable can be set to pass additional options to gll.
367367

368368

369+
===============================================================================
370+
yq *ale-yaml-yq*
371+
372+
Website: https://github.com/mikefarah/yq
373+
374+
375+
Installation
376+
-------------------------------------------------------------------------------
377+
378+
Install yq: >
379+
380+
wget https://github.com/mikefarah/yq/releases/download/${VERSION}/${BINARY}.tar.gz -O - | tar xz && mv ${BINARY} /usr/bin/yq
381+
382+
Options
383+
-------------------------------------------------------------------------------
384+
385+
g:ale_yaml_yq_executable *g:ale_yaml_yq_executable*
386+
*b:ale_yaml_yq_executable*
387+
Type: |String|
388+
Default: `'yq'`
389+
390+
This variable can be set to change the path to yq.
391+
392+
393+
g:ale_yaml_yq_options *g:ale_yaml_yq_options*
394+
*b:ale_yaml_yq_options*
395+
Type: |String|
396+
Default: `''`
397+
398+
This variable can be set to pass additional options to yq.
399+
400+
g:ale_yaml_yq_filters *g:ale_yaml_yq_filters
401+
*b:ale_yaml_yq_filters*
402+
Type: |String|
403+
Default: `'.'`
404+
405+
This option can be changed to pass additional filters to yq
406+
369407
===============================================================================
370408
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

doc/ale.txt

+1
Original file line numberDiff line numberDiff line change
@@ -3517,6 +3517,7 @@ documented in additional help files.
35173517
yamlfmt...............................|ale-yaml-yamlfmt|
35183518
yamllint..............................|ale-yaml-yamllint|
35193519
gitlablint............................|ale-yaml-gitlablint|
3520+
yq....................................|ale-yaml-yq|
35203521
yang....................................|ale-yang-options|
35213522
yang-lsp..............................|ale-yang-lsp|
35223523
zeek....................................|ale-zeek-options|

supported-tools.md

+1
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,7 @@ formatting.
738738
* [yamlfix](https://lyz-code.github.io/yamlfix)
739739
* [yamlfmt](https://github.com/google/yamlfmt)
740740
* [yamllint](https://yamllint.readthedocs.io/)
741+
* [yq](https://github.com/mikefarah/yq)
741742
* YANG
742743
* [yang-lsp](https://github.com/theia-ide/yang-lsp)
743744
* Zeek

test/handler/test_yq_handler.vader

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Before:
2+
runtime ale_linters/yaml/yq.vim
3+
4+
After:
5+
call ale#linter#Reset()
6+
7+
Execute (Should parse error correctly):
8+
AssertEqual
9+
\ [
10+
\ {
11+
\ 'lnum': 2,
12+
\ 'text': "did not find expected ',' or ']'",
13+
\ }
14+
\ ],
15+
\ ale_linters#yaml#yq#Handle(bufnr(''), [
16+
\ "Error: bad file '-': yaml: line 2: did not find expected ',' or ']'"
17+
\ ])
18+
19+

test/linter/test_yq.vader

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Before:
2+
call ale#assert#SetUpLinterTest('yaml', 'yq')
3+
4+
After:
5+
call ale#assert#TearDownLinterTest()
6+
7+
Execute(The default command should be correct):
8+
AssertLinter 'yq', ale#Escape('yq')

0 commit comments

Comments
 (0)