Verified Commit fd816d68 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖
Browse files

clang-tidy configuration and auto-fixes

parent 2e1e1408
# clang-analyzer-cplusplus.NewDeleteLeaks triggers false-positives in QObject::connect()
# readability-redundant-access-specifiers triggered by Q_SLOTS
# readability-inconsistent-declaration-parameter-name trigered by generated Qt code
# performance-no-automatic-move is triggered by constness of qstring_literal_tmp in QStringLiteral macro
Checks: -*
clang-analyzer-*,
-clang-analyzer-osx,
-clang-analyzer-cplusplus.NewDeleteLeaks,
google-explicit-constructor,
google-global-names-in-headers,
hicpp-signed-bitwise,
misc-*,
-misc-definitions-in-headers,
-*-non-private-member-variables-in-classes,
performance-*,
-performance-no-automatic-move,
readability-*,
-readability-avoid-const-params-in-decls,
-readability-convert-member-functions-to-static,
-readability-else-after-return,
-readability-redundant-access-specifiers,
-readability-implicit-bool-conversion,
-readability-static-accessed-through-instance,
-readability-inconsistent-declaration-parameter-name
AnalyzeTemporaryDtors: true
CheckOptions:
- key: bugprone-assert-side-effects.AssertMacros
value: 'Q_ASSERT'
- key: CheckFunctionCalls
value: true
# Same base checks as in top-level .clang-tidy, but with some additional
# checks disabled to give us some leeway in autotests (e.g. no magic numbers)
Checks: -*
clang-analyzer-*,
-clang-analyzer-osx,
-clang-analyzer-cplusplus.NewDeleteLeaks,
google-explicit-constructor,
google-global-names-in-headers,
hicpp-signed-bitwise,
misc-*,
-misc-definitions-in-headers,
-*-non-private-member-variables-in-classes,
performance-*,
-performance-no-automatic-move,
readability-*,
-readability-avoid-const-params-in-decls,
-readability-convert-member-functions-to-static,
-readability-else-after-return,
-readability-redundant-access-specifiers,
-readability-implicit-bool-conversion,
-readability-static-accessed-through-instance,
-readability-inconsistent-declaration-parameter-name,
-readability-magic-numbers
AnalyzeTemporaryDtors: true
CheckOptions:
- key: bugprone-assert-side-effects.AssertMacros
value: 'Q_ASSERT'
- key: CheckFunctionCalls
value: true
......@@ -37,7 +37,7 @@ class ActionStateManagerTest;
class UnitActionStateManager : public ActionStateManager
{
public:
UnitActionStateManager(ActionStateManagerTest *receiver);
explicit UnitActionStateManager(ActionStateManagerTest *receiver);
protected:
bool hasResourceCapability(const Collection &collection, const QString &capability) const override;
......@@ -568,8 +568,10 @@ private Q_SLOTS:
UnitActionStateManager manager(this);
Collection::List favoriteCollections;
if (collections.contains(folderCollectionThree))
if (collections.contains(folderCollectionThree)) {
favoriteCollections << folderCollectionThree;
}
manager.updateState(collections, favoriteCollections, Item::List());
QCOMPARE(stateMap.count(), mStateMap.count());
......@@ -580,8 +582,9 @@ private Q_SLOTS:
//qDebug() << it.key();
QVERIFY(mStateMap.contains(it.key()));
const bool expected = mStateMap.value(it.key());
if (it.value() != expected)
if (it.value() != expected) {
qWarning() << "Wrong state for" << it.key();
}
QCOMPARE(it.value(), expected);
}
}
......
......@@ -39,11 +39,9 @@ QTEST_AKONADIMAIN(CollectionAttributeTest)
class TestAttribute : public Attribute
{
public:
TestAttribute()
: Attribute()
{
}
TestAttribute(const QByteArray &data)
TestAttribute() = default;
explicit TestAttribute(const QByteArray &data)
: mData(data)
{
}
......@@ -106,7 +104,7 @@ void CollectionAttributeTest::testAttributes()
QFETCH(QByteArray, attr2);
struct Cleanup {
Cleanup(const Collection &col) : m_col(col) {}
explicit Cleanup(const Collection &col) : m_col(col) {}
~Cleanup() {
// cleanup
CollectionDeleteJob *del = new CollectionDeleteJob(m_col);
......
......@@ -173,12 +173,12 @@ class ResultSignalTester : public QObject
public:
QStringList receivedSignals;
public Q_SLOTS:
void onCollectionsReceived(const Akonadi::Collection::List &)
void onCollectionsReceived(const Akonadi::Collection::List & /*unused*/)
{
receivedSignals << QStringLiteral("collectionsReceived");
}
void onCollectionRetrievalDone(KJob *)
void onCollectionRetrievalDone(KJob * /*unused*/)
{
receivedSignals << QStringLiteral("result");
}
......@@ -420,8 +420,8 @@ void CollectionJobTest::testStatistics()
AKVERIFYEXEC(statistics);
CollectionStatistics s = statistics->statistics();
QCOMPARE(s.count(), 0ll);
QCOMPARE(s.unreadCount(), 0ll);
QCOMPARE(s.count(), 0LL);
QCOMPARE(s.unreadCount(), 0LL);
// folder with attributes and content
CollectionPathResolver *resolver = new CollectionPathResolver(QStringLiteral("res1/foo"), this);
......@@ -430,8 +430,8 @@ void CollectionJobTest::testStatistics()
AKVERIFYEXEC(statistics);
s = statistics->statistics();
QCOMPARE(s.count(), 15ll);
QCOMPARE(s.unreadCount(), 14ll);
QCOMPARE(s.count(), 15LL);
QCOMPARE(s.unreadCount(), 14LL);
}
void CollectionJobTest::testModify_data()
......@@ -440,7 +440,7 @@ void CollectionJobTest::testModify_data()
QTest::addColumn<QString>("rid");
QTest::newRow("uid") << AkonadiTest::collectionIdFromPath(QStringLiteral("res1/foo")) << QString();
QTest::newRow("rid") << -1ll << QStringLiteral("10");
QTest::newRow("rid") << -1LL << QStringLiteral("10");
}
#define RESET_COLLECTION_ID \
......@@ -594,8 +594,8 @@ void CollectionJobTest::testUtf8CollectionName()
CollectionStatisticsJob *statistics = new CollectionStatisticsJob(col, this);
AKVERIFYEXEC(statistics);
CollectionStatistics s = statistics->statistics();
QCOMPARE(s.count(), 0ll);
QCOMPARE(s.unreadCount(), 0ll);
QCOMPARE(s.count(), 0LL);
QCOMPARE(s.unreadCount(), 0LL);
// delete collection
CollectionDeleteJob *del = new CollectionDeleteJob(col, this);
......
......@@ -51,7 +51,7 @@ private Q_SLOTS:
col = cj->collection();
QVERIFY(col.isValid());
auto attr = col.attribute<EntityDisplayAttribute>(Collection::AddIfMissing);
auto *attr = col.attribute<EntityDisplayAttribute>(Collection::AddIfMissing);
attr->setDisplayName(QStringLiteral("Test Collection"));
col.setContentMimeTypes({ Collection::mimeType(), QLatin1String("application/octet-stream") });
......
......@@ -51,7 +51,7 @@ private:
QVERIFY(cache.isCached(1));
QVERIFY(cache.isRequested(1));
const T e1 = cache.retrieve(1);
QCOMPARE(e1.id(), 1ll);
QCOMPARE(e1.id(), 1LL);
QVERIFY(e1.parentCollection().isValid());
QVERIFY(!e1.parentCollection().remoteId().isEmpty() || e1.parentCollection() == Collection::root());
......@@ -72,7 +72,7 @@ private:
const T e2 = cache.retrieve(2);
const T e3a = cache.retrieve(3);
QCOMPARE(e3a.id(), 3ll);
QCOMPARE(e3a.id(), 3LL);
QVERIFY(!e2.isValid());
cache.invalidate(3);
......@@ -144,7 +144,7 @@ private Q_SLOTS:
QVERIFY(cache.isCached(1));
QVERIFY(cache.isRequested(1));
const Item item = cache.retrieve(1);
QCOMPARE(item.id(), 1ll);
QCOMPARE(item.id(), 1LL);
QVERIFY(item.hasPayload<QByteArray>());
}
......
......@@ -98,18 +98,18 @@ private Q_SLOTS:
private:
QPair<FakeServerData *, Akonadi::EntityTreeModel *> populateModel(const QString &serverContent, const QString &mimeType = QString())
{
const auto fakeMonitor = new FakeMonitor(this);
auto *const fakeMonitor = new FakeMonitor(this);
fakeMonitor->setSession(m_fakeSession);
fakeMonitor->setCollectionMonitored(Collection::root());
if (!mimeType.isEmpty()) {
fakeMonitor->setMimeTypeMonitored(mimeType);
}
const auto model = new EntityTreeModel(fakeMonitor, this);
auto *const model = new EntityTreeModel(fakeMonitor, this);
m_modelSpy = new ModelSpy{model, this};
const auto serverData = new FakeServerData(model, m_fakeSession, fakeMonitor, this);
auto *const serverData = new FakeServerData(model, m_fakeSession, fakeMonitor, this);
serverData->setCommands(FakeJobResponse::interpret(serverData, serverContent));
// Give the model a chance to populate
......@@ -150,13 +150,13 @@ void EntityTreeModelTest::cleanupTestCase()
void EntityTreeModelTest::testInitialFetch()
{
const auto fakeMonitor = new FakeMonitor(this);
auto *const fakeMonitor = new FakeMonitor(this);
fakeMonitor->setSession(m_fakeSession);
fakeMonitor->setCollectionMonitored(Collection::root());
const auto model = new EntityTreeModel(fakeMonitor, this);
auto *const model = new EntityTreeModel(fakeMonitor, this);
const auto serverData = new FakeServerData(model, m_fakeSession, fakeMonitor, this);
auto *const serverData = new FakeServerData(model, m_fakeSession, fakeMonitor, this);
serverData->setCommands(FakeJobResponse::interpret(serverData, QString::fromLatin1(serverContent1)));
m_modelSpy = new ModelSpy(model, this);
......@@ -240,15 +240,15 @@ void EntityTreeModelTest::testCollectionMove()
QFETCH(QString, targetCollection);
const auto testDrivers = populateModel(serverContent);
const auto serverData = testDrivers.first;
const auto model = testDrivers.second;
auto *const serverData = testDrivers.first;
auto *const model = testDrivers.second;
const auto movedIndex = firstMatchedIndex(*model, movedCollection);
Q_ASSERT(movedIndex.isValid());
const auto sourceCollection = movedIndex.parent().data().toString();
const auto sourceRow = movedIndex.row();
const auto moveCommand = new FakeCollectionMovedCommand(movedCollection, sourceCollection, targetCollection, serverData);
auto *const moveCommand = new FakeCollectionMovedCommand(movedCollection, sourceCollection, targetCollection, serverData);
m_modelSpy->startSpying();
serverData->setCommands({moveCommand});
......@@ -288,9 +288,9 @@ void EntityTreeModelTest::testCollectionAdded()
QFETCH(QString, parentCollection);
const auto testDrivers = populateModel(serverContent);
const auto serverData = testDrivers.first;
auto *const serverData = testDrivers.first;
const auto addCommand = new FakeCollectionAddedCommand(addedCollection, parentCollection, serverData);
auto *const addCommand = new FakeCollectionAddedCommand(addedCollection, parentCollection, serverData);
m_modelSpy->startSpying();
serverData->setCommands({addCommand});
......@@ -332,14 +332,14 @@ void EntityTreeModelTest::testCollectionRemoved()
QFETCH(QString, removedCollection);
const auto testDrivers = populateModel(serverContent);
const auto serverData = testDrivers.first;
const auto model = testDrivers.second;
auto *const serverData = testDrivers.first;
auto *const model = testDrivers.second;
const auto removedIndex = firstMatchedIndex(*model, removedCollection);
const auto parentCollection = removedIndex.parent().data().toString();
const auto sourceRow = removedIndex.row();
const auto removeCommand = new FakeCollectionRemovedCommand(removedCollection, parentCollection, serverData);
auto *const removeCommand = new FakeCollectionRemovedCommand(removedCollection, parentCollection, serverData);
m_modelSpy->startSpying();
serverData->setCommands({removeCommand});
......@@ -382,15 +382,15 @@ void EntityTreeModelTest::testCollectionChanged()
QFETCH(QString, monitoredMimeType); // ##### TODO: this is unused. Is this test correct?
const auto testDrivers = populateModel(serverContent);
const auto serverData = testDrivers.first;
const auto model = testDrivers.second;
auto *const serverData = testDrivers.first;
auto *const model = testDrivers.second;
const auto changedIndex = firstMatchedIndex(*model, collectionName);
const auto parentCollection = changedIndex.parent().data().toString();
qDebug() << parentCollection;
const auto changedRow = changedIndex.row();
const auto changeCommand = new FakeCollectionChangedCommand(collectionName, parentCollection, serverData);
auto *const changeCommand = new FakeCollectionChangedCommand(collectionName, parentCollection, serverData);
m_modelSpy->startSpying();
serverData->setCommands({changeCommand});
......@@ -429,8 +429,8 @@ void EntityTreeModelTest::testItemMove()
QFETCH(QString, targetCollection);
const auto testDrivers = populateModel(serverContent);
const auto serverData = testDrivers.first;
const auto model = testDrivers.second;
auto *const serverData = testDrivers.first;
auto *const model = testDrivers.second;
const auto movedIndex = firstMatchedIndex(*model, movedItem);
const auto sourceCollection = movedIndex.parent().data().toString();
......@@ -439,7 +439,7 @@ void EntityTreeModelTest::testItemMove()
const auto targetIndex = firstMatchedIndex(*model, targetCollection);
const auto targetRow = model->rowCount(targetIndex);
const auto moveCommand = new FakeItemMovedCommand(movedItem, sourceCollection, targetCollection, serverData);
auto *const moveCommand = new FakeItemMovedCommand(movedItem, sourceCollection, targetCollection, serverData);
m_modelSpy->startSpying();
serverData->setCommands({moveCommand});
......@@ -485,13 +485,13 @@ void EntityTreeModelTest::testItemAdded()
QFETCH(QString, parentCollection);
const auto testDrivers = populateModel(serverContent);
const auto serverData = testDrivers.first;
const auto model = testDrivers.second;
auto *const serverData = testDrivers.first;
auto *const model = testDrivers.second;
const auto parentIndex = firstMatchedIndex(*model, parentCollection);
const auto targetRow = model->rowCount(parentIndex);
const auto addedCommand = new FakeItemAddedCommand(addedItem, parentCollection, serverData);
auto *const addedCommand = new FakeItemAddedCommand(addedItem, parentCollection, serverData);
m_modelSpy->startSpying();
......@@ -538,14 +538,14 @@ void EntityTreeModelTest::testItemRemoved()
QFETCH(QString, removedItem);
const auto testDrivers = populateModel(serverContent);
const auto serverData = testDrivers.first;
const auto model = testDrivers.second;
auto *const serverData = testDrivers.first;
auto *const model = testDrivers.second;
const auto removedIndex = firstMatchedIndex(*model, removedItem);
const auto sourceCollection = removedIndex.parent().data().toString();
const auto sourceRow = removedIndex.row();
const auto removeCommand = new FakeItemRemovedCommand(removedItem, sourceCollection, serverData);
auto *const removeCommand = new FakeItemRemovedCommand(removedItem, sourceCollection, serverData);
m_modelSpy->startSpying();
serverData->setCommands({removeCommand});
......@@ -592,14 +592,14 @@ void EntityTreeModelTest::testItemChanged()
QFETCH(QString, changedItem);
const auto testDrivers = populateModel(serverContent);
const auto serverData = testDrivers.first;
const auto model = testDrivers.second;
auto *const serverData = testDrivers.first;
auto *const model = testDrivers.second;
const auto changedIndex = firstMatchedIndex(*model, changedItem);
const auto parentCollection = changedIndex.parent().data().toString();
const auto sourceRow = changedIndex.row();
const auto changeCommand = new FakeItemChangedCommand(changedItem, parentCollection, serverData);
auto *const changeCommand = new FakeItemChangedCommand(changedItem, parentCollection, serverData);
m_modelSpy->startSpying();
serverData->setCommands({changeCommand});
......@@ -628,15 +628,15 @@ void EntityTreeModelTest::testRemoveCollectionOnChanged()
const auto monitoredMimeType = QStringLiteral("text/directory");
const auto testDrivers = populateModel(serverContent, monitoredMimeType);
const auto serverData = testDrivers.first;
const auto model = testDrivers.second;
auto *const serverData = testDrivers.first;
auto *const model = testDrivers.second;
const auto changedIndex = firstMatchedIndex(*model, collectionName);
auto changedCol = changedIndex.data(Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
changedCol.setContentMimeTypes({QStringLiteral("foobar")});
const auto parentCollection = changedIndex.parent().data().toString();
const auto changeCommand = new FakeCollectionChangedCommand(changedCol, serverData);
auto *const changeCommand = new FakeCollectionChangedCommand(changedCol, serverData);
m_modelSpy->startSpying();
serverData->setCommands({changeCommand});
......
......@@ -67,7 +67,7 @@ public Q_SLOTS:
start = s;
end = e;
}
void onRowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)
void onRowsMoved(const QModelIndex & /*unused*/, int /*unused*/, int /*unused*/, const QModelIndex & /*unused*/, int /*unused*/)
{
mSignals << QStringLiteral("rowsMoved");
}
......
......@@ -30,7 +30,7 @@ class FakeMonitorPrivate : public ChangeRecorderPrivate
{
Q_DECLARE_PUBLIC(FakeMonitor)
public:
FakeMonitorPrivate(FakeMonitor *monitor)
explicit FakeMonitorPrivate(FakeMonitor *monitor)
: ChangeRecorderPrivate(nullptr, monitor)
{
}
......
......@@ -53,7 +53,7 @@ FakeServerData::FakeServerData(TagModel *model, FakeSession *session, FakeMonito
m_nextTagId(1)
{
connect(session, &FakeSession::jobAdded,
[this](Akonadi::Job *) {
[this](Akonadi::Job * /*unused*/) {
QTimer::singleShot(0, [this]() {
jobAdded();
});
......
......@@ -195,7 +195,7 @@ void FavoriteProxyTest::testLoadConfig()
class Filter: public QSortFilterProxyModel
{
public:
bool filterAcceptsRow(int, const QModelIndex &) const override
bool filterAcceptsRow(int /*source_row*/, const QModelIndex & /*source_parent*/) const override
{
return accepts;
}
......
......@@ -95,7 +95,7 @@ void GidTest::testSetAndFetch_data()
}
}
static void fetchAndSetGid(Item item)
static void fetchAndSetGid(const Item& item)
{
ItemFetchJob *prefetchjob = new ItemFetchJob(item);
prefetchjob->fetchScope().fetchFullPayload();
......
......@@ -243,19 +243,19 @@ void ImapParserTest::testParseNumber()
pos = ImapParser::parseNumber(input, result, &ok, 0);
QCOMPARE(ok, true);
QCOMPARE(pos, 2);
QCOMPARE(result, 1ll);
QCOMPARE(result, 1LL);
// multiple digits
pos = ImapParser::parseNumber(input, result, &ok, 3);
QCOMPARE(ok, true);
QCOMPARE(pos, 5);
QCOMPARE(result, 23ll);
QCOMPARE(result, 23LL);
// number at input end
pos = ImapParser::parseNumber(input, result, &ok, 6);
QCOMPARE(ok, true);
QCOMPARE(pos, 7);
QCOMPARE(result, 4ll);
QCOMPARE(result, 4LL);
// out of bounds access
pos = ImapParser::parseNumber(input, result, &ok, input.length());
......
......@@ -241,11 +241,11 @@ void ItemAppendTest::testItemSize_data()
Item i(QStringLiteral("application/octet-stream"));
i.setPayload(QByteArray("ABCD"));
QTest::newRow("auto size") << i << 4ll;
QTest::newRow("auto size") << i << 4LL;
i.setSize(3);
QTest::newRow("too small") << i << 4ll;
QTest::newRow("too small") << i << 4LL;
i.setSize(10);
QTest::newRow("too large") << i << 10ll;
QTest::newRow("too large") << i << 10LL;
}
void ItemAppendTest::testItemSize()
......
......@@ -78,7 +78,7 @@ private Q_SLOTS:
QCOMPARE(item.attributes().count(), 1);
QVERIFY(item.remoteId().isEmpty());
QEXPECT_FAIL("", "statistics are not properly updated after copy", Abort);
QCOMPARE(target.statistics().count(), 1ll);
QCOMPARE(target.statistics().count(), 1LL);
}
void testIlleagalCopy()
......@@ -108,15 +108,15 @@ private Q_SLOTS:
Item item(QStringLiteral("application/octet-stream"));
item.setPayloadPath(file.fileName());
auto create = new ItemCreateJob(item, source, this);
auto *create = new ItemCreateJob(item, source, this);
AKVERIFYEXEC(create);
item = create->item();
const Collection target(AkonadiTest::collectionIdFromPath(QStringLiteral("res2/space folder")));
auto copy = new ItemCopyJob(item, target, this);
auto *copy = new ItemCopyJob(item, target, this);
AKVERIFYEXEC(copy);
auto fetch = new ItemFetchJob(target, this);
auto *fetch = new ItemFetchJob(target, this);
fetch->fetchScope().fetchFullPayload(true);
AKVERIFYEXEC(fetch);
QCOMPARE(fetch->items().size(), 1);
......
......@@ -119,7 +119,7 @@ void ItemFetchTest::testResourceRetrieval()
AKVERIFYEXEC(job);
QCOMPARE(job->items().count(), 1);
item = job->items().first();
QCOMPARE(item.id(), 1ll);
QCOMPARE(item.id(), 1LL);
QVERIFY(!item.remoteId().isEmpty());
QVERIFY(!item.hasPayload()); // not yet in cache
QCOMPARE(item.attributes().count(), 1);
......@@ -131,7 +131,7 @@ void ItemFetchTest::testResourceRetrieval()
AKVERIFYEXEC(job);
QCOMPARE(job->items().count(), 1);
item = job->items().first();
QCOMPARE(item.id(), 1ll);
QCOMPARE(item.id(), 1LL);
QVERIFY(!item.remoteId().isEmpty());
QVERIFY(item.hasPayload());
QCOMPARE(item.attributes().count(), 1);
......
......@@ -361,7 +361,9 @@ void ItemHydra::testSharedPointerConversions()
QVERIFY(!a.hasPayload<GerdPtr>());
QVERIFY(a.payload<RudiPtr>().get());
QVERIFY(a.payload<VolkerPtr>().get());
bool thrown = false, thrownCorrectly = true;
bool thrown = false;
bool thrownCorrectly = true;
try {
QVERIFY(!a.payload<GerdPtr>());
} catch (const Akonadi::PayloadException &e) {
......
......@@ -159,7 +159,7 @@ private Q_SLOTS:
item.setPayload(QByteArray("This is a test payload"));
item.setSize(34);
item.setParentCollection(col);
auto create = new ItemCreateJob(item, col, this);
auto *create = new ItemCreateJob(item, col, this);
AKVERIFYEXEC(create);
item = create->item();
......@@ -169,7 +169,7 @@ private Q_SLOTS:
QCOMPARE(ntfItem.flags(), item.flags());
Collection dest(AkonadiTest::collectionIdFromPath(QStringLiteral("res1/foo/bar")));
auto move = new ItemMoveJob(item, dest, this);
auto *move = new ItemMoveJob(item, dest, this);
AKVERIFYEXEC(move);
QTRY_COMPARE(itemMovedSpy.size(), 1);
......
......@@ -423,13 +423,13 @@ void ItemStoreTest::itemModifyJobShouldOnlySendModifiedAttributes()
class ParallelJobsRunner
{
public:
ParallelJobsRunner(int count)
explicit ParallelJobsRunner(int count)
: numSessions(count)
{
sessions.reserve(numSessions);
modifyJobs.reserve(numSessions);
for (int i = 0 ; i < numSessions; ++i) {
auto session = new Session(QByteArray::number(i));
auto *session = new Session(QByteArray::number(i));
sessions.push_back(session);
}
}
......@@ -457,8 +457,10 @@ public:
if (!doneJobs.contains(mjob)) {
QSignalSpy spy(mjob, &ItemModifyJob::result);
QVERIFY(spy.