quickshell/src/debug/lint.cpp
outfoxxed 783b97152a
Some checks failed
Build / Nix (push) Has been cancelled
Build / Nix-1 (push) Has been cancelled
Build / Nix-2 (push) Has been cancelled
Build / Nix-3 (push) Has been cancelled
Build / Nix-4 (push) Has been cancelled
Build / Nix-5 (push) Has been cancelled
Build / Nix-6 (push) Has been cancelled
Build / Nix-7 (push) Has been cancelled
Build / Nix-8 (push) Has been cancelled
Build / Nix-9 (push) Has been cancelled
Build / Nix-10 (push) Has been cancelled
Build / Nix-11 (push) Has been cancelled
Build / Nix-12 (push) Has been cancelled
Build / Nix-13 (push) Has been cancelled
Build / Nix-14 (push) Has been cancelled
Build / Nix-15 (push) Has been cancelled
Build / Nix-16 (push) Has been cancelled
Build / Nix-17 (push) Has been cancelled
Build / Nix-18 (push) Has been cancelled
Build / Nix-19 (push) Has been cancelled
Build / Nix-20 (push) Has been cancelled
Build / Nix-21 (push) Has been cancelled
Build / Nix-22 (push) Has been cancelled
Build / Nix-23 (push) Has been cancelled
Build / Nix-24 (push) Has been cancelled
Build / Nix-25 (push) Has been cancelled
Build / Nix-26 (push) Has been cancelled
Build / Nix-27 (push) Has been cancelled
Build / Nix-28 (push) Has been cancelled
Build / Nix-29 (push) Has been cancelled
Build / Nix-30 (push) Has been cancelled
Build / Nix-31 (push) Has been cancelled
Build / Nix-32 (push) Has been cancelled
Build / Nix-33 (push) Has been cancelled
Build / Archlinux (push) Has been cancelled
Lint / Lint (push) Has been cancelled
build: update CI, nix checkouts, lints
2026-01-13 23:20:55 -08:00

82 lines
1.9 KiB
C++

#include "lint.hpp"
#include <algorithm>
#include <qlogging.h>
#include <qloggingcategory.h>
#include <qobject.h>
#include <qqmlcontext.h>
#include <qqmlengine.h>
#include <qqmlinfo.h>
#include <qquickitem.h>
#include <qquickwindow.h>
#include <qstring.h>
#include "../core/logcat.hpp"
namespace qs::debug {
namespace {
QS_LOGGING_CATEGORY(logLint, "quickshell.linter", QtWarningMsg);
void lintZeroSized(QQuickItem* item);
bool isRenderable(QQuickItem* item);
} // namespace
void lintObjectTree(QObject* object) {
if (!logLint().isWarningEnabled()) return;
for (auto* child: object->children()) {
if (child->isQuickItemType()) {
auto* item = static_cast<QQuickItem*>(child); // NOLINT;
lintItemTree(item);
} else {
lintObjectTree(child);
}
}
}
void lintItemTree(QQuickItem* item) {
if (!logLint().isWarningEnabled()) return;
lintZeroSized(item);
for (auto* child: item->childItems()) {
lintItemTree(child);
}
}
namespace {
void lintZeroSized(QQuickItem* item) {
if (!item->isEnabled() || !item->isVisible()) return;
if (item->childItems().isEmpty()) return;
auto zeroWidth = item->width() == 0;
auto zeroHeight = item->height() == 0;
if (!zeroWidth && !zeroHeight) return;
if (!isRenderable(item)) return;
auto* ctx = QQmlEngine::contextForObject(item);
if (!ctx || ctx->baseUrl().scheme() != QStringLiteral("qsintercept")) return;
qmlWarning(item) << "Item is visible and has visible children, but has zero "
<< (zeroWidth && zeroHeight ? "width and height"
: zeroWidth ? "width"
: "height");
}
bool isRenderable(QQuickItem* item) {
if (!item->isEnabled() || !item->isVisible()) return false;
if (item->flags().testFlags(QQuickItem::ItemHasContents)) {
return true;
}
return std::ranges::any_of(item->childItems(), [](auto* item) { return isRenderable(item); });
}
} // namespace
} // namespace qs::debug