diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index a0e0c530..d2de0fc2 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -179,7 +179,12 @@ let s:default_registry = { \ 'yamlfix': { \ 'function': 'ale#fixers#yamlfix#Fix', \ 'suggested_filetypes': ['yaml'], -\ 'description': 'Fix yaml files with yamlfix.', +\ 'description': 'Fix YAML files with yamlfix.', +\ }, +\ 'yamlfmt': { +\ 'function': 'ale#fixers#yamlfmt#Fix', +\ 'suggested_filetypes': ['yaml'], +\ 'description': 'Format YAML files with yamlfmt.', \ }, \ 'yapf': { \ 'function': 'ale#fixers#yapf#Fix', diff --git a/autoload/ale/fixers/yamlfmt.vim b/autoload/ale/fixers/yamlfmt.vim new file mode 100644 index 00000000..e730832a --- /dev/null +++ b/autoload/ale/fixers/yamlfmt.vim @@ -0,0 +1,20 @@ +" Author: https://github.com/Spixmaster +" Description: Format YAML files with yamlfmt. + +call ale#Set('yaml_yamlfmt_executable', 'yamlfmt') +call ale#Set('yaml_yamlfmt_use_global', get(g:, 'ale_use_global_executables', 0)) +call ale#Set('yaml_yamlfmt_options', '') + +function! ale#fixers#yamlfmt#Fix(buffer) abort + let l:executable = ale#python#FindExecutable( + \ a:buffer, + \ 'yaml_yamlfmt', + \ ['yamlfmt'] + \) + + let l:options = ale#Var(a:buffer, 'yaml_yamlfmt_options') + + return { + \ 'command': ale#Escape(l:executable) . ' ' . l:options . ' -in', + \} +endfunction diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index da57908a..40c78f76 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -699,6 +699,7 @@ Notes: * `swaglint` * `yaml-language-server` * `yamlfix` + * `yamlfmt` * `yamllint` * YANG * `yang-lsp` diff --git a/doc/ale-yaml.txt b/doc/ale-yaml.txt index b3450b87..a6741c83 100644 --- a/doc/ale-yaml.txt +++ b/doc/ale-yaml.txt @@ -47,6 +47,7 @@ g:ale_yaml_actionlint_options *g:ale_yaml_actionlint_options* < Please note that passing `-format` as option is not supported at the moment. + =============================================================================== circleci *ale-yaml-circleci* @@ -242,6 +243,44 @@ g:ale_yaml_yamlfix_use_global *g:ale_yaml_yamlfix_use_global* See |ale-integrations-local-executables| +=============================================================================== +yamlfmt *ale-yaml-yamlfmt* + +Website: https://github.com/google/yamlfmt + + +Installation +------------------------------------------------------------------------------- + +Install yamlfmt: + + See the website. + +Options +------------------------------------------------------------------------------- +g:ale_yaml_yamlfmt_executable *g:ale_yaml_yamlfmt_executable* + *b:ale_yaml_yamlfmt_executable* + Type: |String| + Default: `'yamlfmt'` + + See |ale-integrations-local-executables| + + +g:ale_yaml_yamlfmt_options *g:ale_yaml_yamlfmt_options* + *b:ale_yaml_yamlfmt_options* + Type: |String| + Default: `''` + + This variable can be set to pass extra options to yamlfmt. + +g:ale_yaml_yamlfmt_use_global *g:ale_yaml_yamlfmt_use_global* + *b:ale_yaml_yamlfmt_use_global* + Type: |Number| + Default: `get(g:, 'ale_use_global_executables', 0)` + + See |ale-integrations-local-executables| + + =============================================================================== yamllint *ale-yaml-yamllint* diff --git a/doc/ale.txt b/doc/ale.txt index fd9dc1ca..e73abc99 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -3427,6 +3427,7 @@ documented in additional help files. swaglint..............................|ale-yaml-swaglint| yaml-language-server..................|ale-yaml-language-server| yamlfix...............................|ale-yaml-yamlfix| + yamlfmt...............................|ale-yaml-yamlfmt| yamllint..............................|ale-yaml-yamllint| gitlablint............................|ale-yaml-gitlablint| yang....................................|ale-yang-options| diff --git a/supported-tools.md b/supported-tools.md index c3c53289..72b45671 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -708,6 +708,7 @@ formatting. * [swaglint](https://github.com/byCedric/swaglint) :warning: * [yaml-language-server](https://github.com/redhat-developer/yaml-language-server) * [yamlfix](https://lyz-code.github.io/yamlfix) + * [yamlfmt](https://github.com/google/yamlfmt) * [yamllint](https://yamllint.readthedocs.io/) * YANG * [yang-lsp](https://github.com/theia-ide/yang-lsp) diff --git a/test/fixers/test_yamlfmt_fixer_callback.vader b/test/fixers/test_yamlfmt_fixer_callback.vader new file mode 100644 index 00000000..53604e4b --- /dev/null +++ b/test/fixers/test_yamlfmt_fixer_callback.vader @@ -0,0 +1,12 @@ +Before: + call ale#assert#SetUpFixerTest('yaml', 'yamlfmt') + +After: + Restore + + call ale#assert#TearDownFixerTest() + +Execute(The yamlfmt callback should return the correct default command): + AssertEqual + \ {'command': ale#Escape('yamlfmt') . ' -in'}, + \ ale#fixers#yamlfmt#Fix(bufnr(''))