Skip to content

Commit

Permalink
Add yq support (#4861)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
7 people authored Dec 29, 2024
1 parent 5b2e69a commit e82fd24
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 0 deletions.
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 @@ -729,6 +729,7 @@ Notes:
* `yamlfix`
* `yamlfmt`
* `yamllint`
* `yq`
* YANG
* `yang-lsp`
* Zeek
Expand Down
38 changes: 38 additions & 0 deletions doc/ale-yaml.txt
Original file line number Diff line number Diff line change
Expand Up @@ -366,5 +366,43 @@ 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: `'yq'`

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


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 yq.

g:ale_yaml_yq_filters *g:ale_yaml_yq_filters
*b:ale_yaml_yq_filters*
Type: |String|
Default: `'.'`

This option can be changed to pass additional filters to yq

===============================================================================
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 @@ -3517,6 +3517,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 @@ -738,6 +738,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
19 changes: 19 additions & 0 deletions test/handler/test_yq_handler.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Before:
runtime ale_linters/yaml/yq.vim

After:
call ale#linter#Reset()

Execute (Should parse error correctly):
AssertEqual
\ [
\ {
\ 'lnum': 2,
\ 'text': "did not find expected ',' or ']'",
\ }
\ ],
\ ale_linters#yaml#yq#Handle(bufnr(''), [
\ "Error: bad file '-': yaml: line 2: did not find expected ',' or ']'"
\ ])


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')

0 comments on commit e82fd24

Please sign in to comment.