diff options
author | w0rp <w0rp@users.noreply.github.com> | 2018-10-25 14:05:48 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-25 14:05:48 +0100 |
commit | 68b55912990226003213c25e43a57847ac7f36f1 (patch) | |
tree | 4ee62e09f83cd92622037f9730661fffd12f52b5 | |
parent | 2000436dfd7a25a8e9f66788c94bfb4512adda98 (diff) | |
parent | 395cabc22a2ffd71ab0ed288d9de8651afacfbf1 (diff) | |
download | ale-68b55912990226003213c25e43a57847ac7f36f1.zip |
Merge pull request #2015 from dsifford/dsifford-terraform
add terraform fmt fixer for terraform and hcl filetypes
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | autoload/ale/fix/registry.vim | 5 | ||||
-rw-r--r-- | autoload/ale/fixers/terraform.vim | 17 | ||||
-rw-r--r-- | doc/ale-hcl.txt | 11 | ||||
-rw-r--r-- | doc/ale-terraform.txt | 18 | ||||
-rw-r--r-- | doc/ale.txt | 6 | ||||
-rw-r--r-- | test/fixers/test_terraform_fmt_fixer_callback.vader | 34 |
7 files changed, 92 insertions, 2 deletions
@@ -133,6 +133,7 @@ formatting. | Haml | [haml-lint](https://github.com/brigade/haml-lint) | | Handlebars | [ember-template-lint](https://github.com/rwjblue/ember-template-lint) | | Haskell | [brittany](https://github.com/lspitzner/brittany), [ghc](https://www.haskell.org/ghc/), [cabal-ghc](https://www.haskell.org/cabal/), [stylish-haskell](https://github.com/jaspervdj/stylish-haskell), [stack-ghc](https://haskellstack.org/), [stack-build](https://haskellstack.org/) !!, [ghc-mod](https://github.com/DanielG/ghc-mod), [hlint](https://hackage.haskell.org/package/hlint), [hdevtools](https://hackage.haskell.org/package/hdevtools), [hfmt](https://github.com/danstiner/hfmt), [hie](https://github.com/haskell/haskell-ide-engine) | +| HCL | [terraform-fmt](https://github.com/hashicorp/terraform) | | HTML | [alex](https://github.com/wooorm/alex) !!, [HTMLHint](http://htmlhint.com/), [proselint](http://proselint.com/), [tidy](http://www.html-tidy.org/), [write-good](https://github.com/btford/write-good) | | Idris | [idris](http://www.idris-lang.org/) | | Java | [checkstyle](http://checkstyle.sourceforge.net), [javac](http://www.oracle.com/technetwork/java/javase/downloads/index.html), [google-java-format](https://github.com/google/google-java-format), [PMD](https://pmd.github.io/), [javalsp](https://github.com/georgewfraser/vscode-javac), [uncrustify](https://github.com/uncrustify/uncrustify) | @@ -184,7 +185,7 @@ formatting. | SQL | [sqlint](https://github.com/purcell/sqlint), [sqlfmt](https://github.com/jackc/sqlfmt) | | Swift | [swiftlint](https://github.com/realm/SwiftLint), [swiftformat](https://github.com/nicklockwood/SwiftFormat) | | Tcl | [nagelfar](http://nagelfar.sourceforge.net) !! | -| Terraform | [tflint](https://github.com/wata727/tflint) | +| Terraform | [fmt](https://github.com/hashicorp/terraform), [tflint](https://github.com/wata727/tflint) | | Texinfo | [alex](https://github.com/wooorm/alex) !!, [proselint](http://proselint.com/), [write-good](https://github.com/btford/write-good)| | Text^ | [alex](https://github.com/wooorm/alex) !!, [proselint](http://proselint.com/), [redpen](http://redpen.cc/), [textlint](https://textlint.github.io/), [vale](https://github.com/ValeLint/vale), [write-good](https://github.com/btford/write-good) | | Thrift | [thrift](http://thrift.apache.org/) | diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index 76cce87f..98f52232 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -250,6 +250,11 @@ let s:default_registry = { \ 'suggested_filetypes': ['c', 'cpp', 'cs', 'objc', 'objcpp', 'd', 'java', 'p', 'vala' ], \ 'description': 'Fix C, C++, C#, ObjectiveC, ObjectiveC++, D, Java, Pawn, and VALA files with uncrustify.', \ }, +\ 'terraform': { +\ 'function': 'ale#fixers#terraform#Fix', +\ 'suggested_filetypes': ['hcl', 'terraform'], +\ 'description': 'Fix tf and hcl files with terraform fmt.', +\ }, \} " Reset the function registry to the default entries. diff --git a/autoload/ale/fixers/terraform.vim b/autoload/ale/fixers/terraform.vim new file mode 100644 index 00000000..bc05380a --- /dev/null +++ b/autoload/ale/fixers/terraform.vim @@ -0,0 +1,17 @@ +" Author: dsifford <dereksifford@gmail.com> +" Description: Fixer for terraform and .hcl files + +call ale#Set('terraform_fmt_executable', 'terraform') +call ale#Set('terraform_fmt_options', '') + +function! ale#fixers#terraform#Fix(buffer) abort + let l:executable = ale#Var(a:buffer, 'terraform_fmt_executable') + let l:options = ale#Var(a:buffer, 'terraform_fmt_options') + + return { + \ 'command': ale#Escape(l:executable) + \ . ' fmt' + \ . (empty(l:options) ? '' : ' ' . l:options) + \ . ' -' + \} +endfunction diff --git a/doc/ale-hcl.txt b/doc/ale-hcl.txt new file mode 100644 index 00000000..8060ac44 --- /dev/null +++ b/doc/ale-hcl.txt @@ -0,0 +1,11 @@ +=============================================================================== +ALE HCL Integration *ale-hcl-options* + + +=============================================================================== +terraform-fmt *ale-hcl-terraform-fmt* + +See |ale-terraform-fmt| for information about the available options. + +=============================================================================== + vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale-terraform.txt b/doc/ale-terraform.txt index ec86e9a0..49a55028 100644 --- a/doc/ale-terraform.txt +++ b/doc/ale-terraform.txt @@ -3,6 +3,24 @@ ALE Terraform Integration *ale-terraform-options* =============================================================================== +fmt *ale-terraform-fmt* + +g:ale_terraform_fmt_executable *g:ale_terraform_fmt_executable* + *b:ale_terraform_fmt_executable* + + Type: |String| + Default: `'terraform'` + + This variable can be changed to use a different executable for terraform. + + +g:ale_terraform_fmt_options *g:ale_terraform_fmt_options* + *b:ale_terraform_fmt_options* + Type: |String| + Default: `''` + + +=============================================================================== tflint *ale-terraform-tflint* g:ale_terraform_tflint_executable *g:ale_terraform_tflint_executable* diff --git a/doc/ale.txt b/doc/ale.txt index 3aab94b4..38fbbfab 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -129,6 +129,8 @@ CONTENTS *ale-contents* stack-build.........................|ale-haskell-stack-build| stylish-haskell.....................|ale-haskell-stylish-haskell| hie.................................|ale-haskell-hie| + hcl...................................|ale-hcl-options| + terraform-fmt.......................|ale-hcl-terraform-fmt| html..................................|ale-html-options| htmlhint............................|ale-html-htmlhint| tidy................................|ale-html-tidy| @@ -297,6 +299,7 @@ CONTENTS *ale-contents* tcl...................................|ale-tcl-options| nagelfar............................|ale-tcl-nagelfar| terraform.............................|ale-terraform-options| + fmt.................................|ale-terraform-fmt| tflint..............................|ale-terraform-tflint| tex...................................|ale-tex-options| chktex..............................|ale-tex-chktex| @@ -417,6 +420,7 @@ Notes: * Haml: `haml-lint` * Handlebars: `ember-template-lint` * Haskell: `brittany`, `ghc`, `cabal-ghc`, `stylish-haskell`, `stack-ghc`, `stack-build`!!, `ghc-mod`, `hlint`, `hdevtools`, `hfmt`, `hie` +* HCL: `terraform-fmt` * HTML: `alex`!!, `HTMLHint`, `proselint`, `tidy`, `write-good` * Idris: `idris` * Java: `checkstyle`, `javac`, `google-java-format`, `PMD`, `javalsp`, `uncrustify` @@ -468,7 +472,7 @@ Notes: * SQL: `sqlint`, `sqlfmt` * Swift: `swiftlint`, `swiftformat` * Tcl: `nagelfar`!! -* Terraform: `tflint` +* Terraform: `fmt`, `tflint` * Texinfo: `alex`!!, `proselint`, `write-good` * Text^: `alex`!!, `proselint`, `redpen`, `textlint`, `vale`, `write-good` * Thrift: `thrift` diff --git a/test/fixers/test_terraform_fmt_fixer_callback.vader b/test/fixers/test_terraform_fmt_fixer_callback.vader new file mode 100644 index 00000000..15377a7e --- /dev/null +++ b/test/fixers/test_terraform_fmt_fixer_callback.vader @@ -0,0 +1,34 @@ +Before: + Save g:ale_terraform_fmt_executable + Save g:ale_terraform_fmt_options + + " Use an invalid global executable, so we don't match it. + let g:ale_terraform_fmt_executable = 'xxxinvalid' + let g:ale_terraform_fmt_options = '' + + call ale#test#SetDirectory('/testplugin/test/fixers') + +After: + Restore + + call ale#test#RestoreDirectory() + +Execute(The terraform fmt callback should return the correct default values): + + AssertEqual + \ { + \ 'command': ale#Escape('xxxinvalid') . ' fmt -', + \ }, + \ ale#fixers#terraform#Fix(bufnr('')) + +Execute(The terraform fmt callback should include custom options): + let g:ale_terraform_fmt_options = "-list=true" + + AssertEqual + \ { + \ 'command': ale#Escape('xxxinvalid') + \ . ' fmt' + \ . ' ' . g:ale_terraform_fmt_options + \ . ' -', + \ }, + \ ale#fixers#terraform#Fix(bufnr('')) |