diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index 4ff04bac81..1ab569789d 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -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'], diff --git a/autoload/ale/fixers/apkbuild_fixer.vim b/autoload/ale/fixers/apkbuild_fixer.vim new file mode 100644 index 0000000000..b297fc61cd --- /dev/null +++ b/autoload/ale/fixers/apkbuild_fixer.vim @@ -0,0 +1,19 @@ +" Author: Leo <thinkabit.ukim@gmail.com> +" 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 diff --git a/doc/ale-apkbuild.txt b/doc/ale-apkbuild.txt index 052614009b..f80ca290f2 100644 --- a/doc/ale-apkbuild.txt +++ b/doc/ale-apkbuild.txt @@ -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* diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index 40d9210c30..2cd6260ed0 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -23,6 +23,7 @@ Notes: * API Blueprint * `drafter` * APKBUILD + * `apkbuild-fixer` * `apkbuild-lint` * `secfixes-check` * AsciiDoc diff --git a/doc/ale.txt b/doc/ale.txt index 3d7e8f5a94..67e89a2414 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -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| diff --git a/supported-tools.md b/supported-tools.md index c6a99de02c..4bf6c72138 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -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 diff --git a/test/fixers/test_apkbuild_fixer_callback.vader b/test/fixers/test_apkbuild_fixer_callback.vader new file mode 100644 index 0000000000..f7bce5cdf0 --- /dev/null +++ b/test/fixers/test_apkbuild_fixer_callback.vader @@ -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' + \}