diff options
Diffstat (limited to 'src/checks/level0')
25 files changed, 0 insertions, 321 deletions
diff --git a/src/checks/level0/README-connect-by-name.md b/src/checks/level0/README-connect-by-name.md deleted file mode 100644 index e5f7d255..00000000 --- a/src/checks/level0/README-connect-by-name.md +++ /dev/null @@ -1,10 +0,0 @@ -# connect-by-name - -Warns when "auto-connection slots" are used. They're also known as "connect by name", a -very old and unpopular feature which shouldn't be used anymore. See http://doc.qt.io/qt-5/qobject.html#auto-connection for more information about them. - -These types of connections are very brittle, as a simple object rename would break your code. -In Qt 5 the PMF connect syntax is recommended as it catches errors at compile time. - -This check simply warns for any slot named like on_*_*, because even if you're not using .ui files -this naming is misleading and not good for readability, as the reader would think you're using auto-connection. diff --git a/src/checks/level0/README-connect-non-signal.md b/src/checks/level0/README-connect-non-signal.md deleted file mode 100644 index 627523c9..00000000 --- a/src/checks/level0/README-connect-non-signal.md +++ /dev/null @@ -1,8 +0,0 @@ -# connect-non-signal - -Warns when connecting a non-signal to something. - -For example: -`connect(obj, &MyObj::mySlot, ...);` - -Only works with the new Qt5 connect syntax (PMF). diff --git a/src/checks/level0/README-connect-not-normalized.md b/src/checks/level0/README-connect-not-normalized.md deleted file mode 100644 index 3931fd69..00000000 --- a/src/checks/level0/README-connect-not-normalized.md +++ /dev/null @@ -1,10 +0,0 @@ -# connect-not-normalized - -Warns when the contents of `SIGNAL()`, `SLOT()`, `Q_ARG()` and `Q_RETURN_ARG()` are not normalized. - -Using normalized signatures allows to avoid unneeded memory allocations. - -For signals and slots it only warns for `connect` statements, not `disconnect`, since it only -impacts the performance of the former. - -See `QMetaObject::normalizedSignature()` for more information. diff --git a/src/checks/level0/README-container-anti-pattern.md b/src/checks/level0/README-container-anti-pattern.md deleted file mode 100644 index b7a77d18..00000000 --- a/src/checks/level0/README-container-anti-pattern.md +++ /dev/null @@ -1,24 +0,0 @@ -# container-anti-pattern - -Finds when temporary containers are being created needlessly. -These cases are usually easy to fix by using iterators, avoiding memory allocations. - -Matches code like: - - {QMap, QHash, QSet}.values().* - {QMap, QHash}.keys().* - {QVector, QSet}.toList().* - QList::toVector().* - QSet::intersect(other).isEmpty() - for (auto i : {QHash, QMap}.values()) {} - foreach (auto i, {QHash, QMap}.values()) {} - -#### Example - - set.toList()[0]; // use set.constFirst() instead - hash.values().size(); // Use hash.size() instead - hash.keys().contains(); // Use hash.contains() instead - hash.values().contains(); // Use std::find(hash.cbegin(), hash.cend(), myValue) instead - map.values(k).foo ; // Use QMap::equal_range(k) instead - for (auto i : hash.values()) {} // Iterate the hash directly instead: for (auto i : hash) {} - QSet::intersect(other).isEmpty() // Use QSet::intersects() instead, avoiding memory allocations and iterations, since Qt 5.6 diff --git a/src/checks/level0/README-fully-qualified-moc-types.md b/src/checks/level0/README-fully-qualified-moc-types.md deleted file mode 100644 index 43f34055..00000000 --- a/src/checks/level0/README-fully-qualified-moc-types.md +++ /dev/null @@ -1,26 +0,0 @@ -# fully-qualified-moc-types - -Warns when a signal, slot or invokable declaration is not using fully-qualified type names, which will break old-style connects -and interaction with QML. - -Also warns if a Q_PROPERTY of type gadget is not fully-qualified (Enums and QObjects in Q_PROPERTY don't need -to be fully qualified). - -Example: - -namespace MyNameSpace { - - struct MyType { (...) }; - - class MyObject : public QObject - { - Q_OBJECT - Q_PROPERTY(MyGadget myprop READ myprop); // Wrong, needs namespace - Q_SIGNALS: - void mySignal(MyType); // Wrong - void mySignal(MyNameSpace::MyType); // OK - }; -} - -Beware that fixing these type names might break user code if they are connecting to them via old style connects, -since the users might have worked around your bug and not included the namespace in their connect statement diff --git a/src/checks/level0/README-lambda-in-connect.md b/src/checks/level0/README-lambda-in-connect.md deleted file mode 100644 index bfdefec4..00000000 --- a/src/checks/level0/README-lambda-in-connect.md +++ /dev/null @@ -1,13 +0,0 @@ -# lambda-in-connect - -Warns when a lambda inside a connect captures local variables by reference. -This usually results in a crash since the lambda might get called after the captured variable went out of scope. - -#### Example: -```` - int a; - connect(obj, &MyObj::mySignal, [&a]{ ... }); -```` -Although it's dangerous to capture by reference in other situations too, this check only warns for -connects, otherwise it would generate false-positives in legitimate situations where you only -use the lambda before going out of scope. diff --git a/src/checks/level0/README-lambda-unique-connection.md b/src/checks/level0/README-lambda-unique-connection.md deleted file mode 100644 index 453f3a28..00000000 --- a/src/checks/level0/README-lambda-unique-connection.md +++ /dev/null @@ -1,4 +0,0 @@ -# lambda-unique-connection - -Finds usages of `Qt::UniqueConnection` when the slot is a functor, lambda or non-member function. -That `connect()` overload does not support `Qt::UniqueConnection`. diff --git a/src/checks/level0/README-mutable-container-key.md b/src/checks/level0/README-mutable-container-key.md deleted file mode 100644 index 1c87c017..00000000 --- a/src/checks/level0/README-mutable-container-key.md +++ /dev/null @@ -1,5 +0,0 @@ -# mutable-container-key - -Looks for `QMap` or `QHash` having key types which can be modified due to external factors. -The key's value should never change, as it's needed for sorting or hashing, but with some types, such as non-owning smart pointers it might happen. -The supported key types are: `QPointer`, `QWeakPointer`, `weak_ptr` and `QPersistentModelIndex`. diff --git a/src/checks/level0/README-qcolor-from-literal.md b/src/checks/level0/README-qcolor-from-literal.md deleted file mode 100644 index cd2d28fe..00000000 --- a/src/checks/level0/README-qcolor-from-literal.md +++ /dev/null @@ -1,10 +0,0 @@ -# qcolor-from-literal - -Warns when a `QColor` is being constructed from a string literal such as "#RRGGBB". -This is less performant than calling the ctor that takes `int`s, since it creates temporary `QString`s. - -Example: - -`QColor c("#000000");` // Use QColor c(0, 0, 0) instead - -`c.setNamedColor("#001122");` // Use c = QColor(0, 0x11, 0x22) instead diff --git a/src/checks/level0/README-qdatetime-utc.md b/src/checks/level0/README-qdatetime-utc.md deleted file mode 100644 index 1741e78a..00000000 --- a/src/checks/level0/README-qdatetime-utc.md +++ /dev/null @@ -1,8 +0,0 @@ -# qdatetime-utc - -Finds calls to `QDateTime::currentDateTime()` which should be replaced by -`QDateTime::currentDateTimeUTC()` in order to avoid expensive timezone code paths. - -The two supported cases are: -- QDateTime::currentDateTime().toTime_t() -> QDateTime::currentDateTimeUtc().toTime_t() -- QDateTime::currentDateTime().toUTC() -> QDateTime::currentDateTimeUtc() diff --git a/src/checks/level0/README-qenums.md b/src/checks/level0/README-qenums.md deleted file mode 100644 index 1c25f058..00000000 --- a/src/checks/level0/README-qenums.md +++ /dev/null @@ -1,3 +0,0 @@ -# qenums - -Warns when you're using `Q_ENUMS`. Use Q_ENUM instead. diff --git a/src/checks/level0/README-qfileinfo-exists.md b/src/checks/level0/README-qfileinfo-exists.md deleted file mode 100644 index 279fc01c..00000000 --- a/src/checks/level0/README-qfileinfo-exists.md +++ /dev/null @@ -1,6 +0,0 @@ -# qfileinfo-exists - -Finds places using `QFileInfo("filename").exists()` instead of the faster version `QFileInfo::exists("filename")`. - -According to Qt's docs: -"Using this function is faster than using QFileInfo(file).exists() for file system access." diff --git a/src/checks/level0/README-qgetenv.md b/src/checks/level0/README-qgetenv.md deleted file mode 100644 index 3292d798..00000000 --- a/src/checks/level0/README-qgetenv.md +++ /dev/null @@ -1,6 +0,0 @@ -# qgetenv - -Warns on innefficient usages of `qgetenv()` which usually allocate memory. -Suggests usage of `qEnvironmentVariableIsSet()`, `qEnvironmentVariableIsEmpty()` and `qEnvironmentVariableIntValue()`. - -These replacements are available since Qt 5.5. diff --git a/src/checks/level0/README-qmap-with-pointer-key.md b/src/checks/level0/README-qmap-with-pointer-key.md deleted file mode 100644 index 6fe5ed96..00000000 --- a/src/checks/level0/README-qmap-with-pointer-key.md +++ /dev/null @@ -1,7 +0,0 @@ -# qmap-with-pointer-key - -Finds cases where you're using `QMap<K,T>` and K is a pointer. - -`QMap` has the particularity of sorting it's keys, but sorting by memory -address makes no sense. -Use `QHash` instead, which provides faster lookups. diff --git a/src/checks/level0/README-qstring-arg.md b/src/checks/level0/README-qstring-arg.md deleted file mode 100644 index 819a97cf..00000000 --- a/src/checks/level0/README-qstring-arg.md +++ /dev/null @@ -1,39 +0,0 @@ -# qstring-arg - -Implements two warnings: - -1. Detects when you're using chained `QString::arg()` calls and should instead use the multi-arg overload to save memory allocations - - QString("%1 %2").arg(a).arg(b); - QString("%1 %2").arg(a, b); // one less temporary heap allocation - -2. Detects when you're using misleading `QString::arg()` overloads - - QString arg(qlonglong a, int fieldwidth = 0, int base = 10, QChar fillChar = QLatin1Char(' ')) const - QString arg(qulonglong a, int fieldwidth = 0, int base = 10, QChar fillChar = QLatin1Char(' ')) const - QString arg(long a, int fieldwidth = 0, int base=10, QChar fillChar = QLatin1Char(' ')) const - QString arg(ulong a, int fieldwidth = 0, int base=10, QChar fillChar = QLatin1Char(' ')) const - QString arg(int a, int fieldWidth = 0, int base = 10, QChar fillChar = QLatin1Char(' ')) const - QString arg(uint a, int fieldWidth = 0, int base = 10, QChar fillChar = QLatin1Char(' ')) const - QString arg(short a, int fieldWidth = 0, int base = 10, QChar fillChar = QLatin1Char(' ')) const - QString arg(ushort a, int fieldWidth = 0, int base = 10, QChar fillChar = QLatin1Char(' ')) const - QString arg(double a, int fieldWidth = 0, char fmt = 'g', int prec = -1, QChar fillChar = QLatin1Char(' ')) const - QString arg(char a, int fieldWidth = 0, QChar fillChar = QLatin1Char(' ')) const - QString arg(QChar a, int fieldWidth = 0, QChar fillChar = QLatin1Char(' ')) const - QString arg(const QString &a, int fieldWidth = 0, QChar fillChar = QLatin1Char(' ')) const - -because they are commonly misused, for example: - - int hours = ...; - int minutes = ...; - // This won't do what you think it would at first glance. - QString s("The time is %1:%2").arg(hours, minutes); - -To reduce false positives, some cases won't be warned about: - - str.arg(hours, 2); // User explicitly used a integer literal, it's probably fine - str.arg(foo); // We're only after cases where the second argument (or further) is specified, so this is safe - str.arg(foo, width); // Second argument is named width, or contains the name "width", it's safe. Same for third argument and "base". - -Using these misleading overloads is perfectly valid, so only warning (1) is enabled by default. -To enable warning (2), `export CLAZY_EXTRA_OPTIONS="qstring-arg-fillChar-overloads"` diff --git a/src/checks/level0/README-qstring-insensitive-allocation.md b/src/checks/level0/README-qstring-insensitive-allocation.md deleted file mode 100644 index d3b2a7e3..00000000 --- a/src/checks/level0/README-qstring-insensitive-allocation.md +++ /dev/null @@ -1,12 +0,0 @@ -# qstring-insensitive-allocation - -Finds unneeded memory allocations such as - `if (str.toLower().contains("foo"))` which you should fix as - `if (str.contains("foo", Qt::CaseInsensitive))` to avoid the heap allocation caused by toLower(). - -Matches any of the following cases: - `str.{toLower, toUpper}().{contains, compare, startsWith, endsWith}()` - -#### Pitfalls -`Qt::CaseInsensitive` is different from `QString::toLower()` comparison for a few code points, but it -should be very rare: <http://lists.qt-project.org/pipermail/development/2016-February/024776.html> diff --git a/src/checks/level0/README-qstring-ref.md b/src/checks/level0/README-qstring-ref.md deleted file mode 100644 index 7dcf05e8..00000000 --- a/src/checks/level0/README-qstring-ref.md +++ /dev/null @@ -1,17 +0,0 @@ -# qstring-ref - -Finds places where `QString::fooRef()` should be used instead of `QString::foo()`, to avoid temporary heap allocations. - -#### Example - - str.mid(5).toInt(ok) // BAD - - str.midRef(5).toInt(ok) // GOOD - -Where `mid` can be any of: `mid`, `left`, `right`. -And `toInt()` can be any of: `compare`, `contains`, `count`, `startsWith`, `endsWith`, `indexOf`, `isEmpty`, `isNull`, `lastIndexOf`, `length`, `size`, `to*`, `trimmed` - -#### FixIts - -Fixing the above cases can be automated with: -`export CLAZY_FIXIT="fix-missing-qstringref"` diff --git a/src/checks/level0/README-qt-macros.md b/src/checks/level0/README-qt-macros.md deleted file mode 100644 index 9d6353d5..00000000 --- a/src/checks/level0/README-qt-macros.md +++ /dev/null @@ -1,7 +0,0 @@ -# qt-macros - -Finds misusages of some Qt macros. - -The two cases are: -- Using `Q_OS_WINDOWS` instead of `Q_OS_WIN` (The former doesn't exist). -- Testing a `Q_OS_XXX` macro before including `qglobal.h` diff --git a/src/checks/level0/README-qvariant-template-instantiation.md b/src/checks/level0/README-qvariant-template-instantiation.md deleted file mode 100644 index 9a8f5e9a..00000000 --- a/src/checks/level0/README-qvariant-template-instantiation.md +++ /dev/null @@ -1,5 +0,0 @@ -# qvariant-template-instantiation - -Detects when you're using `QVariant::value<Foo>()` instead of `QVariant::toFoo()`. - -The former results in more code being generated. diff --git a/src/checks/level0/README-strict-iterators.md b/src/checks/level0/README-strict-iterators.md deleted file mode 100644 index 0730710a..00000000 --- a/src/checks/level0/README-strict-iterators.md +++ /dev/null @@ -1,19 +0,0 @@ -# strict-iterators - -Warns when `iterator` objects are implicitly cast to `const_iterator`. -This is mostly equivalent to passing -DQT_STRICT_ITERATORS to the compiler. -This prevents detachments but also caches subtle bugs such as: - - QHash<int, int> wrong; - if (wrong.find(1) == wrong.cend()) { - qDebug() << "Not found"; - } else { - qDebug() << "Found"; // find() detached the container before cend() was called, so it prints "Found" - } - - QHash<int, int> right; - if (right.constFind(1) == right.cend()) { - qDebug() << "Not found"; // This is correct now ! - } else { - qDebug() << "Found"; - } diff --git a/src/checks/level0/README-temporary-iterator.md b/src/checks/level0/README-temporary-iterator.md deleted file mode 100644 index c9dcd776..00000000 --- a/src/checks/level0/README-temporary-iterator.md +++ /dev/null @@ -1,22 +0,0 @@ -# temporary-iterator - -Detects when you're using using functions returning iterators (eg. `begin()` or `end()`) on a temporary container. - -#### Example - - // temporary list returned by function - QList<type> getList() - { - QList<type> list; - ... add some items to list ... - return list; - } - - // Will cause a crash if iterated using: - - for (QList<type>::iterator it = getList().begin(); it != getList().end(); ++it) - { - ... - } - -because the end iterator was returned from a different container object than the begin iterator. diff --git a/src/checks/level0/README-unused-non-trivial-variable.md b/src/checks/level0/README-unused-non-trivial-variable.md deleted file mode 100644 index 377344bd..00000000 --- a/src/checks/level0/README-unused-non-trivial-variable.md +++ /dev/null @@ -1,16 +0,0 @@ -# unused-non-trivial-variable - - Warns about unused Qt value classes. - Compilers usually only warn when trivial classes are unused and don't emit warnings for non-trivial classes. - - This check has a whitelist of common Qt classes such as containers, `QFont`, `QUrl`, etc and warns for those too. - - See `UnusedNonTrivialType::isInterestingType(QualType t)` for a list of all types. - - It's possible to extend the whitelist with user types, by setting the env variable `CLAZY_UNUSED_NON_TRIVIAL_VARIABLE_WHITELIST`. - It accepts a comma separate name of types. - - It's possible to disable the whitelist via exporting `CLAZY_EXTRA_OPTIONS=unused-non-trivial-variable-no-whitelist`, - when this env variable is set clazy will warn for any unused non-trivial type. This will create many false positives, - such as RAII classes, but still useful to run at least once on your codebase. When disabling the whitelist this way it's also possible - to black list types, by setting a comma separated list of types to `CLAZY_UNUSED_NON_TRIVIAL_VARIABLE_BLACKLIST` diff --git a/src/checks/level0/README-writing-to-temporary.md b/src/checks/level0/README-writing-to-temporary.md deleted file mode 100644 index f39eb5d4..00000000 --- a/src/checks/level0/README-writing-to-temporary.md +++ /dev/null @@ -1,19 +0,0 @@ -# writing-to-temporary - -Catches when calling setters on temporaries. -#### Example -`widget->sizePolicy().setHorizontalStretch(1);` - -Which should instead be: -``` -QSizePolicy sp = widget->sizePolicy(); -sp.setHorizontalStretch(1); -widget->setSizePolicy(sp); -``` - -#### Requirements -- The method must be of void return type, and must belong to one of these whitelisted classes: - QList, QVector, QMap, QHash, QString, QSet, QByteArray, QUrl, QVarLengthArray, QLinkedList, QRect, QRectF, QBitmap, QVector2D, QVector3D, QVector4D, QSize, QSizeF, QSizePolicy - -- Optionally, if you set env variable `CLAZY_EXTRA_OPTIONS="writing-to-temporary-widen-criteria"`, it will warn on any method with name starting with "set", regardless of it being whitelisted, example: -`foo().setBar()` diff --git a/src/checks/level0/README-wrong-qevent-cast.md b/src/checks/level0/README-wrong-qevent-cast.md deleted file mode 100644 index 96244231..00000000 --- a/src/checks/level0/README-wrong-qevent-cast.md +++ /dev/null @@ -1,11 +0,0 @@ -# wrong-qevent-cast - -Warns when a QEvent is possibly cast to the wrong derived class via static_cast. - -Example: -switch (ev->type()) { - case QEvent::MouseMove: - auto e = static_cast<QKeyEvent*>(ev); -} - -Currently only casts inside switches are verified. diff --git a/src/checks/level0/README-wrong-qglobalstatic.md b/src/checks/level0/README-wrong-qglobalstatic.md deleted file mode 100644 index 70734870..00000000 --- a/src/checks/level0/README-wrong-qglobalstatic.md +++ /dev/null @@ -1,14 +0,0 @@ -# wrong-qglobalstatic - -Finds `Q_GLOBAL_STATIC`s being used with trivial types. -This is unnecessary and creates code bloat. - -#### Example: - - struct Trivial - { - int v; - }; - - Q_GLOBAL_STATIC(Trivial, t); // Wrong - static Trivial t; // Correct |