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
2 changes: 1 addition & 1 deletion ale_linters/json/jq.vim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ call ale#Set('json_jq_filters', '.')

" Matches patterns like the following:
" parse error: Expected another key-value pair at line 4, column 3
let s:pattern = '^parse error: \(.\+\) at line \(\d\+\), column \(\d\+\)$'
let s:pattern = 'parse error: \(.\+\) at line \(\d\+\), column \(\d\+\)$'

function! ale_linters#json#jq#Handle(buffer, lines) abort
return ale#util#MapMatches(a:lines, s:pattern, {match -> {
Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/bandit.vim
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function! ale_linters#python#bandit#GetCommand(buffer) abort
endif
endif

let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run bandit'
\ : ''

Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/flake8.vim
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ endfunction
function! ale_linters#python#flake8#GetCommand(buffer, version) abort
let l:executable = ale_linters#python#flake8#GetExecutable(a:buffer)

let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run flake8'
\ : ''

Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/flakehell.vim
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ endfunction
function! ale_linters#python#flakehell#GetCommand(buffer, version) abort
let l:executable = ale_linters#python#flakehell#GetExecutable(a:buffer)

if (l:executable =~? 'pipenv\|poetry\|uv$')
if (l:executable =~? '\(pipenv\|poetry\|uv\)$')
let l:exec_args = ' run flakehell'
elseif (l:executable is? 'python')
let l:exec_args = ' -m flakehell'
Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/jedils.vim
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ endfunction

function! ale_linters#python#jedils#GetCommand(buffer) abort
let l:executable = ale_linters#python#jedils#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run jedi-language-server'
\ : ''
let l:env_string = ''
Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/mypy.vim
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ endfunction

function! ale_linters#python#mypy#GetCommand(buffer) abort
let l:executable = ale_linters#python#mypy#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run mypy'
\ : ''

Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/prospector.vim
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ endfunction
function! ale_linters#python#prospector#GetCommand(buffer) abort
let l:executable = ale_linters#python#prospector#GetExecutable(a:buffer)

let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run prospector'
\ : ''

Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/pycln.vim
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ endfunction

function! ale_linters#python#pycln#GetCommand(buffer, version) abort
let l:executable = ale_linters#python#pycln#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run pycln'
\ : ''

Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/pycodestyle.vim
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ endfunction
function! ale_linters#python#pycodestyle#GetCommand(buffer) abort
let l:executable = ale_linters#python#pycodestyle#GetExecutable(a:buffer)

let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run pycodestyle'
\ : ''

Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/pydocstyle.vim
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ endfunction

function! ale_linters#python#pydocstyle#GetCommand(buffer) abort
let l:executable = ale_linters#python#pydocstyle#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run pydocstyle'
\ : ''

Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/pyflakes.vim
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ endfunction
function! ale_linters#python#pyflakes#GetCommand(buffer) abort
let l:executable = ale_linters#python#pyflakes#GetExecutable(a:buffer)

let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run pyflakes'
\ : ''

Expand Down
4 changes: 2 additions & 2 deletions ale_linters/python/pylama.vim
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ endfunction

function! ale_linters#python#pylama#RunWithVersionCheck(buffer) abort
let l:executable = ale_linters#python#pylama#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run pylama'
\ : ''

Expand Down Expand Up @@ -59,7 +59,7 @@ endfunction

function! ale_linters#python#pylama#GetCommand(buffer, version) abort
let l:executable = ale_linters#python#pylama#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run pylama'
\ : ''

Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/pylint.vim
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ endfunction

function! ale_linters#python#pylint#GetCommand(buffer, version) abort
let l:executable = ale_linters#python#pylint#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run pylint'
\ : ''

Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/pylsp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ endfunction

function! ale_linters#python#pylsp#GetCommand(buffer) abort
let l:executable = ale_linters#python#pylsp#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run pylsp'
\ : ''
let l:env_string = ''
Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/pyre.vim
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ endfunction

function! ale_linters#python#pyre#GetCommand(buffer) abort
let l:executable = ale_linters#python#pyre#GetExecutable(a:buffer)
let l:exec_args = (l:executable =~? 'pipenv\|poetry\|uv$' ? ' run pyre' : '') . ' persistent'
let l:exec_args = (l:executable =~? '\(pipenv\|poetry\|uv\)$' ? ' run pyre' : '') . ' persistent'

return ale#Escape(l:executable) . l:exec_args
endfunction
Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/pyright.vim
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ endfunction

function! ale_linters#python#pyright#GetCommand(buffer) abort
let l:executable = ale_linters#python#pyright#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run pyright-langserver'
\ : ''
let l:env_string = ''
Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/refurb.vim
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ endfunction

function! ale_linters#python#refurb#GetCommand(buffer) abort
let l:executable = ale_linters#python#refurb#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run refurb'
\ : ''

Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/ruff.vim
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ endfunction

function! ale_linters#python#ruff#GetCommand(buffer, version) abort
let l:executable = ale_linters#python#ruff#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run ruff'
\ : ''

Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/unimport.vim
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ endfunction

function! ale_linters#python#unimport#GetCommand(buffer) abort
let l:executable = ale_linters#python#unimport#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run unimport'
\ : ''

Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/vulture.vim
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ endfunction

function! ale_linters#python#vulture#GetCommand(buffer) abort
let l:executable = ale_linters#python#vulture#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run vulture'
\ : ''
let l:lint_dest = ale#Var(a:buffer, 'python_vulture_change_directory')
Expand Down
16 changes: 12 additions & 4 deletions ale_linters/sql/sqlfluff.vim
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,24 @@ function! ale_linters#sql#sqlfluff#Handle(buffer, version, lines) abort

if ale#semver#GTE(a:version, [3, 0, 0])
for l:violation in get(l:json, 'violations', [])
call add(l:output, {
let l:err = {
\ 'filename': l:json.filepath,
\ 'lnum': l:violation.start_line_no,
\ 'end_lnum': l:violation.end_line_no,
\ 'col': l:violation.start_line_pos,
\ 'end_col': l:violation.end_line_pos,
\ 'text': l:violation.description,
\ 'code': l:violation.code,
\ 'type': 'W',
\})
\}

if has_key(l:violation, 'end_line_no')
let l:err.end_lnum = l:violation.end_line_no
endif

if has_key(l:violation, 'end_line_pos')
let l:err.end_col = l:violation.end_line_pos
endif

call add(l:output, l:err)
endfor
else
for l:violation in get(l:json, 'violations', [])
Expand Down
23 changes: 23 additions & 0 deletions ale_linters/yaml/actionlint.vim
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,32 @@ function! ale_linters#yaml#actionlint#GetCommand(buffer) abort
let l:options .= ale#Pad('-oneline')
endif

let l:configfile = ale_linters#yaml#actionlint#GitRepoHasConfig(a:buffer)

if !empty(l:configfile)
let l:options .= ale#Pad('-config-file ' . l:configfile)
endif

return '%e' . ale#Pad(l:options) . ' - '
endfunction

" If we have a actionlint.yml or actionlint.yaml in our github directory
" use that as our config file.
function! ale_linters#yaml#actionlint#GitRepoHasConfig(buffer) abort
let l:filename = expand('#' . a:buffer . ':p')
let l:configfilebase = substitute(l:filename, '\.github/.*', '.github/actionlint.','')

for l:ext in ['yml', 'yaml']
let l:configfile = l:configfilebase . l:ext

if filereadable(l:configfile)
return l:configfile
endif
endfor

return ''
endfunction

function! ale_linters#yaml#actionlint#Handle(buffer, lines) abort
" Matches patterns line the following:
".github/workflows/main.yml:19:0: could not parse as YAML: yaml: line 19: mapping values are not allowed in this context [yaml-syntax]
Expand Down
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',
\})
15 changes: 15 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 Expand Up @@ -327,6 +332,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['go'],
\ 'description': 'Fix Go files imports with goimports.',
\ },
\ 'golangci_lint': {
\ 'function': 'ale#fixers#golangci_lint#Fix',
\ 'suggested_filetypes': ['go'],
\ 'description': 'Fix Go files with golangci-lint.',
\ },
\ 'golines': {
\ 'function': 'ale#fixers#golines#Fix',
\ 'suggested_filetypes': ['go'],
Expand Down Expand Up @@ -672,6 +682,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['ruby'],
\ 'description': 'A formatter for Ruby source code',
\ },
\ 'cljfmt': {
\ 'function': 'ale#fixers#cljfmt#Fix',
\ 'suggested_filetypes': ['clojure'],
\ 'description': 'formatter and linter for clojure files',
\ },
\}

" Reset the function registry to the default entries.
Expand Down
2 changes: 1 addition & 1 deletion autoload/ale/fixers/autoflake.vim
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ endfunction
function! ale#fixers#autoflake#Fix(buffer) abort
let l:executable = ale#fixers#autoflake#GetExecutable(a:buffer)

let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run autoflake'
\ : ''

Expand Down
2 changes: 1 addition & 1 deletion autoload/ale/fixers/autoimport.vim
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ endfunction
function! ale#fixers#autoimport#Fix(buffer) abort
let l:executable = ale#fixers#autoimport#GetExecutable(a:buffer)

let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run autoimport'
\ : ''

Expand Down
2 changes: 1 addition & 1 deletion autoload/ale/fixers/autopep8.vim
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ endfunction
function! ale#fixers#autopep8#Fix(buffer) abort
let l:executable = ale#fixers#autopep8#GetExecutable(a:buffer)

let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run autopep8'
\ : ''

Expand Down
2 changes: 1 addition & 1 deletion autoload/ale/fixers/black.vim
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function! ale#fixers#black#Fix(buffer) abort
let l:executable = ale#fixers#black#GetExecutable(a:buffer)
let l:cmd = [ale#Escape(l:executable)]

if l:executable =~? 'pipenv\|poetry\|uv$'
if l:executable =~? '\(pipenv\|poetry\|uv\)$'
call extend(l:cmd, ['run', 'black'])
endif

Expand Down
14 changes: 14 additions & 0 deletions autoload/ale/fixers/cljfmt.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
" Author: rudolf ordoyne <[email protected]>
" Description: Support for cljfmt https://github.com/weavejester/cljfmt

call ale#Set('clojure_cljfmt_executable', 'cljfmt')

function! ale#fixers#cljfmt#Fix(buffer) abort
let l:executable = ale#Var(a:buffer, 'clojure_cljfmt_executable')

return {
\ 'command': ale#Escape(l:executable) . ' fix %t',
\ 'read_temporary_file': 1,
\}
endfunction

32 changes: 32 additions & 0 deletions autoload/ale/fixers/golangci_lint.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
" Author: Ian Stapleton Cordasco <[email protected]>
" Description: Run golangci-lint with the --fix flag to autofix some issues

call ale#Set('go_golangci_lint_options', '')
call ale#Set('go_golangci_lint_executable', 'golangci-lint')
call ale#Set('go_golangci_lint_package', 1)

function! ale#fixers#golangci_lint#GetCommand(buffer) abort
let l:filename = expand('#' . a:buffer . ':t')
let l:executable = ale#Var(a:buffer, 'go_golangci_lint_executable')
let l:options = ale#Var(a:buffer, 'go_golangci_lint_options') . ' --fix'
let l:package_mode = ale#Var(a:buffer, 'go_golangci_lint_package')
let l:env = ale#go#EnvString(a:buffer)


if l:package_mode
return l:env . ale#Escape(l:executable)
\ . ' run '
\ . l:options
endif

return l:env . ale#Escape(l:executable)
\ . ' run '
\ . l:options
\ . ' ' . ale#Escape(l:filename)
endfunction

function! ale#fixers#golangci_lint#Fix(buffer) abort
return {
\ 'command': ale#fixers#golangci_lint#GetCommand(a:buffer),
\}
endfunction
Loading
Loading