Search code examples
vimtidylintervim-ale

How to configure VIM Ale to use the Tidy linter for HTML?


I'm trying to configure the vim Ale plugin to use Tidy to lint HTML code. I added to my .vimrc file:

 let g:ale_linters = {
 \   'css': ['csslint'],
 \   'html': ['tidy'],
 \   'javascript': ['eslint'],
 \   'php': [''],
 \   'python': ['flake8'],
 \}

I got the linters working for CSS, JavaScript, and Python, but not HTML.

:ALEInfo outputs:

Current Filetype: html
Available Linters: ['alex', 'fecs', 'htmlhint', 'proselint', 'stylelint', 'tidy', 'writegood']
Linter Aliases: 'writegood' -> ['write-good']

Enabled Linters: ['tidy']

. . . at the end of the information . . .

Command History: (executable check - success) tidy

It looks like the Tidy linter is available and configured, but I can't get it to work. The html files seem to have no linting at all.

I am able to run Tidy successfully in the terminal:

> tidy test.html
line 1 column 1 - Warning: missing <!DOCTYPE> declaration
line 1 column 1 - Warning: plain text isn't allowed in <head> elements
line 1 column 2 - Warning: discarding unexpected <html>
line 2 column 5 - Warning: <body> unexpected or duplicate quote mark
line 2 column 5 - Warning: discarding unexpected <body>
line 4 column 7 - Error: <bdy> is not recognized!
line 4 column 7 - Warning: discarding unexpected <bdy>
line 1 column 1 - Warning: inserting missing 'title' element
line 3 column 7 - Warning: trimming empty <p>
Info: Document content looks like HTML 3.2
8 warnings, 1 error were found!

How can I get Tidy to work with Ale in vim?


Solution

  • You also need to tell vim where to find the tidy executable, e.g., tidy on Linux, or tidy.exe on Windows.

    In my case, I added this to my vimrc:

    let g:ale_html_tidy_executable = "D://TidyHtml//tidy-5.6.0-vc14-64b//bin//tidy.exe"
    

    In vim, to get Ale help for tidy: :h ale-html-tidy