aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Lohnau <alexander.lohnau@gmx.de>2024-02-04 16:37:45 +0100
committerAlexander Lohnau <alexander.lohnau@gmx.de>2024-02-04 16:42:43 +0100
commita9ec6984d2642a9c2f08477dabf7f080618e3e7d (patch)
treee3fba1c16a311b871d46285ff583daaed1e09e89
parent5cf62495f0eb1664e509d86b61c5272d3601692f (diff)
fully-qualified-moc-types: Remove fixit snippet from message, add fixit test
-rw-r--r--README.md2
-rw-r--r--checks.json7
-rw-r--r--src/Checks.h1
-rw-r--r--src/checks/level0/fully-qualified-moc-types.cpp6
-rw-r--r--tests/fully-qualified-moc-types/config.json3
-rw-r--r--tests/fully-qualified-moc-types/main.cpp.expected22
-rw-r--r--tests/fully-qualified-moc-types/main.cpp.fixed.expected102
7 files changed, 125 insertions, 18 deletions
diff --git a/README.md b/README.md
index 8bc4cedd..d94b6307 100644
--- a/README.md
+++ b/README.md
@@ -255,7 +255,7 @@ clazy runs all checks from level1 by default.
- [connect-not-normalized](docs/checks/README-connect-not-normalized.md)
- [container-anti-pattern](docs/checks/README-container-anti-pattern.md)
- [empty-qstringliteral](docs/checks/README-empty-qstringliteral.md)
- - [fully-qualified-moc-types](docs/checks/README-fully-qualified-moc-types.md)
+ - [fully-qualified-moc-types](docs/checks/README-fully-qualified-moc-types.md) (fix-fully-qualified-moc-types)
- [lambda-in-connect](docs/checks/README-lambda-in-connect.md)
- [lambda-unique-connection](docs/checks/README-lambda-unique-connection.md)
- [lowercase-qml-type-name](docs/checks/README-lowercase-qml-type-name.md)
diff --git a/checks.json b/checks.json
index 8bd9da73..1c334aff 100644
--- a/checks.json
+++ b/checks.json
@@ -243,7 +243,12 @@
"class_name" : "FullyQualifiedMocTypes",
"level" : 0,
"categories" : ["bug", "qml"],
- "visits_decls" : true
+ "visits_decls" : true,
+ "fixits" : [
+ {
+ "name" : "fully-qualified-moc-types"
+ }
+ ]
},
{
"name" : "qvariant-template-instantiation",
diff --git a/src/Checks.h b/src/Checks.h
index 1ba6109d..c9844338 100644
--- a/src/Checks.h
+++ b/src/Checks.h
@@ -170,6 +170,7 @@ void CheckManager::registerChecks()
registerCheck(check<ContainerAntiPattern>("container-anti-pattern", CheckLevel0, RegisteredCheck::Option_VisitsStmts));
registerCheck(check<EmptyQStringliteral>("empty-qstringliteral", CheckLevel0, RegisteredCheck::Option_VisitsStmts));
registerCheck(check<FullyQualifiedMocTypes>("fully-qualified-moc-types", CheckLevel0, RegisteredCheck::Option_VisitsDecls));
+ registerFixIt(1, "fix-fully-qualified-moc-types", "fully-qualified-moc-types");
registerCheck(check<LambdaInConnect>("lambda-in-connect", CheckLevel0, RegisteredCheck::Option_VisitsStmts));
registerCheck(check<LambdaUniqueConnection>("lambda-unique-connection", CheckLevel0, RegisteredCheck::Option_VisitsStmts));
registerCheck(check<LowercaseQMlTypeName>("lowercase-qml-type-name", CheckLevel0, RegisteredCheck::Option_VisitsStmts));
diff --git a/src/checks/level0/fully-qualified-moc-types.cpp b/src/checks/level0/fully-qualified-moc-types.cpp
index cedb9d50..98cade5b 100644
--- a/src/checks/level0/fully-qualified-moc-types.cpp
+++ b/src/checks/level0/fully-qualified-moc-types.cpp
@@ -77,8 +77,7 @@ void FullyQualifiedMocTypes::VisitDecl(clang::Decl *decl)
fixitRange = SourceRange(fixitRange.getBegin(), fixitRange.getEnd().getLocWithOffset(-1));
}
std::vector fixits{FixItHint::CreateReplacement(fixitRange, qualifiedTypeName)};
- std::string warning = accessSpecifierManager->qtAccessSpecifierTypeStr(qst).str() + " arguments need to be fully-qualified (" + qualifiedTypeName
- + " instead of " + typeName + ")";
+ std::string warning = accessSpecifierManager->qtAccessSpecifierTypeStr(qst).str() + " arguments need to be fully-qualified";
emitWarning(param->getTypeSpecStartLoc(), warning, fixits);
}
}
@@ -87,8 +86,7 @@ void FullyQualifiedMocTypes::VisitDecl(clang::Decl *decl)
QualType returnT = clazy::pointeeQualType(method->getReturnType());
if (!typeIsFullyQualified(returnT, /*by-ref*/ qualifiedTypeName, /*by-ref*/ typeName)) {
SourceRange returnTypeSourceRange = method->getReturnTypeSourceRange();
- std::string warning = accessSpecifierManager->qtAccessSpecifierTypeStr(qst).str() + " return types need to be fully-qualified (" + qualifiedTypeName
- + " instead of " + typeName + ")";
+ std::string warning = accessSpecifierManager->qtAccessSpecifierTypeStr(qst).str() + " return types need to be fully-qualified";
std::vector fixits{FixItHint::CreateReplacement(returnTypeSourceRange, qualifiedTypeName)};
emitWarning(returnTypeSourceRange.getBegin(), warning, fixits);
}
diff --git a/tests/fully-qualified-moc-types/config.json b/tests/fully-qualified-moc-types/config.json
index 0213baae..e93ade48 100644
--- a/tests/fully-qualified-moc-types/config.json
+++ b/tests/fully-qualified-moc-types/config.json
@@ -2,7 +2,8 @@
"minimum_qt_version": 50800,
"tests": [
{
- "filename": "main.cpp"
+ "filename": "main.cpp",
+ "has_fixits": true
}
]
}
diff --git a/tests/fully-qualified-moc-types/main.cpp.expected b/tests/fully-qualified-moc-types/main.cpp.expected
index 0c189845..49a5e3d8 100644
--- a/tests/fully-qualified-moc-types/main.cpp.expected
+++ b/tests/fully-qualified-moc-types/main.cpp.expected
@@ -1,12 +1,12 @@
-fully-qualified-moc-types/main.cpp:29:21: warning: signal arguments need to be fully-qualified (NS::MyType instead of MyType) [-Wclazy-fully-qualified-moc-types]
-fully-qualified-moc-types/main.cpp:38:22: warning: slot arguments need to be fully-qualified (NS::MyType instead of MyType) [-Wclazy-fully-qualified-moc-types]
-fully-qualified-moc-types/main.cpp:47:39: warning: invokable arguments need to be fully-qualified (NS::MyType instead of MyType) [-Wclazy-fully-qualified-moc-types]
-fully-qualified-moc-types/main.cpp:54:21: warning: invokable return types need to be fully-qualified (NS::MyType instead of MyType) [-Wclazy-fully-qualified-moc-types]
-fully-qualified-moc-types/main.cpp:79:12: warning: slot return types need to be fully-qualified (std::pair<bool, MyObj2::QualMe> instead of std::pair<bool, QualMe>) [-Wclazy-fully-qualified-moc-types]
-fully-qualified-moc-types/main.cpp:80:12: warning: slot return types need to be fully-qualified (std::pair<bool, MyObj2::QualMe> instead of pair<bool, QualMe>) [-Wclazy-fully-qualified-moc-types]
-fully-qualified-moc-types/main.cpp:82:12: warning: slot return types need to be fully-qualified (MyObj2::MyList instead of MyList) [-Wclazy-fully-qualified-moc-types]
-fully-qualified-moc-types/main.cpp:83:12: warning: slot return types need to be fully-qualified (QList<MyObj2::QualMe> instead of QList<QualMe>) [-Wclazy-fully-qualified-moc-types]
-fully-qualified-moc-types/main.cpp:87:12: warning: slot return types need to be fully-qualified (QDBusPendingReply<MyObj2::QualMe> instead of QDBusPendingReply<QualMe>) [-Wclazy-fully-qualified-moc-types]
-fully-qualified-moc-types/main.cpp:90:12: warning: slot return types need to be fully-qualified (QDBusPendingReply<MyObj2::MyList> instead of QDBusPendingReply<MyList>) [-Wclazy-fully-qualified-moc-types]
-fully-qualified-moc-types/main.cpp:92:48: warning: slot arguments need to be fully-qualified (QDBusPendingReply<std::shared_ptr<MyObj2::MyList>> instead of QDBusPendingReply<std::shared_ptr<MyList>>) [-Wclazy-fully-qualified-moc-types]
+fully-qualified-moc-types/main.cpp:29:21: warning: signal arguments need to be fully-qualified [-Wclazy-fully-qualified-moc-types]
+fully-qualified-moc-types/main.cpp:38:22: warning: slot arguments need to be fully-qualified [-Wclazy-fully-qualified-moc-types]
+fully-qualified-moc-types/main.cpp:47:39: warning: invokable arguments need to be fully-qualified [-Wclazy-fully-qualified-moc-types]
+fully-qualified-moc-types/main.cpp:54:21: warning: invokable return types need to be fully-qualified [-Wclazy-fully-qualified-moc-types]
+fully-qualified-moc-types/main.cpp:79:12: warning: slot return types need to be fully-qualified [-Wclazy-fully-qualified-moc-types]
+fully-qualified-moc-types/main.cpp:80:12: warning: slot return types need to be fully-qualified [-Wclazy-fully-qualified-moc-types]
+fully-qualified-moc-types/main.cpp:82:12: warning: slot return types need to be fully-qualified [-Wclazy-fully-qualified-moc-types]
+fully-qualified-moc-types/main.cpp:83:12: warning: slot return types need to be fully-qualified [-Wclazy-fully-qualified-moc-types]
+fully-qualified-moc-types/main.cpp:87:12: warning: slot return types need to be fully-qualified [-Wclazy-fully-qualified-moc-types]
+fully-qualified-moc-types/main.cpp:90:12: warning: slot return types need to be fully-qualified [-Wclazy-fully-qualified-moc-types]
+fully-qualified-moc-types/main.cpp:92:48: warning: slot arguments need to be fully-qualified [-Wclazy-fully-qualified-moc-types]
fully-qualified-moc-types/main.cpp:18:5: warning: Q_PROPERTY of type NamespacedGadget should use full qualification (NS::NamespacedGadget) [-Wclazy-fully-qualified-moc-types]
diff --git a/tests/fully-qualified-moc-types/main.cpp.fixed.expected b/tests/fully-qualified-moc-types/main.cpp.fixed.expected
new file mode 100644
index 00000000..597f12b1
--- /dev/null
+++ b/tests/fully-qualified-moc-types/main.cpp.fixed.expected
@@ -0,0 +1,102 @@
+#include <QtCore/QObject>
+#include <QtDBus/QDBusPendingReply>
+#include <memory>
+struct A {};
+struct NonNamespacedGadget {
+ Q_GADGET
+};
+
+namespace NS {
+ struct MyType {};
+
+ struct NamespacedGadget {
+ Q_GADGET
+ };
+
+ enum EnumFoo { EnumFoo1 };
+
+ class MyObject : public QObject
+ {
+ Q_OBJECT
+ Q_PROPERTY(NS::MyType foo READ foo) // OK, not gadget
+ Q_PROPERTY(MyType foo1 READ foo) // OK, not gadget
+ Q_PROPERTY(EnumFoo enumFoo READ enumFoo CONSTANT) // OK
+ Q_PROPERTY(NamespacedGadget namespacedGadget READ namespacedGadget CONSTANT) // Warn, gadget
+ Q_PROPERTY(NS::NamespacedGadget namespacedGadget2 READ namespacedGadget2 CONSTANT) // OK
+ Q_PROPERTY(NonNamespacedGadget nonNamespacedGadget READ nonNamespacedGadget CONSTANT) // OK
+ Q_SIGNALS:
+ void mysig(NS::MyType);
+ void mysig2(NS::MyType &); // Warn
+ void mysig3(NS::MyType);
+ void mysig4(const NS::MyType &);
+ void mysig5(A);
+ void mysig6(const A);
+ void mysig7(const A *);
+ void mysig8(A *);
+ public Q_SLOTS:
+ void myslot1(NS::MyType);
+ void myslot2(NS::MyType); // Warn
+ void myslot3(NS::MyType);
+ void myslot4(const NS::MyType &);
+ void myslot5(A);
+ void myslot6(const A);
+ void myslot7(const A *);
+ void myslot8(A *);
+ public:
+ Q_INVOKABLE void myinvokable1(NS::MyType);
+ Q_INVOKABLE void myinvokable2(NS::MyType); // Warn
+ Q_INVOKABLE void myinvokable3(NS::MyType);
+ Q_INVOKABLE void myinvokable4(const NS::MyType &);
+ Q_INVOKABLE void myinvokable5(A);
+ Q_INVOKABLE void myinvokable6(const A);
+ Q_INVOKABLE void myinvokable7(const A *);
+ Q_INVOKABLE void myinvokable8(A *);
+ Q_INVOKABLE NS::MyType myinvokable9(NS::MyType); // Warn
+ NS::MyType foo();
+ NamespacedGadget namespacedGadget() const;
+ NamespacedGadget namespacedGadget2() const;
+ NonNamespacedGadget nonNamespacedGadget() const;
+ EnumFoo enumFoo() const;
+ };
+}
+
+
+
+namespace { // annonymous
+ struct AnnonFoo {};
+};
+
+using namespace std; // pair<bool,QualMe> is returned for one method, the check should warn about the missing "std::" prefix
+class MyObj2 : public QObject
+{
+public:
+ struct QualMe {};
+ using MyList = QList<QualMe>; // QualMe is not fully qualified here, but it shouldn't matter when using the typedef
+Q_OBJECT
+Q_SIGNALS:
+ void mySig(AnnonFoo);
+public Q_SLOTS:
+ inline std::pair<bool, MyObj2::QualMe> unqualPairParam() {return {};} // Warn
+ inline std::pair<bool, MyObj2::QualMe> unqualPairClass() {return {};} // Warn
+ inline std::pair<bool, MyObj2::QualMe> fullyQUalPair() {return {};} // OK
+ inline MyObj2::MyList typeAlias() {return {};} // WARN
+ inline QList<MyObj2::QualMe> genericWithoutFullyQual() {return {};} // WARN
+ inline QList<MyObj2::QualMe> genericFullyQual() {return {};} // OK
+ inline QStringList qstringListTypealias() {return {};} // OK
+ inline MyObj2::MyList fullTypeAlias() {return {};} // OK
+ inline QDBusPendingReply<MyObj2::QualMe> unqualGenericDbusReply() {return {};} // WARN
+ inline QDBusPendingReply<bool> boolDbusReply() {return {};} // OK
+ inline QDBusPendingReply<> voidDbusReply() {return {};} // OK
+ inline QDBusPendingReply<MyObj2::MyList> typedefInGeneric() {return {};} // WARN
+ inline void nestedGeneric(QDBusPendingReply<std::shared_ptr<MyObj2>>) {} // OK
+ inline void nestedNotFullyQualifiedGeneric(QDBusPendingReply<std::shared_ptr<MyObj2::MyList>>) {} // WARN
+};
+
+Q_DECLARE_METATYPE(MyObj2::QualMe);
+Q_DECLARE_METATYPE(std::shared_ptr<MyObj2::MyList>);
+
+#if QT_VERSION_MAJOR == 5
+#include "main.qt5.moc_"
+#else
+#include "main.qt6.moc_"
+#endif