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 #13362: Misra report on command line #7096

Open
wants to merge 36 commits into
base: main
Choose a base branch
from

Conversation

ludviggunne
Copy link
Contributor

WIP. Will add tests and HTML output.

lib/cppcheck.cpp Outdated Show resolved Hide resolved
lib/cppcheck.cpp Outdated Show resolved Hide resolved
lib/errorlogger.cpp Show resolved Hide resolved
lib/cppcheck.cpp Outdated Show resolved Hide resolved
@ludviggunne ludviggunne force-pushed the 13362 branch 3 times, most recently from 70c91e1 to aed1653 Compare December 21, 2024 15:19
@ludviggunne
Copy link
Contributor Author

@firewave I seem to be missing something with the CMake build, could you point me in the right direction? As I understand it all the lib/ sources should be available in the GUI.

/~https://github.com/danmar/cppcheck/actions/runs/12446323642/job/34748592068?pr=7096#step:12:141

@ludviggunne
Copy link
Contributor Author

@firewave I seem to be missing something with the CMake build, could you point me in the right direction? As I understand it all the lib/ sources should be available in the GUI.

/~https://github.com/danmar/cppcheck/actions/runs/12446323642/job/34748592068?pr=7096#step:12:141

Nevermind, found the problem.

Copy link
Owner

@danmar danmar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a line in the releasenotes file also.

lib/checkers.h Outdated Show resolved Hide resolved
lib/utils.cpp Outdated Show resolved Hide resolved
lib/utils.cpp Outdated Show resolved Hide resolved
lib/utils.cpp Outdated Show resolved Hide resolved
@ludviggunne ludviggunne force-pushed the 13362 branch 2 times, most recently from d4e9dec to d337781 Compare January 8, 2025 16:37
@ludviggunne ludviggunne marked this pull request as ready for review January 9, 2025 13:33
lib/checkers.cpp Outdated
@@ -2096,3 +2097,183 @@ std::vector<checkers::Info> checkers::certCppInfo{
{"MSC53-CPP", "L2"},
{"MSC54-CPP", "L2"},
};

namespace checkers {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file is autogenerated so don't change this file. Next time I autogenerate this file to make it uptodate this code will be removed it will be a mess.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a preference for which file these functions should be in?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm ideally I think it would be better if this information was dynamic. cppcheck could fetch the list of checkers from premiumaddon at runtime. but that does not feel like a refactoring you should make in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I'm not sure if we're talking about the same functions. The functions I added don't depend on the premiumCheckers map. Or am I missing something?

Copy link
Owner

@danmar danmar Jan 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a preference for which file these functions should be in?

I suggest that it is added in the ErrorLogger.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been working on moving this logic to ErrorLogger, unfortunatley it seems to be necessary to drag in a bunch of dependencies for the gui tests. Maybe these functions could be in its own file/some other file?

@ludviggunne ludviggunne force-pushed the 13362 branch 3 times, most recently from 2ecfb14 to e997eb9 Compare January 18, 2025 15:18
@@ -1824,6 +1847,15 @@ void CmdLineParser::printHelp() const
" currently only possible to apply the base paths to\n"
" files that are on a lower level in the directory tree.\n"
" --report-progress Report progress messages while checking a file (single job only).\n"
" --report-type=<type> Add guideline and classification fields for specified coding standard.\n"
" The available report types are:\n"
" * normal Default, only show cppcheck error ID and severity)\n"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ")" seems redundant:

Suggested change
" * normal Default, only show cppcheck error ID and severity)\n"
" * normal Default, only show cppcheck error ID and severity\n"

</term>
<listitem>
<para>Add guideline and classification fields for specified coding standard. The available report types are:
<glosslist><glossentry><glossterm>normal</glossterm><glossdef><para>Default, only show cppcheck error ID and severity)</para></glossdef></glossentry><glossentry><glossterm>autosar</glossterm><glossdef><para>Autosar</para></glossdef></glossentry><glossentry><glossterm>certC</glossterm><glossdef><para>Cert C</para></glossdef></glossentry><glossentry><glossterm>certCpp</glossterm><glossdef><para>Cert Cpp</para></glossdef></glossentry><glossentry><glossterm>misraC</glossterm><glossdef><para>Misra C</para></glossdef></glossentry><glossentry><glossterm>misraCpp2008</glossterm><glossdef><para>Misra C++ 2008</para></glossdef></glossentry><glossentry><glossterm>misraCpp2023</glossterm><glossdef><para>Misra C++ 2023</para></glossdef></glossentry></glosslist>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm I would rather add some newlines here I think if each option was on a separate line that would be more readable.

*/
CPPCHECKLIB std::vector<std::string> splitString(const std::string& str, char sep);
template<template<class ...> class T = std::vector>
T<std::string> splitString(const std::string& str, char sep)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I see T is always std::vector so I don't see a good reason to make it a template.

@@ -28,6 +28,7 @@
#include "platform.h"
#include "standards.h"
#include "suppressions.h"
#include "errorlogger.h"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't have to include errorlogger.h here. As far as I see you can have a forward declaration of ReportType in settings.h and initialize the Settings::reportType in the constructor. That would probably reduce the dependencies.

ReportType reportType = ReportType::normal;

/** @brief Maps cppcheck error ids to guidelines */
std::map<std::string, std::string> guidelineMapping;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

basically if this guidelineMapping map is created and used in ErrorLogger only it feels like it should be in ErrorLogger. But I don't know if there are problems to move it?

@@ -22,6 +22,7 @@

#include "report.h"
#include "showtypes.h"
#include "common.h"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems unfortunate to replace the forward declaration with a include here.

@@ -24,6 +24,8 @@
#include <QMap>
#include <QString>

#include "errorlogger.h"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a feeling that maybe it's better that errorlogger.h is included explicitly when needed.

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