Add support for Packer (#4192)

* Add support for HashiCorp Packer

* Add test for packer fmt

* Add doc for HCL/Packer

* Add link to Packer doc

* Also suggest packer fix for packer ft

* Add more links to TOC
This commit is contained in:
Zhuoyun Wei 2022-05-16 05:15:52 -07:00 committed by GitHub
parent b611fde718
commit 429f5a1447
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 94 additions and 0 deletions

View File

@ -436,6 +436,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['hcl', 'terraform'],
\ 'description': 'Fix tf and hcl files with terraform fmt.',
\ },
\ 'packer': {
\ 'function': 'ale#fixers#packer#Fix',
\ 'suggested_filetypes': ['hcl', 'packer'],
\ 'description': 'Fix Packer HCL files with packer fmt.',
\ },
\ 'crystal': {
\ 'function': 'ale#fixers#crystal#Fix',
\ 'suggested_filetypes': ['cr'],

View File

@ -0,0 +1,17 @@
" Author: Zhuoyun Wei <wzyboy@wzyboy.org>
" Description: Fixer for Packer HCL files
call ale#Set('packer_fmt_executable', 'packer')
call ale#Set('packer_fmt_options', '')
function! ale#fixers#packer#Fix(buffer) abort
let l:executable = ale#Var(a:buffer, 'packer_fmt_executable')
let l:options = ale#Var(a:buffer, 'packer_fmt_options')
return {
\ 'command': ale#Escape(l:executable)
\ . ' fmt'
\ . (empty(l:options) ? '' : ' ' . l:options)
\ . ' -'
\}
endfunction

View File

@ -2,6 +2,11 @@
ALE HCL Integration *ale-hcl-options*
===============================================================================
packer-fmt *ale-hcl-packer-fmt*
See |ale-packer-fmt-fixer| for information about the available options.
===============================================================================
terraform-fmt *ale-hcl-terraform-fmt*

24
doc/ale-packer.txt Normal file
View File

@ -0,0 +1,24 @@
===============================================================================
ALE Packer Integration *ale-packer-options*
===============================================================================
packer-fmt-fixer *ale-packer-fmt-fixer*
g:ale_packer_fmt_executable *g:ale_packer_fmt_executable*
*b:ale_packer_fmt_executable*
Type: |String|
Default: `'packer'`
This variable can be changed to use a different executable for packer.
g:ale_packer_fmt_options *g:ale_packer_fmt_options*
*b:ale_packer_fmt_options*
Type: |String|
Default: `''`
===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View File

@ -239,6 +239,7 @@ Notes:
* `stack-ghc`
* `stylish-haskell`
* HCL
* `packer-fmt`
* `terraform-fmt`
* HTML
* `VSCode HTML language server`
@ -392,6 +393,8 @@ Notes:
* `ibm_validator`
* `prettier`
* `yamllint`
* Packer
* `packer-fmt-fixer`
* Pascal
* `ptop`
* Pawn

View File

@ -2911,6 +2911,7 @@ documented in additional help files.
hie...................................|ale-haskell-hie|
ormolu................................|ale-haskell-ormolu|
hcl.....................................|ale-hcl-options|
packer-fmt............................|ale-hcl-packer-fmt|
terraform-fmt.........................|ale-hcl-terraform-fmt|
help....................................|ale-help-options|
cspell................................|ale-help-cspell|
@ -3041,6 +3042,8 @@ documented in additional help files.
ibm_validator.........................|ale-openapi-ibm-validator|
prettier..............................|ale-openapi-prettier|
yamllint..............................|ale-openapi-yamllint|
packer..................................|ale-packer-options|
packer-fmt-fixer......................|ale-packer-fmt-fixer|
pascal..................................|ale-pascal-options|
ptop..................................|ale-pascal-ptop|
pawn....................................|ale-pawn-options|

View File

@ -248,6 +248,7 @@ formatting.
* [stack-ghc](https://haskellstack.org/)
* [stylish-haskell](https://github.com/jaspervdj/stylish-haskell)
* HCL
* [packer-fmt](https://github.com/hashicorp/packer)
* [terraform-fmt](https://github.com/hashicorp/terraform)
* HTML
* [VSCode HTML language server](https://github.com/hrsh7th/vscode-langservers-extracted)
@ -401,6 +402,8 @@ formatting.
* [ibm_validator](https://github.com/IBM/openapi-validator)
* [prettier](https://github.com/prettier/prettier)
* [yamllint](https://yamllint.readthedocs.io/)
* Packer (HCL)
* [packer-fmt-fixer](https://github.com/hashicorp/packer)
* Pascal
* [ptop](https://www.freepascal.org/tools/ptop.var)
* Pawn

View File

@ -0,0 +1,34 @@
Before:
Save g:ale_packer_fmt_executable
Save g:ale_packer_fmt_options
" Use an invalid global executable, so we don't match it.
let g:ale_packer_fmt_executable = 'xxxinvalid'
let g:ale_packer_fmt_options = ''
call ale#test#SetDirectory('/testplugin/test/fixers')
After:
Restore
call ale#test#RestoreDirectory()
Execute(The packer fmt callback should return the correct default values):
AssertEqual
\ {
\ 'command': ale#Escape('xxxinvalid') . ' fmt -',
\ },
\ ale#fixers#packer#Fix(bufnr(''))
Execute(The packer fmt callback should include custom options):
let g:ale_packer_fmt_options = "-list=true"
AssertEqual
\ {
\ 'command': ale#Escape('xxxinvalid')
\ . ' fmt'
\ . ' ' . g:ale_packer_fmt_options
\ . ' -',
\ },
\ ale#fixers#packer#Fix(bufnr(''))