]> git.madduck.net Git - etc/vim.git/blob - autoload/ale/handlers/djlint.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / autoload / ale / handlers / djlint.vim
1 " Author: Vivian De Smedt <vds2212@gmail.com>, Adrian Vollmer <computerfluesterer@protonmail.com>
2 " Description: Adds support for djlint
3 "
4 function! ale#handlers#djlint#GetExecutable(buffer) abort
5     return ale#Var(a:buffer, 'html_djlint_executable')
6 endfunction
7
8 function! ale#handlers#djlint#GetCommand(buffer) abort
9     let l:executable = ale#handlers#djlint#GetExecutable(a:buffer)
10
11     let l:options = ale#Var(a:buffer, 'html_djlint_options')
12
13     let l:profile = ''
14     let l:filetypes = split(getbufvar(a:buffer, '&filetype'), '\.')
15
16     " Append the --profile flag depending on the current filetype (unless it's
17     " already set in g:html_djlint_options).
18     if match(l:options, '--profile') == -1
19         let l:djlint_profiles = {
20         \    'html': 'html',
21         \    'htmldjango': 'django',
22         \    'jinja': 'jinja',
23         \    'nunjucks': 'nunjucks',
24         \    'handlebars': 'handlebars',
25         \    'gohtmltmpl': 'golang',
26         \    'htmlangular': 'angular',
27         \}
28
29         for l:filetype in l:filetypes
30             if has_key(l:djlint_profiles, l:filetype)
31                 let l:profile = l:djlint_profiles[l:filetype]
32                 break
33             endif
34         endfor
35     endif
36
37     if !empty(l:profile)
38         let l:options = (!empty(l:options) ? l:options . ' ' : '') . '--profile ' . l:profile
39     endif
40
41     return ale#Escape(l:executable)
42     \ . (!empty(l:options) ? ' ' . l:options : '') . ' %s'
43 endfunction
44
45 function! ale#handlers#djlint#Handle(buffer, lines) abort
46     let l:output = []
47     let l:pattern = '\v^([A-Z]\d+) (\d+):(\d+) (.*)$'
48     let l:i = 0
49
50     for l:match in ale#util#GetMatches(a:lines, l:pattern)
51         let l:i += 1
52         let l:item = {
53         \   'lnum': l:match[2] + 0,
54         \   'col': l:match[3] + 0,
55         \   'vcol': 1,
56         \   'text': l:match[4],
57         \   'code': l:match[1],
58         \   'type': 'W',
59         \}
60         call add(l:output, l:item)
61     endfor
62
63     return l:output
64 endfunction