From 7516e2e4849fb633555d5d40c2137e585ed10b64 Mon Sep 17 00:00:00 2001 From: Arash Mousavi Date: Wed, 17 Apr 2024 15:58:28 +0100 Subject: [PATCH] Add htmlbeautifier support (#4751) --- autoload/ale/fix/registry.vim | 5 +++++ autoload/ale/fixers/htmlbeautifier.vim | 13 +++++++++++++ doc/ale-eruby.txt | 13 +++++++++++++ doc/ale-supported-languages-and-tools.txt | 1 + doc/ale.txt | 1 + supported-tools.md | 1 + .../test_htmlbeautifier_fixer_callback.vader | 19 +++++++++++++++++++ 7 files changed, 53 insertions(+) create mode 100644 autoload/ale/fixers/htmlbeautifier.vim create mode 100644 test/fixers/test_htmlbeautifier_fixer_callback.vader diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index 141276a08d..b8829a5e66 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -561,6 +561,11 @@ let s:default_registry = { \ 'suggested_filetypes': ['html', 'htmldjango'], \ 'description': 'Fix HTML files with html-beautify from js-beautify.', \ }, +\ 'htmlbeautifier': { +\ 'function': 'ale#fixers#htmlbeautifier#Fix', +\ 'suggested_filetypes': ['eruby'], +\ 'description': 'Fix ERB files with htmlbeautifier gem.', +\ }, \ 'lua-format': { \ 'function': 'ale#fixers#lua_format#Fix', \ 'suggested_filetypes': ['lua'], diff --git a/autoload/ale/fixers/htmlbeautifier.vim b/autoload/ale/fixers/htmlbeautifier.vim new file mode 100644 index 0000000000..756d4a05a3 --- /dev/null +++ b/autoload/ale/fixers/htmlbeautifier.vim @@ -0,0 +1,13 @@ +" Author: Arash Mousavi +" Description: Support for HTML Beautifier https://github.com/threedaymonk/htmlbeautifier + +call ale#Set('eruby_htmlbeautifier_executable', 'htmlbeautifier') + +function! ale#fixers#htmlbeautifier#Fix(buffer) abort + let l:executable = ale#Var(a:buffer, 'eruby_htmlbeautifier_executable') + + return { + \ 'command': ale#Escape(l:executable) . ' %t', + \ 'read_temporary_file': 1, + \} +endfunction diff --git a/doc/ale-eruby.txt b/doc/ale-eruby.txt index 65bd8a306c..82fe685a03 100644 --- a/doc/ale-eruby.txt +++ b/doc/ale-eruby.txt @@ -7,6 +7,7 @@ There are four linters for `eruby` files: - `erblint` - `erubis` - `erubi` +- `htmlbeautifier` - `ruumba` `erb` is in the Ruby standard library and is mostly universal. `erubis` is the @@ -47,6 +48,18 @@ g:ale_eruby_erblint_options *g:ale_ruby_erblint_options* This variable can be change to modify flags given to erblint. +=============================================================================== +htmlbeautifier *ale-eruby-htmlbeautifier* + +g:ale_eruby_htmlbeautifier_executable *g:ale_eruby_htmlbeautifier_executable* + *b:ale_eruby_htmlbeautifier_executable* + Type: |String| + Default: `'htmlbeautifier'` + + Override the invoked htmlbeautifier binary. This is useful for running + htmlbeautifier from binstubs or a bundle. + + =============================================================================== ruumba *ale-eruby-ruumba* diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index d92321b444..2e4b4ab021 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -182,6 +182,7 @@ Notes: * `erblint` * `erubi` * `erubis` + * `htmlbeautifier` * `ruumba` * Erlang * `SyntaxErl` diff --git a/doc/ale.txt b/doc/ale.txt index 5cf926240e..9f5d4f86e3 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -3020,6 +3020,7 @@ documented in additional help files. eruby...................................|ale-eruby-options| erb-formatter.........................|ale-eruby-erbformatter| erblint...............................|ale-eruby-erblint| + htmlbeautifier........................|ale-eruby-htmlbeautifier| ruumba................................|ale-eruby-ruumba| fish....................................|ale-fish-options| fish_indent...........................|ale-fish-fish_indent| diff --git a/supported-tools.md b/supported-tools.md index affdeff9a1..0b6383f5de 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -191,6 +191,7 @@ formatting. * [erblint](https://github.com/Shopify/erb-lint) * [erubi](https://github.com/jeremyevans/erubi) * [erubis](https://github.com/kwatch/erubis) + * [htmlbeautifier](https://github.com/threedaymonk/htmlbeautifier) * [ruumba](https://github.com/ericqweinstein/ruumba) * Erlang * [SyntaxErl](https://github.com/ten0s/syntaxerl) diff --git a/test/fixers/test_htmlbeautifier_fixer_callback.vader b/test/fixers/test_htmlbeautifier_fixer_callback.vader new file mode 100644 index 0000000000..e54bab978c --- /dev/null +++ b/test/fixers/test_htmlbeautifier_fixer_callback.vader @@ -0,0 +1,19 @@ +Before: + call ale#assert#SetUpFixerTest('eruby', 'htmlbeautifier') + +After: + call ale#assert#TearDownFixerTest() + +Execute(The htmlbeautifier callback should return the correct default values): + AssertFixer { + \ 'command': ale#Escape('htmlbeautifier') . ' %t', + \ 'read_temporary_file': 1, + \} + +Execute(The htmlbeautifier callback should allow custom htmlbeautifier executables): + let g:ale_eruby_htmlbeautifier_executable = 'foo/bar' + + AssertFixer { + \ 'command': ale#Escape('foo/bar') . ' %t', + \ 'read_temporary_file': 1, + \}