]> git.madduck.net Git - etc/vim.git/blob - autoload/ale/engine/ignore.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 / engine / ignore.vim
1 " Author: w0rp <devw0rp@gmail.com>
2 " Description: Code for ignoring linters. Only loaded and if configured.
3
4 " A map for remapping lspconfig server names to linter names or aliases in
5 " ALE. We should change the names where they will conflict with names in ALE.
6 "
7 " Notes on names from nvim-lspconfig not included here.
8 "
9 " * 'rubocop' is run in a language server mode
10 " * 'eslint' is run via 'vscode-eslint-language-server'
11 let s:lspconfig_map = {
12 \   'als': 'adals',
13 \   'ansiblels': 'ansible-language-server',
14 \   'bicep': 'bicep_language_server',
15 \   'cmake': 'cmake_language_server',
16 \   'denols': 'deno',
17 \   'erlangls': 'erlang_ls',
18 \   'html': 'vscodehtml',
19 \   'ocamlls': 'ocaml-language-server',
20 \   'ols': 'odin-lsp',
21 \   'puppet': 'puppet_languageserver',
22 \}
23
24 " Given a filetype and a configuration for ignoring linters, return a List of
25 " Strings for linter names to ignore.
26 function! ale#engine#ignore#GetList(filetype, config) abort
27     if type(a:config) is v:t_list
28         return a:config
29     endif
30
31     if type(a:config) is v:t_dict
32         let l:names_to_remove = []
33
34         for l:part in split(a:filetype , '\.')
35             call extend(l:names_to_remove, get(a:config, l:part, []))
36         endfor
37
38         return l:names_to_remove
39     endif
40
41     return []
42 endfunction
43
44 " This function can be mocked in tests.
45 function! ale#engine#ignore#GetLSPConfigNames() abort
46     return luaeval('require ''ale.util''.configured_lspconfig_servers()')
47 endfunction
48
49 function! s:GetMappedLSPConfigNames() abort
50     " Check the lspconfig flag before calling luaeval.
51     if !get(g:, 'lspconfig', 0)
52         return []
53     endif
54
55     let l:lspconfig_servers = ale#engine#ignore#GetLSPConfigNames()
56
57     return map(
58     \   !empty(l:lspconfig_servers) ? l:lspconfig_servers : [],
59     \   {_, val -> get(s:lspconfig_map, val, val) }
60     \)
61 endfunction
62
63 " Given a List of linter descriptions, exclude the linters to be ignored.
64 function! ale#engine#ignore#Exclude(filetype, all_linters, config, disable_lsp) abort
65     let l:names_to_remove = ale#engine#ignore#GetList(a:filetype, a:config)
66
67     " If configured to automatically ignore otherwise configured LSP linter
68     " names, add them to the names to remove. This could ignore linters
69     " with matching names that are not marked as LSP linters.
70     if a:disable_lsp is# 'auto'
71         call extend(l:names_to_remove, s:GetMappedLSPConfigNames())
72     endif
73
74     let l:ignore_all_lsps = a:disable_lsp is 1 || a:disable_lsp is v:true
75     let l:filtered_linters = []
76
77     for l:linter in a:all_linters
78         let l:should_include = index(l:names_to_remove, l:linter.name) == -1
79         let l:i = 0
80
81         while l:should_include && l:i < len(l:linter.aliases)
82             let l:name = l:linter.aliases[l:i]
83             let l:should_include = index(l:names_to_remove, l:name) == -1
84             let l:i += 1
85         endwhile
86
87         if l:should_include && l:ignore_all_lsps
88             let l:should_include = empty(get(l:linter, 'lsp'))
89         endif
90
91         if l:should_include
92             call add(l:filtered_linters, l:linter)
93         endif
94     endfor
95
96     return l:filtered_linters
97 endfunction