Menu

Using --project with a file does not work anymore

2024-06-05
2024-06-05
  • David Daniel

    David Daniel - 2024-06-05

    I was using Cppcheck within my editor (neovim) within my projects building with cross compile builds. I therefore setup compile_commands.json files (I am also using for clangd) and using this with Cppcheck. That way I got the analysis results within the editor.
    This feature is broken, after the last update I get an error message that --project does not work with single files.
    This used to work and now it doesn't anymore. That way I cannot use Cppcheck anymore within my editor, so I ditched the usage of Cppcheck completely.

    Will there be a fix to this?

     
  • Oliver Stöneberg

    It seems there is no documentation on how to set up Cppcheck in neovim. Could you please provide some details on that?

    This was changed because if --project and files were specified at the same time one of them would have been omitted. IIRC based on the options this might not have been consistent either.

    You can see some more comments on how fixing this is not that straight forward here: https://github.com/danmar/cppcheck/pull/6456#issuecomment-2135337081.

     
  • David Daniel

    David Daniel - 2024-06-05

    I will show the configuration I used in neovim. I am using nvim-lint through lazy.
    nvim-lint comes with predefined settings for Cppcheck, I remember having issues with why I modified those a little.

    return {
        'mfussenegger/nvim-lint',
    
        config = function ()
            local lint_parser = require ('lint.parser')
            local lint = require ('lint')
    
            table.insert (lint.linters.cppcheck.args, '--enable=all')
            table.insert (lint.linters.cppcheck.args, '--project=compile_commands.json')
    
            lint.linters.cppcheck.parser = lint_parser.from_pattern (
                                               '([^:]+):(%d+):[^:]*: ([^:]+): (.+)',
                                               {'file', 'lnum', 'severity', 'message'}, nil,
                                               {source = 'cppcheck'})
            lint.linters_by_ft = {
                cpp = {'cppcheck'},
                c = {'cppcheck'}
            }
        end
    }
    

    The above settings might even not be necessary at all but I remember that the default settings for the template uses column which I cannot find in the cppcheck man page. I guess I defined the pattern that way because of the fact that cppcheck does (did) not support that but I might be wrong on that.

    It was not reporting the column but nevertheless it allowed me to quickly identify issues and using the trouble plugin I was able to jump to the line directly.

    Sadly I had to disable it because --project doesn't work anymore - when using cross compilation without telling Cppcheck where to find includes etc. I get tons of false positives and errors.

     

Log in to post a comment.