Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Cppcheck error message #30

Closed
wants to merge 1 commit into from

Conversation

Takishima
Copy link
Contributor

@Takishima Takishima commented Jun 18, 2021

The version of Cppcheck that I currently have on my machine (2.4.1) seems to output everything to the standard error stream. The current code simply resets that stream if some useless parts are found.

This PR addresses this by only deleting the lines that match the useless part predicate. Note that this code would fail if the useless line extends over multiple lines.

Fixes #31

- Newer versions of Cppcheck might output all the errors on stderr
  (tested with Cppcheck 2.4.1)
@JackNewman12
Copy link

JackNewman12 commented Jul 12, 2021

This fix works for me. Thanks.

A few things.

  • The call can be changed so all files are passed into cppcheck in a single run_command() to save some processing. (not sure if this is a pre-commit requirement)
    • given that cppcheck is run over a subset of all the files there will be unused function false positives. I think it makes sense to add --suppress=unusedFunction as a default
  • Instead of ignoring lines about missing includes why not just add the default flag to cppcheck? --suppress=missingIncludeSystem

Note these changes above will also need --suppress=unmatchedSuppression

@pocc
Copy link
Owner

pocc commented Sep 1, 2021

Agreeing that the current logic is kludgy. It sounds like the method proposed by @JackNewman12 is more "correct", so I'm going to add this to the class init function.

    self.add_if_missing(["--suppress=unmatchedSuppression", "--suppress=missingIncludeSystem"])

In terms of combining all files passed, I tried it out, and I don't like the UI. I like focusing on one thing at a time, and clang-tidy, cppcheck, and oclint will show you all the errors without failing fast if all files are passed in.

In your usage, do you use --suppress=unusedFunction in your pre-commit-config because it predictably creates these errors?

@pocc pocc closed this in 1f6d8d2 Sep 1, 2021
@JackNewman12
Copy link

Yes. I add --suppress=unusedFunction for all of my pre-commits since only a subset of files are passed to cppcheck.

@Takishima Takishima deleted the fix/cppcheck-error-message branch September 9, 2021 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants