Skip to content

Commit

Permalink
Implement support for apkbuild-fixer (#4881)
Browse files Browse the repository at this point in the history
I am not the author of a single file, but have full permissions from the
original author for permission for submitting this to ALE under the
2-Clause BSD licence.

See: https://gitlab.alpinelinux.org/Leo/apkbuild.vim/-/issues/3
  • Loading branch information
WhyNotHugo authored Dec 29, 2024
1 parent e82fd24 commit d69f8fe
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 1 deletion.
5 changes: 5 additions & 0 deletions autoload/ale/fix/registry.vim
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['help'],
\ 'description': 'Align help tags to the right margin',
\ },
\ 'apkbuild-fixer': {
\ 'function': 'ale#fixers#apkbuild_fixer#Fix',
\ 'suggested_filetypes': ['apkbuild'],
\ 'description': 'Fix policy violations found by apkbuild-lint in APKBUILDs',
\ },
\ 'autoimport': {
\ 'function': 'ale#fixers#autoimport#Fix',
\ 'suggested_filetypes': ['python'],
Expand Down
19 changes: 19 additions & 0 deletions autoload/ale/fixers/apkbuild_fixer.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
" Author: Leo <[email protected]>
" Description: Fix policy violations found by apkbuild-lint

call ale#Set('apkbuild_apkbuild_fixer_executable', 'apkbuild-fixer')
call ale#Set('apkbuild_apkbuild_fixer_lint_executable', get(g:, 'ale_apkbuild_apkbuild_lint_executable'))
call ale#Set('apkbuild_apkbuild_fixer_options', '')

function! ale#fixers#apkbuild_fixer#Fix(buffer) abort
let l:executable = ale#Var(a:buffer, 'apkbuild_apkbuild_fixer_executable')
let l:options = ale#Var(a:buffer, 'apkbuild_apkbuild_fixer_options')

return {
\ 'command': ale#Escape(l:executable)
\ . ' -p ' . ale#Var(a:buffer, 'apkbuild_apkbuild_fixer_lint_executable')
\ . (empty(l:options) ? '' : ' ' . l:options)
\ . ' %t',
\ 'read_temporary_file': 1,
\}
endfunction
33 changes: 32 additions & 1 deletion doc/ale-apkbuild.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,41 @@
ALE APKBUILD Integration *ale-apkbuild-options*


===============================================================================
apkbuild-fixer *ale-apkbuild-apkbuild-fixer*

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

This variable can be set to pass additional options to the apkbuild_fixer
fixer.


g:apkbuild_apkbuild_fixer_executable *g:apkbuild_apkbuild_fixer_executable*
*b:apkbuild_apkbuild_fixer_executable*
Type: |String|
Default: `'apkbuild-fixer'`

This variable can be modified to change the executable path for
`apkbuild-fixer`.


g:apkbuild_apkbuild_fixer_lint_executable
*g:apkbuild_apkbuild_fixer_lint_executable*
*b:apkbuild_apkbuild_fixer_lint_executable*
Type: |String|
Default: `'apkbuild-fixer'`

This variable can be modified to change the executable path for
`apkbuild-lint`, the binary used to find violations.


===============================================================================
apkbuild-lint *ale-apkbuild-apkbuild-lint*

g:ale_apkbuild_apkbuild_lint_executable
g:ale_apkbuild_apkbuild_lint_executable
*g:ale_apkbuild_apkbuild_lint_executable*
*b:ale_apkbuild_apkbuild_lint_executable*

Expand Down
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 @@ -23,6 +23,7 @@ Notes:
* API Blueprint
* `drafter`
* APKBUILD
* `apkbuild-fixer`
* `apkbuild-lint`
* `secfixes-check`
* AsciiDoc
Expand Down
1 change: 1 addition & 0 deletions doc/ale.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2898,6 +2898,7 @@ documented in additional help files.
ansible-language-server...............|ale-ansible-language-server|
ansible-lint..........................|ale-ansible-ansible-lint|
apkbuild................................|ale-apkbuild-options|
apkbuild-fixer........................|ale-apkbuild-apkbuild-fixer|
apkbuild-lint.........................|ale-apkbuild-apkbuild-lint|
secfixes-check........................|ale-apkbuild-secfixes-check|
asciidoc................................|ale-asciidoc-options|
Expand Down
1 change: 1 addition & 0 deletions supported-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ formatting.
* API Blueprint
* [drafter](https://github.com/apiaryio/drafter)
* APKBUILD
* [apkbuild-fixer](https://gitlab.alpinelinux.org/Leo/atools)
* [apkbuild-lint](https://gitlab.alpinelinux.org/Leo/atools)
* [secfixes-check](https://gitlab.alpinelinux.org/Leo/atools)
* AsciiDoc
Expand Down
20 changes: 20 additions & 0 deletions test/fixers/test_apkbuild_fixer_callback.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Before:
call ale#assert#SetUpFixerTest('apkbuild', 'apkbuild-fixer')

After:
call ale#assert#TearDownFixerTest()

Execute(The apkbuild-fixer callback should return the correct default values):
AssertFixer {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape('apkbuild-fixer') . ' -p apkbuild-lint %t',
\}

Execute(The apkbuild-fixer callback should include custom apkbuild-fixer options):
let g:ale_apkbuild_apkbuild_fixer_executable = "another-apkbuild-fixer"
let g:ale_apkbuild_apkbuild_fixer_options = "-s"

AssertFixer {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape('another-apkbuild-fixer') . ' -p apkbuild-lint -s %t'
\}

0 comments on commit d69f8fe

Please sign in to comment.