diff options
-rw-r--r-- | autoload/ale/fix/registry.vim | 5 | ||||
-rw-r--r-- | autoload/ale/fixers/html_beautify.vim | 21 | ||||
-rw-r--r-- | doc/ale-html.txt | 10 | ||||
-rw-r--r-- | doc/ale.txt | 1 | ||||
-rw-r--r-- | supported-tools.md | 1 | ||||
-rwxr-xr-x | test/command_callback/html_beautify_paths/html-beautify | 0 | ||||
-rw-r--r-- | test/command_callback/html_beautify_paths/test.html | 0 | ||||
-rw-r--r-- | test/fixers/test_html_beautify_fixer_callback.vader | 31 |
8 files changed, 69 insertions, 0 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index 2a96a7d6..4dfe767e 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -350,6 +350,11 @@ let s:default_registry = { \ 'suggested_filetypes': ['nix'], \ 'description': 'A formatter for Nix code', \ }, +\ 'html-beautify': { +\ 'function': 'ale#fixers#html_beautify#Fix', +\ 'suggested_filetypes': ['html', 'htmldjango'], +\ 'description': 'Fix HTML files with html-beautify.', +\ }, \} " Reset the function registry to the default entries. diff --git a/autoload/ale/fixers/html_beautify.vim b/autoload/ale/fixers/html_beautify.vim new file mode 100644 index 00000000..236cb6ec --- /dev/null +++ b/autoload/ale/fixers/html_beautify.vim @@ -0,0 +1,21 @@ +" Author: WhyNotHugo <hugo@barrera.io> +" Description: Lint HTML files with html-beautify. +" +call ale#Set('html_beautify_executable', 'html-beautify') +call ale#Set('html_beautify_use_global', get(g:, 'ale_use_global_executables', 0)) +call ale#Set('html_beautify_options', '') +call ale#Set('html_beautify_change_directory', 1) + +function! ale#fixers#html_beautify#Fix(buffer) abort + let l:executable = ale#python#FindExecutable( + \ a:buffer, + \ 'html_beautify', + \ ['html-beautify'] + \) + + let l:options = ale#Var(a:buffer, 'html_beautify_options') + + return { + \ 'command': ale#Escape(l:executable). ' ' . l:options . ' -', + \} +endfunction diff --git a/doc/ale-html.txt b/doc/ale-html.txt index 5d6b20e2..c78dc4cd 100644 --- a/doc/ale-html.txt +++ b/doc/ale-html.txt @@ -9,6 +9,16 @@ fecs *ale-html-fecs* and both of them reads `./.fecsrc` as the default configuration file. See: |ale-javascript-fecs|. +=============================================================================== +html-beautify *ale-html-beautify* + +g:ale_html_beautify_options *g:ale_html_beautify_options* + *b:ale_html_beautify_options* + Type: |String| + Default: `''` + + This variable can be changed to modify flags given to html-beautify. + =============================================================================== htmlhint *ale-html-htmlhint* diff --git a/doc/ale.txt b/doc/ale.txt index 291e90fb..eb3c84d6 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -2293,6 +2293,7 @@ documented in additional help files. terraform-fmt.........................|ale-hcl-terraform-fmt| html....................................|ale-html-options| fecs..................................|ale-html-fecs| + html-beautify.........................|ale-html-beautify| htmlhint..............................|ale-html-htmlhint| tidy..................................|ale-html-tidy| prettier..............................|ale-html-prettier| diff --git a/supported-tools.md b/supported-tools.md index c302d38c..de8882f9 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -203,6 +203,7 @@ formatting. * HTML * [alex](https://github.com/wooorm/alex) :floppy_disk: * [fecs](http://fecs.baidu.com/) + * [html-beautify](https://beautifier.io/) * [HTMLHint](http://htmlhint.com/) * [prettier](https://github.com/prettier/prettier) * [proselint](http://proselint.com/) diff --git a/test/command_callback/html_beautify_paths/html-beautify b/test/command_callback/html_beautify_paths/html-beautify new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/test/command_callback/html_beautify_paths/html-beautify diff --git a/test/command_callback/html_beautify_paths/test.html b/test/command_callback/html_beautify_paths/test.html new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/command_callback/html_beautify_paths/test.html diff --git a/test/fixers/test_html_beautify_fixer_callback.vader b/test/fixers/test_html_beautify_fixer_callback.vader new file mode 100644 index 00000000..dacd1cb2 --- /dev/null +++ b/test/fixers/test_html_beautify_fixer_callback.vader @@ -0,0 +1,31 @@ +Before: + Save g:ale_html_beautify_executable + Save g:ale_html_beautify_options + + let g:ale_html_beautify_options = '' + + call ale#test#SetDirectory('/testplugin/test/fixers') + silent cd .. + silent cd command_callback + let g:dir = getcwd() + +After: + Restore + + unlet! b:bin_dir + + call ale#test#RestoreDirectory() + +Execute(The html-beautify callback should return 0 if html-beautify not found): + let g:ale_html_beautify_executable = 'xxxinvalidpath' + AssertEqual + \ 0, + \ ale#fixers#html_beautify#Fix(bufnr('')) + +Execute(The html-beautify callback should return the correct default command): + AssertEqual + \ { + \ 'command': ale#Escape('html_beautify_paths/html-beautify') + \ . ' -' + \ }, + \ ale#fixers#html_beautify#Fix(bufnr('')) |