diff options
author | w0rp <w0rp@users.noreply.github.com> | 2018-06-23 22:51:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-23 22:51:30 +0100 |
commit | 755f1a4ccfff28463b0fe30f74a97390ae59d1fa (patch) | |
tree | e82ff6bae35e22df5703826e172a41b271fbe42e | |
parent | 0f377251dd90439029435d444594539f854957de (diff) | |
parent | 17c1aefb5bdd58ff854f17e00aa949e841560e94 (diff) | |
download | ale-755f1a4ccfff28463b0fe30f74a97390ae59d1fa.zip |
Merge pull request #1673 from meain/fixer-tidy
Add fixer tidy for HTML
-rw-r--r-- | autoload/ale/fix/registry.vim | 5 | ||||
-rw-r--r-- | autoload/ale/fixers/tidy.vim | 26 | ||||
-rw-r--r-- | doc/ale-html.txt | 8 | ||||
-rw-r--r-- | test/command_callback/tidy_paths/.tidyrc | 0 | ||||
-rw-r--r-- | test/command_callback/tidy_paths/test.html | 0 | ||||
-rwxr-xr-x | test/command_callback/tidy_paths/tidy | 0 | ||||
-rwxr-xr-x | test/command_callback/tidy_paths/tidy.exe | 0 | ||||
-rw-r--r-- | test/fixers/test_tidy_fixer_callback.vader | 29 |
8 files changed, 68 insertions, 0 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index dec762a2..60d7d7a8 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -22,6 +22,11 @@ let s:default_registry = { \ 'suggested_filetypes': ['python'], \ 'description': 'Fix PEP8 issues with black.', \ }, +\ 'tidy': { +\ 'function': 'ale#fixers#tidy#Fix', +\ 'suggested_filetypes': ['html'], +\ 'description': 'Fix HTML files with tidy.', +\ }, \ 'prettier_standard': { \ 'function': 'ale#fixers#prettier_standard#Fix', \ 'suggested_filetypes': ['javascript'], diff --git a/autoload/ale/fixers/tidy.vim b/autoload/ale/fixers/tidy.vim new file mode 100644 index 00000000..1af4120b --- /dev/null +++ b/autoload/ale/fixers/tidy.vim @@ -0,0 +1,26 @@ +" Author: meain <abinsimon10@gmail.com> +" Description: Fixing HTML files with tidy. + +call ale#Set('html_tidy_executable', 'tidy') +call ale#Set('html_tidy_use_global', get(g:, 'ale_use_global_executables', 0)) + +function! ale#fixers#tidy#Fix(buffer) abort + let l:executable = ale#node#FindExecutable( + \ a:buffer, + \ 'html_tidy', + \ ['tidy'], + \) + + if !executable(l:executable) + return 0 + endif + + let l:config = ale#path#FindNearestFile(a:buffer, '.tidyrc') + let l:config_options = !empty(l:config) + \ ? ' -q --tidy-mark no --show-errors 0 --show-warnings 0 -config ' . ale#Escape(l:config) + \ : ' -q --tidy-mark no --show-errors 0 --show-warnings 0' + + return { + \ 'command': ale#Escape(l:executable) . l:config_options, + \} +endfunction diff --git a/doc/ale-html.txt b/doc/ale-html.txt index 2d8873ef..98fddc58 100644 --- a/doc/ale-html.txt +++ b/doc/ale-html.txt @@ -71,6 +71,14 @@ g:ale_html_tidy_options *g:ale_html_tidy_options* (mac), sjis (shiftjis), utf-16le, utf-16, utf-8 +g:ale_html_tidy_use_global *g:html_tidy_use_global* + + Type: |Number| + Default: `get(g:, 'ale_use_global_executables', 0)` + + See |ale-integrations-local-executables| + + =============================================================================== write-good *ale-html-write-good* diff --git a/test/command_callback/tidy_paths/.tidyrc b/test/command_callback/tidy_paths/.tidyrc new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/command_callback/tidy_paths/.tidyrc diff --git a/test/command_callback/tidy_paths/test.html b/test/command_callback/tidy_paths/test.html new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/command_callback/tidy_paths/test.html diff --git a/test/command_callback/tidy_paths/tidy b/test/command_callback/tidy_paths/tidy new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/test/command_callback/tidy_paths/tidy diff --git a/test/command_callback/tidy_paths/tidy.exe b/test/command_callback/tidy_paths/tidy.exe new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/test/command_callback/tidy_paths/tidy.exe diff --git a/test/fixers/test_tidy_fixer_callback.vader b/test/fixers/test_tidy_fixer_callback.vader new file mode 100644 index 00000000..5677d8fd --- /dev/null +++ b/test/fixers/test_tidy_fixer_callback.vader @@ -0,0 +1,29 @@ +Before: + Save g:ale_html_tidy_executable + + let g:ale_html_tidy_executable = 'tidy_paths/tidy' + + call ale#test#SetDirectory('/testplugin/test/fixers') + + silent cd .. + silent cd command_callback + let g:dir = getcwd() + +After: + Restore + + call ale#test#RestoreDirectory() + +Execute(The tidy callback should return 0 if tidy not found): + let g:ale_html_tidy_executable = 'xxxinvalidpath' + AssertEqual + \ 0, + \ ale#fixers#tidy#Fix(bufnr('')) + +Execute(The tidy callback should return the correct default command): + AssertEqual + \ { + \ 'command': ale#Escape('tidy_paths/tidy') + \ . ' -q --tidy-mark no --show-errors 0 --show-warnings 0' + \ }, + \ ale#fixers#tidy#Fix(bufnr('')) |