Skip to content

Commit

Permalink
Add htmlbeautifier support (dense-analysis#4751)
Browse files Browse the repository at this point in the history
  • Loading branch information
arashm authored Apr 17, 2024
1 parent 6db58b3 commit 7516e2e
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 0 deletions.
5 changes: 5 additions & 0 deletions autoload/ale/fix/registry.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
13 changes: 13 additions & 0 deletions autoload/ale/fixers/htmlbeautifier.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
" Author: Arash Mousavi <arash-m>
" 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
13 changes: 13 additions & 0 deletions doc/ale-eruby.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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*

Expand Down
1 change: 1 addition & 0 deletions doc/ale-supported-languages-and-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ Notes:
* `erblint`
* `erubi`
* `erubis`
* `htmlbeautifier`
* `ruumba`
* Erlang
* `SyntaxErl`
Expand Down
1 change: 1 addition & 0 deletions doc/ale.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
1 change: 1 addition & 0 deletions supported-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions test/fixers/test_htmlbeautifier_fixer_callback.vader
Original file line number Diff line number Diff line change
@@ -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,
\}

0 comments on commit 7516e2e

Please sign in to comment.