mirror of
https://github.com/dense-analysis/ale.git
synced 2026-11-19 02:01:03 +08:00
Add linting support for all formats supported by djlint (#4920)
CI / build_image (push) Waiting to run
CI / test_ale (--linters-only) (push) Blocked by required conditions
CI / test_ale (--neovim-07-only) (push) Blocked by required conditions
CI / test_ale (--neovim-08-only) (push) Blocked by required conditions
CI / test_ale (--vim-80-only) (push) Blocked by required conditions
CI / test_ale (--vim-90-only) (push) Blocked by required conditions
CI / build_image (push) Waiting to run
CI / test_ale (--linters-only) (push) Blocked by required conditions
CI / test_ale (--neovim-07-only) (push) Blocked by required conditions
CI / test_ale (--neovim-08-only) (push) Blocked by required conditions
CI / test_ale (--vim-80-only) (push) Blocked by required conditions
CI / test_ale (--vim-90-only) (push) Blocked by required conditions
* Refactor djlint linter code
This patch moves the code to the `autoload` directory, so it's available
when it's needed by a specific linter. This avoids redundant code when
another format supported by djlint is added.
* Add linting support for all formats supported by djlint
So far, the `djlint` linter in ALE only supported `html`, which is only
one of several file types supported by `djlint`.
This patch adds support for the following file types:
* gohtmltmpl
* handlebars
* htmlangular
* htmldjango
* jinja
* nunjucks
* Add djlint fixer for various HTML template formats
* Supported formats:
- html
- htmlangular
- htmldjango
- jinja
- handlebars
- nunjucks
- gohtmltmpl
* Add doc entries
* Add vader tests
---------
Co-authored-by: Adrian Vollmer <computerfluesterer@protonmail.com>
This commit is contained in:
1 parent
fe6a91fb92
commit
47f1f49655
23 files changed
+448
-38
No files matched your search
@@ -0,0 +1,48 @@
|
||||
" Author: Adrian Vollmer (computerfluesterer@protonmail.com)
|
||||
" Description: HTML template formatter using `djlint --reformat`
|
||||
|
||||
call ale#Set('html_djlint_executable', 'djlint')
|
||||
call ale#Set('html_djlint_use_global', get(g:, 'ale_use_global_executables', 0))
|
||||
call ale#Set('html_djlint_options', '')
|
||||
|
||||
function! ale#fixers#djlint#Fix(buffer) abort
|
||||
let l:executable = ale#python#FindExecutable(
|
||||
\ a:buffer,
|
||||
\ 'html_djlint',
|
||||
\ ['djlint']
|
||||
\)
|
||||
|
||||
let l:options = ale#Var(a:buffer, 'html_djlint_options')
|
||||
|
||||
let l:profile = ''
|
||||
let l:filetypes = split(getbufvar(a:buffer, '&filetype'), '\.')
|
||||
|
||||
" Append the --profile flag depending on the current filetype (unless it's
|
||||
" already set in g:html_djlint_options).
|
||||
if match(l:options, '--profile') == -1
|
||||
let l:djlint_profiles = {
|
||||
\ 'html': 'html',
|
||||
\ 'htmldjango': 'django',
|
||||
\ 'jinja': 'jinja',
|
||||
\ 'nunjucks': 'nunjucks',
|
||||
\ 'handlebars': 'handlebars',
|
||||
\ 'gohtmltmpl': 'golang',
|
||||
\ 'htmlangular': 'angular',
|
||||
\}
|
||||
|
||||
for l:filetype in l:filetypes
|
||||
if has_key(l:djlint_profiles, l:filetype)
|
||||
let l:profile = l:djlint_profiles[l:filetype]
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
|
||||
if !empty(l:profile)
|
||||
let l:options = (!empty(l:options) ? l:options . ' ' : '') . '--profile ' . l:profile
|
||||
endif
|
||||
|
||||
return {
|
||||
\ 'command': ale#Escape(l:executable) . ' --reformat ' . l:options . ' -',
|
||||
\}
|
||||
endfunction
|
||||
Reference in new issue
Block a user