From 8a12307a6b7a8ff103b37926bbcb0d99c7227d3c Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Fri, 27 Sep 2024 19:25:48 +0100 Subject: [PATCH] Apply Clang format --- .clang-format | 28 +++++++++++++++++++ src/lib/synergy/gui/ActivationDialog.cpp | 8 ++++-- src/lib/synergy/gui/ActivationDialog.h | 4 +-- .../synergy/gui/license/LicenseHandler.cpp | 13 ++++----- src/lib/synergy/gui/license/LicenseHandler.h | 4 +-- src/lib/synergy/license/SerialKeyType.h | 4 +-- src/lib/synergy/license/parse_serial_key.h | 4 +-- .../gui/license/license_notices_tests.cpp | 19 +++++++------ 8 files changed, 58 insertions(+), 26 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..6a994d72f --- /dev/null +++ b/.clang-format @@ -0,0 +1,28 @@ +# Important: Use the same version of clang-format as our linter, which is: +# +# $ ./scripts/install_deps.py --only-python +# $ ./.venv/bin/clang-format --version +# +# Warning: If you use a different version, the formatting will be different. +# +# To install a specific version of clang-format, use pip: +# $ pip install clang-format== + +BasedOnStyle: LLVM + +# Turn off LLVM default alignment of params with the opening bracket, +# which can be less readable in some cases in our code base. +# +# Using `AlwaysBreak` will result in: +# void fooBarBazQuxHelloWorld( +# int a, +# int b); +# +# Instead of: +# void fooBarBazQuxHelloWorld(int a, +# int b); +AlignAfterOpenBracket: AlwaysBreak + +# Turn off LLVM default packing of ctor initializers. +# This makes it easier to see which members were initialized and in what order. +PackConstructorInitializers: CurrentLine diff --git a/src/lib/synergy/gui/ActivationDialog.cpp b/src/lib/synergy/gui/ActivationDialog.cpp index 918dde628..6ab67d01f 100644 --- a/src/lib/synergy/gui/ActivationDialog.cpp +++ b/src/lib/synergy/gui/ActivationDialog.cpp @@ -44,9 +44,11 @@ QString serialKey() { return ""; } // TODO bool isAvailableAndEnabled(const TlsUtility &tls) { return false; } -ActivationDialog::ActivationDialog(QWidget *parent, AppConfig &appConfig, - LicenseHandler &licenseHandler) - : QDialog(parent), m_ui(new Ui::ActivationDialog), m_pAppConfig(&appConfig), +ActivationDialog::ActivationDialog( + QWidget *parent, AppConfig &appConfig, LicenseHandler &licenseHandler) + : QDialog(parent), + m_ui(new Ui::ActivationDialog), + m_pAppConfig(&appConfig), m_licenseHandler(licenseHandler) { m_ui->setupUi(this); diff --git a/src/lib/synergy/gui/ActivationDialog.h b/src/lib/synergy/gui/ActivationDialog.h index f249d224d..6520190fa 100644 --- a/src/lib/synergy/gui/ActivationDialog.h +++ b/src/lib/synergy/gui/ActivationDialog.h @@ -31,8 +31,8 @@ class ActivationDialog : public QDialog { Q_OBJECT public: - ActivationDialog(QWidget *parent, AppConfig &appConfig, - LicenseHandler &licenseHandler); + ActivationDialog( + QWidget *parent, AppConfig &appConfig, LicenseHandler &licenseHandler); ~ActivationDialog() override; class ActivationMessageError : public std::runtime_error { diff --git a/src/lib/synergy/gui/license/LicenseHandler.cpp b/src/lib/synergy/gui/license/LicenseHandler.cpp index 37a9566fc..28aa629a8 100644 --- a/src/lib/synergy/gui/license/LicenseHandler.cpp +++ b/src/lib/synergy/gui/license/LicenseHandler.cpp @@ -70,8 +70,8 @@ bool LicenseHandler::handleStart(QMainWindow *parent, AppConfig *appConfig) { return showActivationDialog(parent, appConfig); } -bool LicenseHandler::showActivationDialog(QMainWindow *parent, - AppConfig *appConfig) { +bool LicenseHandler::showActivationDialog( + QMainWindow *parent, AppConfig *appConfig) { ActivationDialog dialog(parent, *appConfig, *this); const auto result = dialog.exec(); if (result == QDialog::Accepted) { @@ -91,8 +91,8 @@ void LicenseHandler::updateMainWindow() const { m_mainWindow->setWindowTitle(m_license.productName().c_str()); } -void LicenseHandler::handleSettings(QDialog *parent, - QCheckBox *checkBoxEnableTls) const { +void LicenseHandler::handleSettings( + QDialog *parent, QCheckBox *checkBoxEnableTls) const { const auto onTlsToggle = [this, parent, checkBoxEnableTls] { qDebug("tls checkbox toggled"); @@ -104,9 +104,8 @@ void LicenseHandler::handleSettings(QDialog *parent, checkTlsCheckBox(parent, checkBoxEnableTls, false); } -void LicenseHandler::checkTlsCheckBox(QDialog *parent, - QCheckBox *checkBoxEnableTls, - bool showDialog) const { +void LicenseHandler::checkTlsCheckBox( + QDialog *parent, QCheckBox *checkBoxEnableTls, bool showDialog) const { if (!m_license.isTlsAvailable() && checkBoxEnableTls->isChecked()) { qDebug("tls not available, showing upgrade dialog"); checkBoxEnableTls->setChecked(false); diff --git a/src/lib/synergy/gui/license/LicenseHandler.h b/src/lib/synergy/gui/license/LicenseHandler.h index 0e81e4cdb..c3f983627 100644 --- a/src/lib/synergy/gui/license/LicenseHandler.h +++ b/src/lib/synergy/gui/license/LicenseHandler.h @@ -58,8 +58,8 @@ class LicenseHandler : public QObject { void setEnabled(bool enabled) { m_enabled = enabled; } bool handleStart(QMainWindow *parent, AppConfig *appConfig); void handleSettings(QDialog *parent, QCheckBox *checkBoxEnableTls) const; - void checkTlsCheckBox(QDialog *parent, QCheckBox *checkBoxEnableTls, - bool showDialog) const; + void checkTlsCheckBox( + QDialog *parent, QCheckBox *checkBoxEnableTls, bool showDialog) const; void updateMainWindow() const; bool showActivationDialog(QMainWindow *parent, AppConfig *appConfig); diff --git a/src/lib/synergy/license/SerialKeyType.h b/src/lib/synergy/license/SerialKeyType.h index 4be1ed119..9f7516732 100644 --- a/src/lib/synergy/license/SerialKeyType.h +++ b/src/lib/synergy/license/SerialKeyType.h @@ -21,8 +21,8 @@ class SerialKeyType { private: - friend bool operator==(SerialKeyType const &lhs, - SerialKeyType const &rhs) = default; + friend bool + operator==(SerialKeyType const &lhs, SerialKeyType const &rhs) = default; public: static const std::string Trial; diff --git a/src/lib/synergy/license/parse_serial_key.h b/src/lib/synergy/license/parse_serial_key.h index e41771da6..c8232c483 100644 --- a/src/lib/synergy/license/parse_serial_key.h +++ b/src/lib/synergy/license/parse_serial_key.h @@ -41,8 +41,8 @@ class InvalidSerialKeyFormat : public SerialKeyParseError { class InvalidSerialKeyDate : public SerialKeyParseError { public: - explicit InvalidSerialKeyDate(const std::string &date, - const std::string &cause) + explicit InvalidSerialKeyDate( + const std::string &date, const std::string &cause) : SerialKeyParseError("invalid serial key date: " + date + "\n" + cause) { } }; diff --git a/src/test/unittests/gui/license/license_notices_tests.cpp b/src/test/unittests/gui/license/license_notices_tests.cpp index 5991ee884..a210db3ce 100644 --- a/src/test/unittests/gui/license/license_notices_tests.cpp +++ b/src/test/unittests/gui/license/license_notices_tests.cpp @@ -96,8 +96,9 @@ TEST(license_notices_tests, licenseNotice_subscriptionExpired_correctText) { EXPECT_THAT(notice.toStdString(), HasSubstr("Your license has expired")); } -TEST(license_notices_tests, - licenseNotice_subscriptionExpiringInOneHour_correctText) { +TEST( + license_notices_tests, + licenseNotice_subscriptionExpiringInOneHour_correctText) { SerialKey serialKey(""); serialKey.isValid = true; serialKey.warnTime = kFutureOneHour; @@ -110,8 +111,9 @@ TEST(license_notices_tests, EXPECT_THAT(notice.toStdString(), HasSubstr("Your license expires today")); } -TEST(license_notices_tests, - licenseNotice_subscriptionExpiringInOneDay_correctText) { +TEST( + license_notices_tests, + licenseNotice_subscriptionExpiringInOneDay_correctText) { SerialKey serialKey(""); serialKey.isValid = true; serialKey.warnTime = kFutureOneDay; @@ -124,8 +126,9 @@ TEST(license_notices_tests, EXPECT_THAT(notice.toStdString(), HasSubstr("Your license expires in 1 day")); } -TEST(license_notices_tests, - licenseNotice_subscriptionExpiringInOneWeek_correctText) { +TEST( + license_notices_tests, + licenseNotice_subscriptionExpiringInOneWeek_correctText) { SerialKey serialKey(""); serialKey.isValid = true; serialKey.warnTime = kFutureOneWeek; @@ -135,6 +138,6 @@ TEST(license_notices_tests, QString notice = licenseNotice(license); - EXPECT_THAT(notice.toStdString(), - HasSubstr("Your license expires in 7 days")); + EXPECT_THAT( + notice.toStdString(), HasSubstr("Your license expires in 7 days")); }