mfussenegger / nvim-lint

An asynchronous linter plugin for Neovim complementary to the built-in Language Server Protocol support.
GNU General Public License v3.0
1.88k stars 198 forks source link

Cppcheck v2.12.0 failing #492

Closed tomhampshire closed 3 weeks ago

tomhampshire commented 8 months ago

Recent versions of Cppcheck (v2.12.0) are failing with nvim-lint

kapkanov commented 8 months ago

I'm going to describe my problem and a solution of it, I hope it'll help you

My setup

Problem

No inline diagnostics, only the message Linter command 'cppcheck' exited with code: 1 on the nvim output panel

Solution

nvim-lint passes --cppcheck-build-dir=build to the cppcheck command, so after I've created a build directory within the same directory where the C source file is located, the diagnostics appeared. You can change the passed arguments to suite your needs of course

ismasou commented 7 months ago

I was able to fix this by checking in the linter itself if the build directory exists:

                args = {
                    "--enable=warning,style,performance,information",
                    function()
                        if vim.bo.filetype == "cpp" then
                            return "--language=c++"
                        else
                            return "--language=c"
                        end
                    end,
                    "--inline-suppr",
                    "--quiet",
                    function()
                        if vim.fn.isdirectory("build") == 1 then
                            return "--cppcheck-build-dir=build"
                        else
                            return ""
                        end
                    end,
                    "--template={file}:{line}:{column}: [{id}] {severity}: {message}",
                },
mfussenegger commented 7 months ago

@ismasou could you create a PR for that change?