Skip to content

Commit

Permalink
🧹 chore: clang-tidy improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Sclafus committed Jun 19, 2024
1 parent 13aa386 commit 6c20b37
Show file tree
Hide file tree
Showing 39 changed files with 685 additions and 648 deletions.
147 changes: 147 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# Generated from CLion Inspection settings
---
Checks: '-*,
bugprone-argument-comment,
bugprone-assert-side-effect,
bugprone-bad-signal-to-kill-thread,
bugprone-branch-clone,
bugprone-copy-constructor-init,
bugprone-dangling-handle,
bugprone-dynamic-static-initializers,
bugprone-fold-init-type,
bugprone-forward-declaration-namespace,
bugprone-forwarding-reference-overload,
bugprone-inaccurate-erase,
bugprone-incorrect-roundings,
bugprone-integer-division,
bugprone-lambda-function-name,
bugprone-macro-parentheses,
bugprone-macro-repeated-side-effects,
bugprone-misplaced-operator-in-strlen-in-alloc,
bugprone-misplaced-pointer-arithmetic-in-alloc,
bugprone-misplaced-widening-cast,
bugprone-move-forwarding-reference,
bugprone-multiple-statement-macro,
bugprone-no-escape,
bugprone-parent-virtual-call,
bugprone-posix-return,
bugprone-reserved-identifier,
bugprone-sizeof-container,
bugprone-sizeof-expression,
bugprone-spuriously-wake-up-functions,
bugprone-string-constructor,
bugprone-string-integer-assignment,
bugprone-string-literal-with-embedded-nul,
bugprone-suspicious-enum-usage,
bugprone-suspicious-include,
bugprone-suspicious-memset-usage,
bugprone-suspicious-missing-comma,
bugprone-suspicious-semicolon,
bugprone-suspicious-string-compare,
bugprone-suspicious-memory-comparison,
bugprone-suspicious-realloc-usage,
bugprone-swapped-arguments,
bugprone-terminating-continue,
bugprone-throw-keyword-missing,
bugprone-too-small-loop-variable,
bugprone-undefined-memory-manipulation,
bugprone-undelegated-constructor,
bugprone-unhandled-self-assignment,
bugprone-unused-raii,
bugprone-unused-return-value,
bugprone-use-after-move,
bugprone-virtual-near-miss,
cert-dcl21-cpp,
cert-dcl58-cpp,
cert-err34-c,
cert-err52-cpp,
cert-err60-cpp,
cert-flp30-c,
cert-msc50-cpp,
cert-msc51-cpp,
cert-str34-c,
cppcoreguidelines-interfaces-global-init,
cppcoreguidelines-narrowing-conversions,
cppcoreguidelines-pro-type-member-init,
cppcoreguidelines-pro-type-static-cast-downcast,
cppcoreguidelines-slicing,
google-default-arguments,
google-explicit-constructor,
google-runtime-operator,
hicpp-exception-baseclass,
hicpp-multiway-paths-covered,
misc-misplaced-const,
misc-new-delete-overloads,
misc-no-recursion,
misc-non-copyable-objects,
misc-throw-by-value-catch-by-reference,
misc-unconventional-assign-operator,
misc-uniqueptr-reset-release,
modernize-avoid-bind,
modernize-concat-nested-namespaces,
modernize-deprecated-headers,
modernize-deprecated-ios-base-aliases,
modernize-loop-convert,
modernize-make-shared,
modernize-make-unique,
modernize-pass-by-value,
modernize-raw-string-literal,
modernize-redundant-void-arg,
modernize-replace-auto-ptr,
modernize-replace-disallow-copy-and-assign-macro,
modernize-replace-random-shuffle,
modernize-return-braced-init-list,
modernize-shrink-to-fit,
modernize-unary-static-assert,
modernize-use-auto,
modernize-use-bool-literals,
modernize-use-emplace,
modernize-use-equals-default,
modernize-use-equals-delete,
modernize-use-nodiscard,
modernize-use-noexcept,
modernize-use-nullptr,
modernize-use-override,
modernize-use-transparent-functors,
modernize-use-uncaught-exceptions,
mpi-buffer-deref,
mpi-type-mismatch,
openmp-use-default-none,
performance-faster-string-find,
performance-for-range-copy,
performance-implicit-conversion-in-loop,
performance-inefficient-algorithm,
performance-inefficient-string-concatenation,
performance-inefficient-vector-operation,
performance-move-const-arg,
performance-move-constructor-init,
performance-no-automatic-move,
performance-noexcept-move-constructor,
performance-trivially-destructible,
performance-type-promotion-in-math-fn,
performance-unnecessary-copy-initialization,
performance-unnecessary-value-param,
portability-simd-intrinsics,
readability-avoid-const-params-in-decls,
readability-const-return-type,
readability-container-size-empty,
readability-convert-member-functions-to-static,
readability-delete-null-pointer,
readability-deleted-default,
readability-inconsistent-declaration-parameter-name,
readability-make-member-function-const,
readability-misleading-indentation,
readability-misplaced-array-index,
readability-non-const-parameter,
readability-redundant-control-flow,
readability-redundant-declaration,
readability-redundant-function-ptr-dereference,
readability-redundant-smartptr-get,
readability-redundant-string-cstr,
readability-redundant-string-init,
readability-simplify-subscript-expr,
readability-static-accessed-through-instance,
readability-static-definition-in-anonymous-namespace,
readability-string-compare,
readability-uniqueptr-delete-release,
readability-use-anyofallof'
10 changes: 8 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ compile_commands.json

# Cmake builds
build*
bin*

# VSCode
.vscode

# Testing stuff
*.conf
*.json

#Visual Studio
.vscode
16 changes: 7 additions & 9 deletions src/backup/backup.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#include "backup.h"


void Backup::backup(QString filePath, bool includeSensitiveInfo)
{
void Backup::backup(QString filePath, bool includeSensitiveInfo) {
if (filePath.isEmpty()) {
return;
}

// adding .json if needed
if(!filePath.endsWith(".json")) {
if (!filePath.endsWith(".json")) {
filePath.append(".json");
}

Expand All @@ -26,13 +25,13 @@ void Backup::backup(QString filePath, bool includeSensitiveInfo)
QStringList keys = settings.allKeys();

// sensitive info must be excluded
if(!includeSensitiveInfo) {
keys.removeIf([](const QString& key){
if (!includeSensitiveInfo) {
keys.removeIf([](const QString &key) {
return key.startsWith("osuirc") || key.startsWith("twitch");
});
}

for(const QString& key: keys){
for (const QString &key: keys) {
QString value = settings.value(key).toString();
jsonObject.insert(key, QJsonValue(value));
}
Expand All @@ -45,8 +44,7 @@ void Backup::backup(QString filePath, bool includeSensitiveInfo)
qDebug() << "[Backup] Backup completed";
}

void Backup::restore(QString filePath)
{
void Backup::restore(const QString &filePath) {
if (filePath.isEmpty()) {
return;
}
Expand All @@ -65,7 +63,7 @@ void Backup::restore(QString filePath)

QSettings settings;
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonString.toUtf8());
if (!jsonDoc.isNull()){
if (!jsonDoc.isNull()) {
QJsonObject jsonObject = jsonDoc.object();
for (auto it = jsonObject.begin(); it != jsonObject.end(); ++it) {
QString key = it.key();
Expand Down
7 changes: 4 additions & 3 deletions src/backup/backup.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
#include <QObject>
#include <QSettings>

class Backup
{
// @formatter:off
class Backup {
public:
static void backup(QString filePath, bool includeSensitiveInfo);
static void restore(QString filePath);
static void restore(const QString &filePath);
};
// @formatter:on

#endif // BACKUP_H
55 changes: 24 additions & 31 deletions src/commands/commandswindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,79 +2,73 @@
#include "ui_commandswindow.h"

CommandsWindow::CommandsWindow(QWidget *parent) :
QDialog(parent),
ui(new Ui::CommandsWindow)
{
QDialog(parent),
ui(new Ui::CommandsWindow) {
ui->setupUi(this);
loadData();
connect(ui->addCommandBtn, &QPushButton::clicked, this, &CommandsWindow::on_addCommandBtn_clicked);
connect(ui->removeCommandBtn, &QPushButton::clicked, this, &CommandsWindow::on_removeCommandBtn_clicked);
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &CommandsWindow::on_saveBtn_clicked);
}

CommandsWindow::~CommandsWindow()
{
delete ui;
CommandsWindow::~CommandsWindow() {
delete ui;
}

void CommandsWindow::loadData()
{
void CommandsWindow::loadData() {
qDebug() << "[Commands] Loading data";
QSettings settings;
settings.beginGroup("command");
QStringList commands = settings.childKeys();

for (QString command: commands) {
for (const QString &command: commands) {
addRow(command, settings.value(command).toString());
}
}

void CommandsWindow::addRow(QString command, QString response)
{
void CommandsWindow::addRow(const QString &command, const QString &response) {
// adding new line
ui->commandsTable->insertRow(ui->commandsTable->rowCount());
QTableWidgetItem *commandNameItem = new QTableWidgetItem(command);
QTableWidgetItem *commandResponseItem = new QTableWidgetItem(response);
auto *commandNameItem = new QTableWidgetItem(command);
auto *commandResponseItem = new QTableWidgetItem(response);

// Command name column
ui->commandsTable->setItem(
ui->commandsTable->rowCount() - 1,
0,
commandNameItem
ui->commandsTable->rowCount() - 1,
0,
commandNameItem
);

// Command response column
ui->commandsTable->setItem(
ui->commandsTable->rowCount() - 1,
1,
commandResponseItem
ui->commandsTable->rowCount() - 1,
1,
commandResponseItem
);
}

void CommandsWindow::on_addCommandBtn_clicked()
{
void CommandsWindow::on_addCommandBtn_clicked() {
int lastRow = ui->commandsTable->rowCount() - 1;
auto lastCommand = ui->commandsTable->item(lastRow, 0);
auto lastResponse = ui->commandsTable->item(lastRow, 1);

bool isLastCommandEmpty = lastCommand != nullptr && lastCommand->text().isEmpty();
bool isLastResponseEmpty = lastResponse != nullptr && lastResponse->text().isEmpty();

if (!isLastCommandEmpty && !isLastResponseEmpty){
addRow("","");
if (!isLastCommandEmpty && !isLastResponseEmpty) {
addRow("", "");
}
}

void CommandsWindow::on_removeCommandBtn_clicked()
{
void CommandsWindow::on_removeCommandBtn_clicked() {
QSettings settings;
auto selectionModel = ui->commandsTable->selectionModel();
if (!selectionModel->hasSelection()){
if (!selectionModel->hasSelection()) {
return;
}

auto selected = selectionModel->selectedIndexes();
for (auto selection : selected) {
for (auto selection: selected) {
int row = selection.row();
QString command = ui->commandsTable->item(row, 0)->text();

Expand All @@ -83,21 +77,20 @@ void CommandsWindow::on_removeCommandBtn_clicked()
}
}

void CommandsWindow::on_saveBtn_clicked()
{
void CommandsWindow::on_saveBtn_clicked() {
qDebug() << "[Commands] Saving data...";
QSettings settings;

for (int row = 2; row < ui->commandsTable->rowCount(); row++) {
QTableWidgetItem *commandNameItem = ui->commandsTable->item(row, 0);
QTableWidgetItem *commandResponseItem = ui->commandsTable->item(row, 1);
QTableWidgetItem *commandResponseItem = ui->commandsTable->item(row, 1);

if (commandResponseItem == nullptr || commandNameItem == nullptr) {
return;
}

QString commandName = commandNameItem->text();
QString commandResponse = commandResponseItem->text();
QString commandResponse = commandResponseItem->text();

if (!commandName.startsWith("!")) {
commandName.prepend("!");
Expand Down
Loading

0 comments on commit 6c20b37

Please sign in to comment.