summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorZhuoyun Wei <wzyboy@wzyboy.org>2022-05-16 05:15:52 -0700
committerGitHub <noreply@github.com>2022-05-16 21:15:52 +0900
commit429f5a14474c21392f5d5f863f4a98e04a7e02d0 (patch)
treede4ce7cbc9fc8fb067cc5240133b6faa1e0d2a3f /autoload
parentb611fde7184ce06ab49a19c58a5e2c45d9e40fed (diff)
downloadale-429f5a14474c21392f5d5f863f4a98e04a7e02d0.zip
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
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/fix/registry.vim5
-rw-r--r--autoload/ale/fixers/packer.vim17
2 files changed, 22 insertions, 0 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index 6932ad9d..eae29000 100644
--- a/autoload/ale/fix/registry.vim
+++ b/autoload/ale/fix/registry.vim
@@ -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'],
diff --git a/autoload/ale/fixers/packer.vim b/autoload/ale/fixers/packer.vim
new file mode 100644
index 00000000..8770550d
--- /dev/null
+++ b/autoload/ale/fixers/packer.vim
@@ -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