Skip to content

Commit e4783c8

Browse files
committed
feat(clazy): enforce clazy level 0 and use CI to check for it
added some exceptions Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
1 parent 8accfbf commit e4783c8

148 files changed

Lines changed: 642 additions & 538 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/linux-clang-compile-tests.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,18 @@ jobs:
2323
run: |
2424
mkdir build
2525
cd build
26-
cmake .. -G Ninja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Debug -DQT_MAJOR_VERSION=6 -DQUICK_COMPILER=ON -DBUILD_UPDATER=ON -DBUILD_TESTING=1 -DCMAKE_CXX_FLAGS=-Werror -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
26+
cmake .. -G Ninja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Debug -DQT_MAJOR_VERSION=6 -DQUICK_COMPILER=ON -DBUILD_UPDATER=ON -DBUILD_TESTING=1 -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_CXX_FLAGS="-Werror -Xclang -load -Xclang ClazyPlugin.so -Xclang -add-plugin -Xclang clazy -Xclang -plugin-arg-clazy -Xclang level0,detaching-temporary"
2727
ninja
2828
- name: Run tests
2929
run: |
3030
cd build
3131
useradd -m -s /bin/bash test
3232
chown -R test:test .
3333
su -c 'xvfb-run ctest --output-on-failure' test
34-
- name: Analyze changed C++ code with clang-tidy
34+
- name: Analyze C++ code with clang-tidy
3535
run: |
3636
mkdir clang-tidy-result
37-
/usr/bin/git config --global --add safe.directory "$GITHUB_WORKSPACE"
38-
# Header-only test helper: clang-tidy-diff has no target compile command for it.
39-
# Its consumer test targets compile it with the required GUI include paths.
40-
/usr/bin/git diff -U0 HEAD^ -- ':(exclude)test/macOS/*' ':(exclude)test/systraysynccontroltesthelper.h' ':(exclude)*macOS*' | clang-tidy-diff-21.py -checks='-*,modernize-use-auto,modernize-use-using,modernize-use-nodiscard,modernize-use-nullptr,modernize-use-override,cppcoreguidelines-pro-type-static-cast-downcast' -p1 -path build -regex '^(?!.*/macOS/)(?!.*/MacOSX/).*\.(cpp|cc|cxx|c|h|hpp|hxx)$' -export-fixes clang-tidy-result/fixes.yml
37+
run-clang-tidy -p build -header-filter='.*' -config-file .clang-tidy -export-fixes clang-tidy-result/fixes.yml || true
4138
- name: Publish clang-tidy review
4239
uses: platisd/clang-tidy-pr-comments@28cfb84edafa771c044bde7e4a2a3fae57463818 # v1.6.1 # >1.4.3 switches to composite method w/ a forced python version and breaks things: https://github.com/actions/setup-python/issues/871
4340
with:

shell_integration/dolphin/ownclouddolphinactionplugin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class OwncloudDolphinPluginAction : public KAbstractFileItemActionPlugin
5555

5656
auto menu = new QMenu(parentWidget);
5757
QEventLoop loop;
58-
auto con = connect(helper, &OwncloudDolphinPluginHelper::commandRecieved, this, [&](const QByteArray &cmd) {
58+
auto con = connect(helper, &OwncloudDolphinPluginHelper::commandRecieved, &loop, [&](const QByteArray &cmd) {
5959
if (cmd.startsWith("GET_MENU_ITEMS:END")) {
6060
loop.quit();
6161
} else if (cmd.startsWith("MENU_ITEM:")) {
@@ -68,7 +68,7 @@ class OwncloudDolphinPluginAction : public KAbstractFileItemActionPlugin
6868
action->setDisabled(true);
6969
}
7070
auto call = args.value(1).toLatin1();
71-
connect(action, &QAction::triggered, [helper, call, files] {
71+
connect(action, &QAction::triggered, &loop, [helper, call, files] {
7272
helper->sendCommand(QByteArray(call + ":" + files + "\n").constData());
7373
});
7474
}

shell_integration/dolphin/ownclouddolphinoverlayplugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class OwncloudDolphinPlugin : public KOverlayIconPlugin
4141

4242
helper->sendCommand(QByteArray("RETRIEVE_FILE_STATUS:" + localFile + "\n").constData());
4343

44-
StatusMap::iterator it = m_status.find(localFile);
44+
const auto it = std::as_const(m_status).find(localFile);
4545
if (it != m_status.constEnd()) {
4646
return overlaysForString(*it);
4747
}

src/3rdparty/kirigami/wheelhandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <QPoint>
1111
#include <QQuickItem>
1212
#include <QStyleHints>
13-
#include <QtQml>
13+
#include <QTimer>
1414

1515
class QWheelEvent;
1616
class WheelHandler;

src/3rdparty/kmessagewidget/kmessagewidget.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -190,21 +190,19 @@ void KMessageWidgetPrivate::applyStyleSheet()
190190

191191
const QColor bgFinalColor = QColor(newRed, newGreen, newBlue);
192192

193-
content->setStyleSheet(
194-
QString::fromLatin1(".QFrame {"
195-
"background-color: %1;"
196-
"border-radius: 4px;"
197-
"border: 2px solid %2;"
198-
"margin: %3px;"
199-
"}"
200-
".QLabel { color: %4; }"
201-
)
202-
.arg(bgFinalColor.name())
203-
.arg(border.name())
204-
// DefaultFrameWidth returns the size of the external margin + border width. We know our border is 1px, so we subtract this from the frame normal QStyle FrameWidth to get our margin
205-
.arg(q->style()->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, q) - 1)
206-
.arg(textColor.name())
207-
);
193+
content->setStyleSheet(QString::fromLatin1(".QFrame {"
194+
"background-color: %1;"
195+
"border-radius: 4px;"
196+
"border: 2px solid %2;"
197+
"margin: %3px;"
198+
"}"
199+
".QLabel { color: %4; }")
200+
.arg(bgFinalColor.name(),
201+
border.name(),
202+
// DefaultFrameWidth returns the size of the external margin + border width. We know our border is 1px, so we subtract this
203+
// from the frame normal QStyle FrameWidth to get our margin
204+
QString::number(q->style()->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, q) - 1),
205+
textColor.name()));
208206
}
209207

210208
void KMessageWidgetPrivate::updateLayout()

src/cmd/cmd.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -581,18 +581,18 @@ int main(int argc, char **argv)
581581
QEventLoop loop;
582582
auto *csjob = new CheckServerJob(account);
583583
csjob->setIgnoreCredentialFailure(true);
584-
QObject::connect(csjob, &CheckServerJob::instanceFound, [&](const QUrl &, const QJsonObject &info) {
584+
QObject::connect(csjob, &CheckServerJob::instanceFound, &loop, [&](const QUrl &, const QJsonObject &info) {
585585
// see ConnectionValidator::slotCapabilitiesRecieved: only set server version if not empty
586586
QString serverVersion = CheckServerJob::version(info);
587587
if (!serverVersion.isEmpty()) {
588588
account->setServerVersion(serverVersion);
589589
}
590590
loop.quit();
591591
});
592-
QObject::connect(csjob, &CheckServerJob::instanceNotFound, [&]() {
592+
QObject::connect(csjob, &CheckServerJob::instanceNotFound, &loop, [&]() {
593593
loop.quit();
594594
});
595-
QObject::connect(csjob, &CheckServerJob::timeout, [&](const QUrl &) {
595+
QObject::connect(csjob, &CheckServerJob::timeout, &loop, [&](const QUrl &) {
596596
loop.quit();
597597
});
598598
csjob->start();
@@ -604,12 +604,12 @@ int main(int argc, char **argv)
604604
}
605605

606606
auto *job = new JsonApiJob(account, QLatin1String("ocs/v1.php/cloud/capabilities"));
607-
QObject::connect(job, &JsonApiJob::jsonReceived, [&](const QJsonDocument &json) {
607+
QObject::connect(job, &JsonApiJob::jsonReceived, &loop, [&](const QJsonDocument &json) {
608608
auto caps = json.object().value("ocs").toObject().value("data").toObject().value("capabilities").toObject();
609609
qDebug() << "Server capabilities" << caps;
610610
account->setCapabilities(caps.toVariantMap());
611611
// see ConnectionValidator::slotCapabilitiesRecieved: only set server version if not empty
612-
QString serverVersion = caps["core"].toObject()["status"].toObject()["version"].toString();
612+
QString serverVersion = caps["core"].toObject().value("status").toObject().value("version").toString();
613613
if (!serverVersion.isEmpty()) {
614614
account->setServerVersion(serverVersion);
615615
}
@@ -624,7 +624,7 @@ int main(int argc, char **argv)
624624
}
625625

626626
job = new JsonApiJob(account, QLatin1String("ocs/v1.php/cloud/user"));
627-
QObject::connect(job, &JsonApiJob::jsonReceived, [&](const QJsonDocument &json) {
627+
QObject::connect(job, &JsonApiJob::jsonReceived, &loop, [&](const QJsonDocument &json) {
628628
const QJsonObject data = json.object().value("ocs").toObject().value("data").toObject();
629629
account->setDavUser(data.value("id").toString());
630630
account->setDavDisplayName(data.value("display-name").toString());
@@ -648,7 +648,9 @@ int main(int argc, char **argv)
648648
qCritical() << "Could not open file containing the list of unsynced folders: " << options.unsyncedfolders;
649649
} else {
650650
// filter out empty lines and comments
651-
selectiveSyncList = QString::fromUtf8(f.readAll()).split('\n').filter(QRegularExpression("\\S+")).filter(QRegularExpression("^[^#]"));
651+
static const auto filterComments = QRegularExpression("^[^#]");
652+
static const auto filterEmptyLines = QRegularExpression("\\S+");
653+
selectiveSyncList = QString::fromUtf8(f.readAll()).split('\n').filter(filterEmptyLines).filter(filterComments);
652654

653655
for (int i = 0; i < selectiveSyncList.count(); ++i) {
654656
if (!selectiveSyncList.at(i).endsWith(QLatin1Char('/'))) {

src/cmd/netrcparser.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ bool NetrcParser::parse()
5252
return false;
5353
}
5454

55-
auto tokens = content.split(QRegularExpression("\\s+"));
55+
static const auto splitRegexp = QRegularExpression("\\s+");
56+
auto tokens = content.split(splitRegexp);
5657

5758
LoginPair pair;
5859
QString machine;
@@ -92,7 +93,7 @@ bool NetrcParser::parse()
9293

9394
NetrcParser::LoginPair NetrcParser::find(const QString &machine)
9495
{
95-
QHash<QString, LoginPair>::const_iterator it = _entries.find(machine);
96+
const auto it = _entries.find(machine);
9697
if (it != _entries.end()) {
9798
return *it;
9899
} else {

src/common/syncjournaldb.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ bool SyncJournalDb::updateMetadataTableStructure()
774774
const auto addColumn = [this, &re, &columnExists] (const QString &columnName, const QString &dataType, const bool withIndex = false, const QString defaultCommand = {}) {
775775
if (!columnExists(columnName)) {
776776
SqlQuery query(_db);
777-
auto request = QStringLiteral("ALTER TABLE metadata ADD COLUMN %1 %2").arg(columnName).arg(dataType);
777+
auto request = QStringLiteral("ALTER TABLE metadata ADD COLUMN %1 %2").arg(columnName, dataType);
778778
if (!defaultCommand.isEmpty()) {
779779
request.append(QStringLiteral(" ") + defaultCommand);
780780
}

src/common/vfs.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ bool Vfs::setPinStateInDb(const QString &folderPath, PinState state)
9090
auto path = folderPath.toUtf8();
9191
_setupParams.journal->internalPinStates().wipeForPathAndBelow(path);
9292
if (state != PinState::Inherited) {
93-
_setupParams.journal->internalPinStates().setForPath(path, state);
93+
auto pinState = _setupParams.journal->internalPinStates();
94+
pinState.setForPath(path, state);
9495
}
9596
return true;
9697
}

src/gui/UserStatusSetStatusView.qml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,61 +47,61 @@ ColumnLayout {
4747

4848
UserStatusSelectorButton {
4949
enabled: root.userStatusLoaded
50-
checked: root.userStatusLoaded && userStatusSelectorModel.onlineStatus === NC.userStatus.Online
50+
checked: root.userStatusLoaded && userStatusSelectorModel.onlineStatus === NC.UserStatus.Online
5151
checkable: true
5252
icon.source: userStatusSelectorModel ? userStatusSelectorModel.onlineIcon : ""
5353
icon.color: "transparent"
5454
text: qsTr("Online")
5555
Layout.fillWidth: true
56-
onClicked: handleStatusClick(NC.userStatus.Online)
56+
onClicked: handleStatusClick(NC.UserStatus.Online)
5757
}
5858

5959
UserStatusSelectorButton {
6060
enabled: root.userStatusLoaded
61-
checked: root.userStatusLoaded && userStatusSelectorModel.onlineStatus === NC.userStatus.Away
61+
checked: root.userStatusLoaded && userStatusSelectorModel.onlineStatus === NC.UserStatus.Away
6262
checkable: true
6363
icon.source: userStatusSelectorModel ? userStatusSelectorModel.awayIcon : ""
6464
icon.color: "transparent"
6565
text: qsTr("Away")
6666
Layout.fillWidth: true
67-
onClicked: handleStatusClick(NC.userStatus.Away)
67+
onClicked: handleStatusClick(NC.UserStatus.Away)
6868
}
6969

7070
UserStatusSelectorButton {
7171
visible: userStatusSelectorModel && userStatusSelectorModel.busyStatusSupported
7272
enabled: root.userStatusLoaded
73-
checked: root.userStatusLoaded && userStatusSelectorModel.onlineStatus === NC.userStatus.Busy
73+
checked: root.userStatusLoaded && userStatusSelectorModel.onlineStatus === NC.UserStatus.Busy
7474
checkable: true
7575
icon.source: userStatusSelectorModel ? userStatusSelectorModel.busyIcon : ""
7676
icon.color: "transparent"
7777
text: qsTr("Busy")
7878
Layout.fillWidth: true
79-
onClicked: handleStatusClick(NC.userStatus.Busy)
79+
onClicked: handleStatusClick(NC.UserStatus.Busy)
8080
}
8181

8282
UserStatusSelectorButton {
8383
enabled: root.userStatusLoaded
84-
checked: root.userStatusLoaded && userStatusSelectorModel.onlineStatus === NC.userStatus.DoNotDisturb
84+
checked: root.userStatusLoaded && userStatusSelectorModel.onlineStatus === NC.UserStatus.DoNotDisturb
8585
checkable: true
8686
icon.source: userStatusSelectorModel ? userStatusSelectorModel.dndIcon : ""
8787
icon.color: "transparent"
8888
text: qsTr("Do not disturb")
8989
secondaryText: qsTr("Mute all notifications")
9090
Layout.fillWidth: true
91-
onClicked: handleStatusClick(NC.userStatus.DoNotDisturb)
91+
onClicked: handleStatusClick(NC.UserStatus.DoNotDisturb)
9292
}
9393

9494
UserStatusSelectorButton {
9595
enabled: root.userStatusLoaded
96-
checked: root.userStatusLoaded && (userStatusSelectorModel.onlineStatus === NC.userStatus.Invisible
97-
|| userStatusSelectorModel.onlineStatus === NC.userStatus.Offline)
96+
checked: root.userStatusLoaded && (userStatusSelectorModel.onlineStatus === NC.UserStatus.Invisible
97+
|| userStatusSelectorModel.onlineStatus === NC.UserStatus.Offline)
9898
checkable: true
9999
icon.source: userStatusSelectorModel ? userStatusSelectorModel.invisibleIcon : ""
100100
icon.color: "transparent"
101101
text: qsTr("Invisible")
102102
secondaryText: qsTr("Appear offline")
103103
Layout.fillWidth: true
104-
onClicked: handleStatusClick(NC.userStatus.Invisible)
104+
onClicked: handleStatusClick(NC.UserStatus.Invisible)
105105
}
106106

107107
Item {

0 commit comments

Comments
 (0)