Skip to content

Commit

Permalink
core: clang-tidy and comp fixes (#679)
Browse files Browse the repository at this point in the history
* clang-tidy and comp fixes

* nit changes
  • Loading branch information
Honkazel authored Feb 6, 2025
1 parent ce75045 commit dc6d721
Show file tree
Hide file tree
Showing 18 changed files with 219 additions and 114 deletions.
101 changes: 101 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
WarningsAsErrors: '*'
HeaderFilterRegex: '.*\.hpp'
FormatStyle: file
Checks: >
-*,
bugprone-*,
-bugprone-easily-swappable-parameters,
-bugprone-forward-declararion-namespace,
-bugprone-forward-declararion-namespace,
-bugprone-macro-parentheses,
-bugprone-narrowing-conversions,
-bugprone-branch-clone,
-bugprone-assignment-in-if-condition,
concurrency-*,
-concurrency-mt-unsafe,
cppcoreguidelines-*,
-cppcoreguidelines-owning-memory,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-pro-bounds-constant-array-index,
-cppcoreguidelines-avoid-const-or-ref-data-members,
-cppcoreguidelines-non-private-member-variables-in-classes,
-cppcoreguidelines-avoid-goto,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
-cppcoreguidelines-avoid-do-while,
-cppcoreguidelines-avoid-non-const-global-variables,
-cppcoreguidelines-special-member-functions,
-cppcoreguidelines-explicit-virtual-functions,
-cppcoreguidelines-avoid-c-arrays,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-cppcoreguidelines-narrowing-conversions,
-cppcoreguidelines-pro-type-union-access,
-cppcoreguidelines-pro-type-member-init,
-cppcoreguidelines-macro-usage,
-cppcoreguidelines-macro-to-enum,
-cppcoreguidelines-init-variables,
-cppcoreguidelines-pro-type-cstyle-cast,
-cppcoreguidelines-pro-type-vararg,
-cppcoreguidelines-pro-type-reinterpret-cast,
google-global-names-in-headers,
-google-readability-casting,
google-runtime-operator,
misc-*,
-misc-unused-parameters,
-misc-no-recursion,
-misc-non-private-member-variables-in-classes,
-misc-include-cleaner,
-misc-use-anonymous-namespace,
-misc-const-correctness,
modernize-*,
-modernize-return-braced-init-list,
-modernize-use-trailing-return-type,
-modernize-use-using,
-modernize-use-override,
-modernize-avoid-c-arrays,
-modernize-macro-to-enum,
-modernize-loop-convert,
-modernize-use-nodiscard,
-modernize-pass-by-value,
-modernize-use-auto,
performance-*,
-performance-avoid-endl,
-performance-unnecessary-value-param,
portability-std-allocator-const,
readability-*,
-readability-function-cognitive-complexity,
-readability-function-size,
-readability-identifier-length,
-readability-magic-numbers,
-readability-uppercase-literal-suffix,
-readability-braces-around-statements,
-readability-redundant-access-specifiers,
-readability-else-after-return,
-readability-container-data-pointer,
-readability-implicit-bool-conversion,
-readability-avoid-nested-conditional-operator,
-readability-redundant-member-init,
-readability-redundant-string-init,
-readability-avoid-const-params-in-decls,
-readability-named-parameter,
-readability-convert-member-functions-to-static,
-readability-qualified-auto,
-readability-make-member-function-const,
-readability-isolate-declaration,
-readability-inconsistent-declaration-parameter-name,
-clang-diagnostic-error,
CheckOptions:
performance-for-range-copy.WarnOnAllAutoCopies: true
performance-inefficient-string-concatenation.StrictMode: true
readability-braces-around-statements.ShortStatementLines: 0
readability-identifier-naming.ClassCase: CamelCase
readability-identifier-naming.ClassIgnoredRegexp: I.*
readability-identifier-naming.ClassPrefix: C # We can't use regex here?!?!?!?
readability-identifier-naming.EnumCase: CamelCase
readability-identifier-naming.EnumPrefix: e
readability-identifier-naming.EnumConstantCase: UPPER_CASE
readability-identifier-naming.FunctionCase: camelBack
readability-identifier-naming.NamespaceCase: CamelCase
readability-identifier-naming.NamespacePrefix: N
readability-identifier-naming.StructPrefix: S
readability-identifier-naming.StructCase: CamelCase
8 changes: 4 additions & 4 deletions src/auth/Pam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ int conv(int num_msg, const struct pam_message** msg, struct pam_response** resp
Debug::log(LOG, "PAM: {}", msg[i]->msg);
// Targets this log from pam_faillock: https://github.com/linux-pam/linux-pam/blob/fa3295e079dbbc241906f29bde5fb71bc4172771/modules/pam_faillock/pam_faillock.c#L417
if (const auto MSG = std::string(msg[i]->msg); MSG.contains("left to unlock")) {
CONVERSATIONSTATE->failText = std::move(MSG);
CONVERSATIONSTATE->failText = MSG;
CONVERSATIONSTATE->failTextFromPam = true;
}
break;
Expand All @@ -65,7 +65,7 @@ CPam::CPam() {
m_sPamModule = *PAMMODULE;

if (!std::filesystem::exists(std::filesystem::path("/etc/pam.d/") / m_sPamModule)) {
Debug::log(ERR, "Pam module \"/etc/pam.d/{}\" does not exist! Falling back to \"/etc/pam.d/su\"", m_sPamModule);
Debug::log(ERR, R"(Pam module "/etc/pam.d/{}" does not exist! Falling back to "/etc/pam.d/su")", m_sPamModule);
m_sPamModule = "su";
}

Expand Down Expand Up @@ -106,8 +106,8 @@ void CPam::init() {
}

bool CPam::auth() {
const pam_conv localConv = {conv, (void*)&m_sConversationState};
pam_handle_t* handle = NULL;
const pam_conv localConv = {.conv = conv, .appdata_ptr = (void*)&m_sConversationState};
pam_handle_t* handle = nullptr;
auto uidPassword = getpwuid(getuid());
RASSERT(uidPassword && uidPassword->pw_name, "Failed to get username (getpwuid)");

Expand Down
44 changes: 22 additions & 22 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <hyprlang.hpp>
#include <hyprutils/string/String.hpp>
#include <hyprutils/path/Path.hpp>
#include <hyprutils/string/String.hpp>
#include <filesystem>
#include <glob.h>
#include <cstring>
Expand Down Expand Up @@ -149,7 +148,7 @@ static Hyprlang::CParseResult configHandleGradientSet(const char* VALUE, void**
continue;

try {
DATA->m_vColors.push_back(CHyprColor(configStringToInt(var)));
DATA->m_vColors.emplace_back(configStringToInt(var));
} catch (std::exception& e) {
Debug::log(WARN, "Error parsing gradient {}", V);
parseError = "Error parsing gradient " + V + ": " + e.what();
Expand All @@ -158,14 +157,14 @@ static Hyprlang::CParseResult configHandleGradientSet(const char* VALUE, void**

if (V.empty()) {
DATA->m_bIsFallback = true;
DATA->m_vColors.push_back(0); // transparent
DATA->m_vColors.emplace_back(0); // transparent
}

if (DATA->m_vColors.size() == 0) {
Debug::log(WARN, "Error parsing gradient {}", V);
parseError = "Error parsing gradient " + V + ": No colors?";

DATA->m_vColors.push_back(0); // transparent
DATA->m_vColors.emplace_back(0); // transparent
}

DATA->updateColorsOk();
Expand Down Expand Up @@ -322,9 +321,9 @@ void CConfigManager::init() {
m_config.addSpecialConfigValue("label", "zindex", Hyprlang::INT{0});
SHADOWABLE("label");

m_config.registerHandler(&::handleSource, "source", {false});
m_config.registerHandler(&::handleBezier, "bezier", {false});
m_config.registerHandler(&::handleAnimation, "animation", {false});
m_config.registerHandler(&::handleSource, "source", {.allowFlags = false});
m_config.registerHandler(&::handleBezier, "bezier", {.allowFlags = false});
m_config.registerHandler(&::handleAnimation, "animation", {.allowFlags = false});

//
// Init Animations
Expand Down Expand Up @@ -369,12 +368,13 @@ std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {

//
auto keys = m_config.listKeysForSpecialCategory("background");
result.reserve(keys.size());
for (auto& k : keys) {
// clang-format off
result.push_back(CConfigManager::SWidgetConfig{
"background",
std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("background", "monitor", k.c_str())),
{
.type = "background",
.monitor = std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("background", "monitor", k.c_str())),
.values = {
{"path", m_config.getSpecialConfigValue("background", "path", k.c_str())},
{"color", m_config.getSpecialConfigValue("background", "color", k.c_str())},
{"blur_size", m_config.getSpecialConfigValue("background", "blur_size", k.c_str())},
Expand All @@ -398,9 +398,9 @@ std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
for (auto& k : keys) {
// clang-format off
result.push_back(CConfigManager::SWidgetConfig{
"shape",
std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("shape", "monitor", k.c_str())),
{
.type = "shape",
.monitor = std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("shape", "monitor", k.c_str())),
.values = {
{"size", m_config.getSpecialConfigValue("shape", "size", k.c_str())},
{"rounding", m_config.getSpecialConfigValue("shape", "rounding", k.c_str())},
{"border_size", m_config.getSpecialConfigValue("shape", "border_size", k.c_str())},
Expand All @@ -423,9 +423,9 @@ std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
for (auto& k : keys) {
// clang-format off
result.push_back(CConfigManager::SWidgetConfig{
"image",
std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("image", "monitor", k.c_str())),
{
.type = "image",
.monitor = std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("image", "monitor", k.c_str())),
.values = {
{"path", m_config.getSpecialConfigValue("image", "path", k.c_str())},
{"size", m_config.getSpecialConfigValue("image", "size", k.c_str())},
{"rounding", m_config.getSpecialConfigValue("image", "rounding", k.c_str())},
Expand All @@ -448,9 +448,9 @@ std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
for (auto& k : keys) {
// clang-format off
result.push_back(CConfigManager::SWidgetConfig{
"input-field",
std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("input-field", "monitor", k.c_str())),
{
.type = "input-field",
.monitor = std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("input-field", "monitor", k.c_str())),
.values = {
{"size", m_config.getSpecialConfigValue("input-field", "size", k.c_str())},
{"inner_color", m_config.getSpecialConfigValue("input-field", "inner_color", k.c_str())},
{"outer_color", m_config.getSpecialConfigValue("input-field", "outer_color", k.c_str())},
Expand Down Expand Up @@ -490,9 +490,9 @@ std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
for (auto& k : keys) {
// clang-format off
result.push_back(CConfigManager::SWidgetConfig{
"label",
std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("label", "monitor", k.c_str())),
{
.type = "label",
.monitor = std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("label", "monitor", k.c_str())),
.values = {
{"position", m_config.getSpecialConfigValue("label", "position", k.c_str())},
{"color", m_config.getSpecialConfigValue("label", "color", k.c_str())},
{"font_size", m_config.getSpecialConfigValue("label", "font_size", k.c_str())},
Expand Down
4 changes: 2 additions & 2 deletions src/core/AnimationManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void updateColorVariable(CAnimatedVariable<CHyprColor>& av, const float POINTY,
const auto& L1 = av.begun().asOkLab();
const auto& L2 = av.goal().asOkLab();

static const auto lerp = [](const float one, const float two, const float progress) -> float { return one + (two - one) * progress; };
static const auto lerp = [](const float one, const float two, const float progress) -> float { return one + ((two - one) * progress); };

const Hyprgraphics::CColor lerped = Hyprgraphics::CColor::SOkLab{
.l = lerp(L1.l, L2.l, POINTY),
Expand All @@ -57,7 +57,7 @@ void updateGradientVariable(CAnimatedVariable<CGradientValueData>& av, const flo
const auto& L1 = sourceCol.asOkLab();
const auto& L2 = targetCol.asOkLab();

static const auto lerp = [](const float one, const float two, const float progress) -> float { return one + (two - one) * progress; };
static const auto lerp = [](const float one, const float two, const float progress) -> float { return one + ((two - one) * progress); };

const Hyprgraphics::CColor lerped = Hyprgraphics::CColor::SOkLab{
.l = lerp(L1.l, L2.l, POINTY),
Expand Down
10 changes: 5 additions & 5 deletions src/core/Egl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ CEGL::CEGL(wl_display* display) {
throw std::runtime_error("EGL_EXT_platform_wayland not supported");

eglGetPlatformDisplayEXT = (PFNEGLGETPLATFORMDISPLAYEXTPROC)eglGetProcAddress("eglGetPlatformDisplayEXT");
if (eglGetPlatformDisplayEXT == NULL)
if (eglGetPlatformDisplayEXT == nullptr)
throw std::runtime_error("Failed to get eglGetPlatformDisplayEXT");

eglCreatePlatformWindowSurfaceEXT = (PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC)eglGetProcAddress("eglCreatePlatformWindowSurfaceEXT");
if (eglCreatePlatformWindowSurfaceEXT == NULL)
if (eglCreatePlatformWindowSurfaceEXT == nullptr)
throw std::runtime_error("Failed to get eglCreatePlatformWindowSurfaceEXT");

eglDisplay = eglGetPlatformDisplayEXT(EGL_PLATFORM_WAYLAND_EXT, display, NULL);
eglDisplay = eglGetPlatformDisplayEXT(EGL_PLATFORM_WAYLAND_EXT, display, nullptr);
EGLint matched = 0;
if (eglDisplay == EGL_NO_DISPLAY) {
Debug::log(CRIT, "Failed to create EGL display");
goto error;
}

if (eglInitialize(eglDisplay, NULL, NULL) == EGL_FALSE) {
if (eglInitialize(eglDisplay, nullptr, nullptr) == EGL_FALSE) {
Debug::log(CRIT, "Failed to initialize EGL");
goto error;
}
Expand Down Expand Up @@ -83,4 +83,4 @@ CEGL::~CEGL() {

void CEGL::makeCurrent(EGLSurface surf) {
eglMakeCurrent(eglDisplay, surf, surf, eglContext);
}
}
4 changes: 2 additions & 2 deletions src/core/LockSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void CSessionLockSurface::configure(const Vector2D& size_, uint32_t serial_) {
if (!eglSurface) {
eglSurface = g_pEGL->eglCreatePlatformWindowSurfaceEXT(g_pEGL->eglDisplay, g_pEGL->eglConfig, eglWindow, nullptr);
if (!eglSurface) {
Debug::log(CRIT, "Couldn't create eglSurface: {}", (int)eglGetError());
Debug::log(CRIT, "Couldn't create eglSurface: {}", eglGetError());
// Clean up resources to prevent leaks
wl_egl_window_destroy(eglWindow);
eglWindow = nullptr;
Expand Down Expand Up @@ -150,4 +150,4 @@ void CSessionLockSurface::onCallback() {
needsFrame = false;
render();
}
}
}
6 changes: 3 additions & 3 deletions src/core/Timer.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "Timer.hpp"

CTimer::CTimer(std::chrono::system_clock::duration timeout, std::function<void(std::shared_ptr<CTimer> self, void* data)> cb_, void* data_, bool force) : cb(cb_), data(data_) {
expires = std::chrono::system_clock::now() + timeout;
allowForceUpdate = force;
CTimer::CTimer(std::chrono::system_clock::duration timeout, std::function<void(std::shared_ptr<CTimer> self, void* data)> cb_, void* data_, bool force) :
cb(cb_), data(data_), allowForceUpdate(force) {
expires = std::chrono::system_clock::now() + timeout;
}

bool CTimer::passed() {
Expand Down
Loading

0 comments on commit dc6d721

Please sign in to comment.