Skip to content

Commit

Permalink
Fix #12798: Add inline supression to projectDialog (danmar#6453)
Browse files Browse the repository at this point in the history
  • Loading branch information
olabetskyi committed May 31, 2024
1 parent 22477ef commit 886e306
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 1 deletion.
5 changes: 4 additions & 1 deletion gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,8 @@ QPair<bool,Settings> MainWindow::getCppcheckSettings()
QStringList dirs = mProjectFile->getIncludeDirs();
addIncludeDirs(dirs, result);

result.inlineSuppressions = mProjectFile->getInlineSuppression();

const QStringList defines = mProjectFile->getDefines();
for (const QString& define : defines) {
if (!result.userDefines.empty())
Expand Down Expand Up @@ -1111,6 +1113,8 @@ QPair<bool,Settings> MainWindow::getCppcheckSettings()
result.setMisraRuleTexts(CheckThread::executeCommand);
}
}
else
result.inlineSuppressions = mSettings->value(SETTINGS_INLINE_SUPPRESSIONS, false).toBool();

// Include directories (and files) are searched in listed order.
// Global include directories must be added AFTER the per project include
Expand All @@ -1135,7 +1139,6 @@ QPair<bool,Settings> MainWindow::getCppcheckSettings()
result.force = mSettings->value(SETTINGS_CHECK_FORCE, 1).toBool();
result.xml = false;
result.jobs = mSettings->value(SETTINGS_CHECK_THREADS, 1).toInt();
result.inlineSuppressions = mSettings->value(SETTINGS_INLINE_SUPPRESSIONS, false).toBool();
result.certainty.setEnabled(Certainty::inconclusive, mSettings->value(SETTINGS_INCONCLUSIVE_ERRORS, false).toBool());
if (!mProjectFile || result.platform.type == Platform::Type::Unspecified)
result.platform.set((Platform::Type) mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt());
Expand Down
8 changes: 8 additions & 0 deletions gui/projectfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void ProjectFile::clear()
mAnalyzeAllVsConfigs = false;
mCheckHeaders = true;
mCheckUnusedTemplates = true;
mInlineSuppression = true;
mMaxCtuDepth = settings.maxCtuDepth;
mMaxTemplateRecursion = settings.maxTemplateRecursion;
mCheckUnknownFunctionReturn.clear();
Expand Down Expand Up @@ -143,6 +144,9 @@ bool ProjectFile::read(const QString &filename)
if (xmlReader.name() == QString(CppcheckXml::CheckUnusedTemplatesElementName))
mCheckUnusedTemplates = readBool(xmlReader);

if (xmlReader.name() == QString(CppcheckXml::InlineSuppression))
mInlineSuppression = readBool(xmlReader);

if (xmlReader.name() == QString(CppcheckXml::CheckLevelExhaustiveElementName))
mCheckLevel = CheckLevel::exhaustive;

Expand Down Expand Up @@ -873,6 +877,10 @@ bool ProjectFile::write(const QString &filename)
xmlWriter.writeCharacters(bool_to_string(mCheckUnusedTemplates));
xmlWriter.writeEndElement();

xmlWriter.writeStartElement(CppcheckXml::InlineSuppression);
xmlWriter.writeCharacters(bool_to_string(mInlineSuppression));
xmlWriter.writeEndElement();

xmlWriter.writeStartElement(CppcheckXml::MaxCtuDepthElementName);
xmlWriter.writeCharacters(QString::number(mMaxCtuDepth));
xmlWriter.writeEndElement();
Expand Down
13 changes: 13 additions & 0 deletions gui/projectfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ class ProjectFile : public QObject {
mCheckUnusedTemplates = b;
}

bool getInlineSuppression() const {
return mInlineSuppression;
}

void setInlineSuppression(bool b) {
mInlineSuppression = b;
}

/**
* @brief Get list of include directories.
* @return list of directories.
Expand Down Expand Up @@ -557,6 +565,11 @@ class ProjectFile : public QObject {
/** Check code in unused templates */
bool mCheckUnusedTemplates;

/**
* @brief Enable inline suppression.
*/
bool mInlineSuppression;

/**
* @brief List of include directories used to search include files.
*/
Expand Down
7 changes: 7 additions & 0 deletions gui/projectfile.ui
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,13 @@
</layout>
</widget>
</item>
<item>
<widget class="QCheckBox" name="mInlineSuppressions">
<property name="text">
<string>Enable inline suppressions</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_9">
<property name="orientation">
Expand Down
2 changes: 2 additions & 0 deletions gui/projectfiledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ void ProjectFileDialog::loadFromProjectFile(const ProjectFile *projectFile)
mUI->mCheckLevelNormal->setChecked(true);
mUI->mCheckHeaders->setChecked(projectFile->getCheckHeaders());
mUI->mCheckUnusedTemplates->setChecked(projectFile->getCheckUnusedTemplates());
mUI->mInlineSuppressions->setChecked(projectFile->getInlineSuppression());
mUI->mMaxCtuDepth->setValue(projectFile->getMaxCtuDepth());
mUI->mMaxTemplateRecursion->setValue(projectFile->getMaxTemplateRecursion());
if (projectFile->clangParser)
Expand Down Expand Up @@ -435,6 +436,7 @@ void ProjectFileDialog::saveToProjectFile(ProjectFile *projectFile) const
projectFile->setVSConfigurations(getProjectConfigurations());
projectFile->setCheckHeaders(mUI->mCheckHeaders->isChecked());
projectFile->setCheckUnusedTemplates(mUI->mCheckUnusedTemplates->isChecked());
projectFile->setInlineSuppression(mUI->mInlineSuppressions->isChecked());
projectFile->setMaxCtuDepth(mUI->mMaxCtuDepth->value());
projectFile->setMaxTemplateRecursion(mUI->mMaxTemplateRecursion->value());
projectFile->setIncludes(getIncludePaths());
Expand Down
15 changes: 15 additions & 0 deletions gui/test/projectfile/testprojectfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,21 @@ void TestProjectFile::getAddonFilePath() const
QCOMPARE(ProjectFile::getAddonFilePath(tempdir.path(), filepath), filepath);
}

void TestProjectFile::getInlineSuppressionDefaultValue() const
{
ProjectFile projectFile;
projectFile.setFilename("/some/path/123.cppcheck");
QCOMPARE(projectFile.getInlineSuppression(), true);
}

void TestProjectFile::getInlineSuppression() const
{
ProjectFile projectFile;
projectFile.setFilename("/some/path/123.cppcheck");
projectFile.setInlineSuppression(false);
QCOMPARE(projectFile.getInlineSuppression(), false);
}

void TestProjectFile::getCheckingSuppressionsRelative() const
{
const SuppressionList::Suppression suppression("*", "externals/*");
Expand Down
3 changes: 3 additions & 0 deletions gui/test/projectfile/testprojectfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ private slots:

void getAddonFilePath() const;

void getInlineSuppressionDefaultValue() const;
void getInlineSuppression() const;

void getCheckingSuppressionsRelative() const;
void getCheckingSuppressionsAbsolute() const;
void getCheckingSuppressionsStar() const;
Expand Down
3 changes: 3 additions & 0 deletions lib/importproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,8 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings *setti
checkLevelExhaustive = true;
else if (strcmp(node->Name(), CppcheckXml::CheckUnusedTemplatesElementName) == 0)
temp.checkUnusedTemplates = (strcmp(readSafe(node->GetText(), ""), "true") == 0);
else if (strcmp(node->Name(), CppcheckXml::InlineSuppression) == 0)
temp.inlineSuppressions = (strcmp(readSafe(node->GetText(), ""), "true") == 0);
else if (strcmp(node->Name(), CppcheckXml::MaxCtuDepthElementName) == 0)
temp.maxCtuDepth = strToInt<int>(readSafe(node->GetText(), "2")); // TODO: bail out when missing?
else if (strcmp(node->Name(), CppcheckXml::MaxTemplateRecursionElementName) == 0)
Expand Down Expand Up @@ -1284,6 +1286,7 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings *setti
settings->checkUnusedTemplates = temp.checkUnusedTemplates;
settings->maxCtuDepth = temp.maxCtuDepth;
settings->maxTemplateRecursion = temp.maxTemplateRecursion;
settings->inlineSuppressions |= temp.inlineSuppressions;
settings->safeChecks = temp.safeChecks;

if (checkLevelExhaustive)
Expand Down
1 change: 1 addition & 0 deletions lib/importproject.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ namespace CppcheckXml {
static constexpr char MaxCtuDepthElementName[] = "max-ctu-depth";
static constexpr char MaxTemplateRecursionElementName[] = "max-template-recursion";
static constexpr char CheckUnknownFunctionReturn[] = "check-unknown-function-return-values";
static constexpr char InlineSuppression[] = "inline-suppression";
static constexpr char ClangTidy[] = "clang-tidy";
static constexpr char Name[] = "name";
static constexpr char VSConfigurationElementName[] = "vs-configurations";
Expand Down
2 changes: 2 additions & 0 deletions test/testimportproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ class TestImportProject : public TestFixture {
" <exclude>\n"
" <path name=\"gui/temp/\"/>\n"
" </exclude>\n"
" <inline-suppression>true</inline-suppression>\n"
" <project-name>test test</project-name>\n"
"</project>\n";
std::istringstream istr(xml);
Expand All @@ -368,6 +369,7 @@ class TestImportProject : public TestFixture {
ASSERT_EQUALS("cli/", project.guiProject.pathNames[0]);
ASSERT_EQUALS(1, s.includePaths.size());
ASSERT_EQUALS("lib/", s.includePaths.front());
ASSERT_EQUALS(true, s.inlineSuppressions);
}

void ignorePaths() const {
Expand Down

0 comments on commit 886e306

Please sign in to comment.