enh(ci): add warnings as errors for CppCheck
Description
With sight!736 (closed) ready to be merged, we now can think about enabling warnings as errors for CppCheck, which will ensure no more CppCheck regressions are introduced.
To enable warnings as errors in CppCheck should be as simple as adding a new option --error-exitcode=2
, however we can't possibly simply unconditionally add this option on all CppCheck invocations: We should add a new Sheldon configuration option cppcheck-hook.warnings-as-errors
to handle this, for example enable it for Sight but not for some other projects.
Additionally, for now the configuration options are only written locally, for searching its options, Sheldon uses git config
, which either find result in $REPO_ROOT/.git/config
or $HOME/.gitconfig
. We should add a way for Sheldon to find its option in the versioned repository, eg in $REPO_ROOT/.sheldonconfig
for example. This allows for all developers to have the same configuration when using Sheldon on a given repository.
For convenience and completeness, I'll also add a new option --config
/-o
, which will allow to set an option on the command line. It might be helpful to test a hook without having to modify a configuration file.
Proposal
Optional section to give some functional or technical hints
Functional specifications
- A new configuration option
cppcheck-hook.warnings-as-errors
is added for CppCheck. - Sheldon will also check the repository global configuration file (
$REPO_ROOT/.sheldonconfig
) for options. - A new command line option
--config
/-o
will be added which allow to set an option on the command line.
The check is done in that order, from higher priority to lowest priority: command line (--config
/-o
), global user config ($HOME/.gitconfig
), repository user config ($REPO_ROOT/.git/config
), repository global config ($REPO_ROOT/.sheldonconfig
), default.
Technical specifications
- If
cppcheck-hook.warnings-as-errors
equals totrue
, CppCheck will be called with the option--error-exitcode=2
. - The new option
--config
/-o
will awaits an argument of the formatKEY=VALUE
(for examplecppcheck-hook.warnings-as-errors=true
), which is appended to a list. The list is parsed and transformed into a global dictionary. - When checking for an option, Sheldon will first check if the option exists in the global option dictionary, filled during command line option parsing. If not, it will use
git config
, which will check the global user config ($HOME/.gitconfig
) or the repository user config ($REPO_ROOT/.git/config
). If still not, it will usegit config -f $REPO_ROOT/.sheldonconfig
to check in the repository global config. If still not, the default is used.
Test plan
Describe how you will verify that the implementation fulfils the specifications
Sheldon should fail in CppCheck found an error. The option lookup should works as intended.