From 7579ce8ba42e40df6d57d0f4c7f3fc1f31c8cd52 Mon Sep 17 00:00:00 2001 From: Lars Toenning Date: Sat, 25 Oct 2025 22:45:55 +0200 Subject: [PATCH] refactor: Fix readability-simplify-boolean-expr --- .clang-tidy | 1 + src/core/application.cpp | 4 +--- src/core/context/contextsimulator.cpp | 3 +-- src/core/fsd/servererror.cpp | 3 +-- src/gui/components/atcstationcomponent.cpp | 3 +-- src/gui/dockwidgetinfoarea.cpp | 6 +----- src/gui/infoarea.cpp | 2 +- src/gui/managedstatusbar.cpp | 2 +- src/gui/models/airlineicaofilter.cpp | 4 ++-- src/gui/models/listmodelbase.cpp | 2 +- src/gui/models/listmodelbasenontemplate.cpp | 2 +- src/gui/models/statusmessagefilter.cpp | 2 +- src/misc/aviation/airlineicaocode.cpp | 3 +-- src/misc/aviation/altitude.cpp | 2 +- src/misc/network/networkutils.cpp | 3 +-- src/misc/network/textmessage.cpp | 6 ++---- src/misc/simulation/fscommon/bcdconversions.cpp | 5 +---- src/misc/valuecache.cpp | 2 +- src/swiftlauncher/swiftlauncher.cpp | 4 ++-- 19 files changed, 22 insertions(+), 37 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 075b1d3a4..febf5ff1e 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -47,6 +47,7 @@ Checks: > readability-redundant-member-init, cppcoreguidelines-init-variables, readability-static-accessed-through-instance, + readability-simplify-boolean-expr, CheckOptions: - key: readability-identifier-naming.ClassCase diff --git a/src/core/application.cpp b/src/core/application.cpp index 996151556..f819c2d54 100644 --- a/src/core/application.cpp +++ b/src/core/application.cpp @@ -405,9 +405,7 @@ namespace swift::core if (CBuildConfig::isLocalDeveloperDebugBuild()) { return true; } const CDistribution d(this->getOwnDistribution()); - if (d.isRestricted() && this->isSet(m_cmdDevelopment)) { return true; } - - return false; + return d.isRestricted() && this->isSet(m_cmdDevelopment); } CStatusMessage CApplication::initLocalSettings() diff --git a/src/core/context/contextsimulator.cpp b/src/core/context/contextsimulator.cpp index 6c5ac459a..8c3b67896 100644 --- a/src/core/context/contextsimulator.cpp +++ b/src/core/context/contextsimulator.cpp @@ -53,7 +53,6 @@ namespace swift::core::context bool IContextSimulator::isSimulatorSimulating() const { - if (!isSimulatorAvailable() || !getSimulatorStatus().testFlag(ISimulator::Simulating)) { return false; } - return true; + return isSimulatorAvailable() && getSimulatorStatus().testFlag(ISimulator::Simulating); } } // namespace swift::core::context diff --git a/src/core/fsd/servererror.cpp b/src/core/fsd/servererror.cpp index 20ea3d9da..02838aa69 100644 --- a/src/core/fsd/servererror.cpp +++ b/src/core/fsd/servererror.cpp @@ -26,8 +26,7 @@ namespace swift::core::fsd ServerErrorCode::AuthTimeout, }; - if (fatalErrors.contains(m_errorNumber)) { return true; } - else { return false; } + return fatalErrors.contains(m_errorNumber); } QStringList ServerError::toTokens() const diff --git a/src/gui/components/atcstationcomponent.cpp b/src/gui/components/atcstationcomponent.cpp index d90e54ef7..cf18baaf8 100644 --- a/src/gui/components/atcstationcomponent.cpp +++ b/src/gui/components/atcstationcomponent.cpp @@ -419,8 +419,7 @@ namespace swift::gui::components bool CAtcStationComponent::canAccessContext() const { - if (!sGui || sGui->isShuttingDown() || !sGui->getIContextNetwork()) { return false; } - return true; + return sGui && !sGui->isShuttingDown() && sGui->getIContextNetwork(); } void CAtcStationComponent::clearOnlineViews() diff --git a/src/gui/dockwidgetinfoarea.cpp b/src/gui/dockwidgetinfoarea.cpp index 7e06e4b86..8727724d3 100644 --- a/src/gui/dockwidgetinfoarea.cpp +++ b/src/gui/dockwidgetinfoarea.cpp @@ -48,11 +48,7 @@ namespace swift::gui if (!this->isVisible()) { return false; } // further checks - if (this->isFloating()) - { - if (this->isMinimized()) { return false; } - return true; - } + if (this->isFloating()) { return !this->isMinimized(); } else { return isSelectedDockWidget(); } } diff --git a/src/gui/infoarea.cpp b/src/gui/infoarea.cpp index c6343d41e..bedf7ece7 100644 --- a/src/gui/infoarea.cpp +++ b/src/gui/infoarea.cpp @@ -543,7 +543,7 @@ namespace swift::gui { if (!sGui || sGui->isShuttingDown()) { return; } this->setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::East); - const bool init = m_tabBar ? false : true; + const bool init = m_tabBar == nullptr; for (int i = 0; i < m_dockWidgetInfoAreas.size(); i++) { diff --git a/src/gui/managedstatusbar.cpp b/src/gui/managedstatusbar.cpp index 6737319fe..449750d07 100644 --- a/src/gui/managedstatusbar.cpp +++ b/src/gui/managedstatusbar.cpp @@ -40,7 +40,7 @@ namespace swift::gui void CManagedStatusBar::initStatusBar(QStatusBar *statusBar) { if (m_statusBar) { return; } - m_ownedStatusBar = statusBar ? false : true; + m_ownedStatusBar = statusBar == nullptr; m_statusBar = statusBar ? statusBar : new QStatusBar(); if (m_statusBar->objectName().isEmpty()) { m_statusBar->setObjectName("sb_ManagedStatusBar"); } diff --git a/src/gui/models/airlineicaofilter.cpp b/src/gui/models/airlineicaofilter.cpp index 0996114d4..11ce149f5 100644 --- a/src/gui/models/airlineicaofilter.cpp +++ b/src/gui/models/airlineicaofilter.cpp @@ -14,8 +14,8 @@ namespace swift::gui::models : m_id(id), m_vDesignator(vDesignator.trimmed().toUpper()), m_name(name.trimmed()), m_countryIso(countryIso.trimmed().toUpper()), m_real(isReal), m_va(isVa) { - this->m_valid = !(m_id < 0 && this->m_countryIso.isEmpty() && this->m_vDesignator.isEmpty() && - this->m_name.isEmpty() && !this->m_va && !this->m_real); + this->m_valid = m_id >= 0 || !this->m_countryIso.isEmpty() || !this->m_vDesignator.isEmpty() || + !this->m_name.isEmpty() || this->m_va || this->m_real; } CAirlineIcaoCodeList CAirlineIcaoFilter::filter(const CAirlineIcaoCodeList &inContainer) const diff --git a/src/gui/models/listmodelbase.cpp b/src/gui/models/listmodelbase.cpp index 84e047d6b..cb7626913 100644 --- a/src/gui/models/listmodelbase.cpp +++ b/src/gui/models/listmodelbase.cpp @@ -112,7 +112,7 @@ namespace swift::gui::models bool CListModelBase::setData(const QModelIndex &index, const QVariant &value, int role) { auto dataRole = static_cast(role); - if (!(dataRole == Qt::UserRole || dataRole == Qt::EditRole)) { return false; } + if (dataRole != Qt::UserRole && dataRole != Qt::EditRole) { return false; } // check / init if (!this->isValidIndex(index)) { return false; } diff --git a/src/gui/models/listmodelbasenontemplate.cpp b/src/gui/models/listmodelbasenontemplate.cpp index 759d1b19e..530007df0 100644 --- a/src/gui/models/listmodelbasenontemplate.cpp +++ b/src/gui/models/listmodelbasenontemplate.cpp @@ -94,7 +94,7 @@ namespace swift::gui::models bool CListModelBaseNonTemplate::hasValidSortColumn() const { - if (!(m_sortColumn >= 0 && m_sortColumn < m_columns.size())) { return false; } + if (m_sortColumn < 0 || m_sortColumn >= m_columns.size()) { return false; } return m_columns.isSortable(m_sortColumn); } diff --git a/src/gui/models/statusmessagefilter.cpp b/src/gui/models/statusmessagefilter.cpp index 0048af5c6..e452a036f 100644 --- a/src/gui/models/statusmessagefilter.cpp +++ b/src/gui/models/statusmessagefilter.cpp @@ -24,7 +24,7 @@ namespace swift::gui::models CStatusMessageList outContainer; for (const CStatusMessage &msg : inContainer) { - if (!(m_severity == CStatusMessage::SeverityInfo || m_severity == CStatusMessage::SeverityDebug)) + if (m_severity != CStatusMessage::SeverityInfo && m_severity != CStatusMessage::SeverityDebug) { if (!msg.isSeverityHigherOrEqual(this->m_severity)) { continue; } } diff --git a/src/misc/aviation/airlineicaocode.cpp b/src/misc/aviation/airlineicaocode.cpp index 4262df24d..0adfbc7f8 100644 --- a/src/misc/aviation/airlineicaocode.cpp +++ b/src/misc/aviation/airlineicaocode.cpp @@ -280,8 +280,7 @@ namespace swift::misc::aviation // allow 2 chars for special codes like "VV" if (airline.length() < 2 || airline.length() > 5) { return false; } const auto chars = makeRange(airline.begin(), airline.end()); - if (chars.containsBy([](QChar c) { return !c.isUpper() && !c.isDigit(); })) { return false; } - return true; + return !chars.containsBy([](QChar c) { return !c.isUpper() && !c.isDigit(); }); } bool CAirlineIcaoCode::isValidIataCode(const QString &iataCode) diff --git a/src/misc/aviation/altitude.cpp b/src/misc/aviation/altitude.cpp index b4d3fdc48..670835630 100644 --- a/src/misc/aviation/altitude.cpp +++ b/src/misc/aviation/altitude.cpp @@ -294,7 +294,7 @@ namespace swift::misc::aviation if (msgs) { msgs->push_back(CStatusMessage(this).validationError(u"Altitude NULL value")); } return false; } - if (!(this->getReferenceDatum() == FlightLevel || this->getReferenceDatum() == MeanSeaLevel)) + if (this->getReferenceDatum() != FlightLevel && this->getReferenceDatum() != MeanSeaLevel) { if (msgs) { msgs->push_back(CStatusMessage(this).validationError(u"Altitude, must be FL or MSL")); } return false; diff --git a/src/misc/network/networkutils.cpp b/src/misc/network/networkutils.cpp index 7d16bcb90..1698336b9 100644 --- a/src/misc/network/networkutils.cpp +++ b/src/misc/network/networkutils.cpp @@ -265,8 +265,7 @@ namespace swift::misc::network bool CNetworkUtils::looksLikePhpErrorMessage(const QString &errorMessage) { if (errorMessage.length() < 50) { return false; } - if (errorMessage.contains("xdebug", Qt::CaseInsensitive)) { return true; } - return false; + return errorMessage.contains("xdebug", Qt::CaseInsensitive); } const QString &CNetworkUtils::networkOperationToString(QNetworkAccessManager::Operation operation) diff --git a/src/misc/network/textmessage.cpp b/src/misc/network/textmessage.cpp index e906c6366..c8310cdf8 100644 --- a/src/misc/network/textmessage.cpp +++ b/src/misc/network/textmessage.cpp @@ -113,13 +113,11 @@ namespace swift::misc::network if (this->getSenderCallsign() != textMessage.getSenderCallsign()) { return false; } if (this->isRadioMessage() && textMessage.isRadioMessage()) { - if (this->getFrequency() != textMessage.getFrequency()) { return false; } - return true; + return this->getFrequency() == textMessage.getFrequency(); } else if (this->isPrivateMessage() && textMessage.isPrivateMessage()) { - if (this->getRecipientCallsign() != textMessage.getRecipientCallsign()) { return false; } - return true; + return this->getRecipientCallsign() == textMessage.getRecipientCallsign(); } return false; } diff --git a/src/misc/simulation/fscommon/bcdconversions.cpp b/src/misc/simulation/fscommon/bcdconversions.cpp index ca701f038..7fbc9d4d0 100644 --- a/src/misc/simulation/fscommon/bcdconversions.cpp +++ b/src/misc/simulation/fscommon/bcdconversions.cpp @@ -32,10 +32,7 @@ namespace swift::misc::simulation::fscommon quint32 remainder = 0, quotient = 0, result = 0; remainder = num % divider; quotient = num / divider; - if (!(quotient == 0 && remainder == 0)) - { - result += hornerScheme(quotient, divider, factor) * factor + remainder; - } + if (quotient != 0 || remainder != 0) { result += hornerScheme(quotient, divider, factor) * factor + remainder; } return result; } } // namespace swift::misc::simulation::fscommon diff --git a/src/misc/valuecache.cpp b/src/misc/valuecache.cpp index 744ec116c..a0c09e3d4 100644 --- a/src/misc/valuecache.cpp +++ b/src/misc/valuecache.cpp @@ -390,7 +390,7 @@ namespace swift::misc auto object = json.object(); json.setObject(it->mergeToMemoizedJson(object)); - if (!(file.seek(0) && file.resize(0) && file.write(json.toJson()) > 0 && file.checkedClose())) + if (!file.seek(0) || !file.resize(0) || file.write(json.toJson()) <= 0 || !file.checkedClose()) { return CStatusMessage(this).error(u"Failed to write to %1: %2") << file.fileName() << file.errorString(); diff --git a/src/swiftlauncher/swiftlauncher.cpp b/src/swiftlauncher/swiftlauncher.cpp index 0ad7f7184..d9da57abe 100644 --- a/src/swiftlauncher/swiftlauncher.cpp +++ b/src/swiftlauncher/swiftlauncher.cpp @@ -371,8 +371,8 @@ void CSwiftLauncher::setDefaults() ui->rb_WindowNormal->setChecked(!setup.useFramelessWindow()); const CLauncherSetup::CoreMode mode = setup.getCoreMode(); - ui->rb_SwiftStandalone->setChecked(mode == CLauncherSetup::Standalone ? true : false); - ui->rb_SwiftDistributed->setChecked(mode == CLauncherSetup::Distributed ? true : false); + ui->rb_SwiftStandalone->setChecked(mode == CLauncherSetup::Standalone); + ui->rb_SwiftDistributed->setChecked(mode == CLauncherSetup::Distributed); const CLauncherSetup::AudioMode audio = setup.getAudioMode(); ui->cb_DisableCoreAudio->setChecked(audio.testFlag(CLauncherSetup::AudioDisableDistributedCoreAudio));