summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/custom/plugins/nvim-lint.lua
blob: beef2559d1312411b39c911e4a2b2b1db4f7b29f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
return {
    'mfussenegger/nvim-lint',
    lazy = false,
    config = function()
        local lint = require('lint')
        lint.linters_by_ft = {
            c = { 'clangtidy' },
            cpp = { 'clangtidy' },
            go = { 'golangcilint' },
            python = { 'flake8' },
            json = { 'jsonlint' },
            bash = { 'shellcheck' },
        }

        vim.api.nvim_create_autocmd({ 'BufEnter', 'BufWritePost', 'InsertLeave', 'TextChanged', 'TextChangedI' }, {
            group = vim.api.nvim_create_augroup('nvim-lint', { clear = true }),
            callback = function()
                require('lint').try_lint()
            end,
        })

        -- NOTE: most if not all of clangt-idy warnings are
        -- also reported by clangd, so this function filters clang-tidy warnings
        -- to avoid duplication of warnings
        local clangtidy_parser = lint.linters.clangtidy.parser
        lint.linters.clangtidy.parser = function(output, bufnr, linter_cwd)
            local diagnostics = clangtidy_parser(output, bufnr, linter_cwd)
            diagnostics = vim.tbl_filter(function(diagnostic)
                if diagnostic.severity == vim.diagnostic.severity.WARN then
                    return false
                end
                if diagnostic.severity == vim.diagnostic.severity.ERROR then
                    return false
                end

                return true
            end, diagnostics)
            return diagnostics
        end
    end,
}