Skip to content

Commit

Permalink
Merge pull request Murmele#618 from mwerle/feature/clean_build
Browse files Browse the repository at this point in the history
chore: fix compiler warnings
  • Loading branch information
Murmele authored Aug 31, 2023
2 parents e6b5f83 + 6cf922f commit 820c0fd
Show file tree
Hide file tree
Showing 60 changed files with 410 additions and 188 deletions.
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
repos:
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v13.0.1
hooks:
- id: clang-format
args: [ -i ]

9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@ branch. Create pull requests against the `master` branch. Follow the
[seven guidelines](https://chris.beams.io/posts/git-commit/) to writing a
great commit message.

Prior to committing a change, please use `cl-format.sh` to ensure your code
adheres to the formatting conventions for this project. You can also use the
`setup-env.sh` script to install a pre-commit hook which will automatically
run `clang-format` against all modified files.

Prior to pushing a change, please ensure you run the unit tests to avoid any
regressions. These are found in `<build-dir>/test` and can be run using
`ctest`.

License
-------

Expand Down
44 changes: 44 additions & 0 deletions setup-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd "`dirname "$0"`"

PRE_COMMIT=${SCRIPT_DIR}/.venv/bin/pre-commit

pre_commit() {
# Set up pre-commit hook
if [ ! -f "${PRE_COMMIT}" ]; then
pushd ${SCRIPT_DIR}
python3 -m venv .venv
.venv/bin/pip install pre-commit
popd
fi
${PRE_COMMIT} install
}

remove_pre_commt() {
if [ -f "${PRE_COMMIT}" ]; then
${PRE_COMMIT} uninstall
fi
}

if [ $# -eq 0 ]; then
set -- --help
fi

for arg in "$@"; do
case $arg in
pre_commit | pre-commit | install_pre_commit | install-pre-commit)
pre_commit
;;
remove_pre_commit | remove-pre-commit | uninstall_pre_commit | uninstall-pre-commit)
remove_pre_commit
;;
*)
echo "USAGE $0 [commands]"
echo " Commands:"
echo " install-pre-commit - installs pre-commit hooks"
echo " uninstall-pre-commit - removes pre-commit hooks"
;;
esac
done
7 changes: 7 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
include_directories(${CMAKE_CURRENT_SOURCE_DIR})

add_compile_options(-Werror=switch)
# Uncomment to compile with more warnings add_compile_options(-Wall) Uncomment
# to compile with even more warnings add_compile_options(-Wextra) TODO:
# currently there are too many unused parameters which overwhelms the warning
# output with `-Wall`. So let's leave fixing these for later.
add_compile_options(-Wno-unused-parameter)

add_subdirectory(util)
add_subdirectory(cli)
add_subdirectory(conf)
Expand Down
8 changes: 8 additions & 0 deletions src/app/CustomTheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@ QColor CustomTheme::commitEditor(CommitEditor color) {
case CommitEditor::LengthWarning:
return commitEditor.value("lengthwarning").value<QColor>();
}
throw std::runtime_error("unreachable; value=" +
std::to_string(static_cast<int>(color)));
}

QColor CustomTheme::diff(Diff color) {
Expand Down Expand Up @@ -465,6 +467,8 @@ QColor CustomTheme::diff(Diff color) {
case Diff::Error:
return diff.value("error").value<QColor>();
}
throw std::runtime_error("unreachable; value=" +
std::to_string(static_cast<int>(color)));
}

QColor CustomTheme::heatMap(HeatMap color) {
Expand All @@ -476,6 +480,8 @@ QColor CustomTheme::heatMap(HeatMap color) {
case HeatMap::Cold:
return QColor(heatmap.value("cold").toString());
}
throw std::runtime_error("unreachable; value=" +
std::to_string(static_cast<int>(color)));
}

QColor CustomTheme::remoteComment(Comment color) {
Expand All @@ -491,6 +497,8 @@ QColor CustomTheme::remoteComment(Comment color) {
case Comment::Timestamp:
return QColor(comment.value("timestamp").toString());
}
throw std::runtime_error("unreachable; value=" +
std::to_string(static_cast<int>(color)));
}

QColor CustomTheme::star() {
Expand Down
19 changes: 18 additions & 1 deletion src/app/Theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,14 @@ QColor Theme::badge(BadgeRole role, BadgeState state) {
case BadgeState::Head:
return QPalette().color(QPalette::HighlightedText);

default:
case BadgeState::Normal: // fall through
case BadgeState::Conflicted: // fall through
case BadgeState::Notification: // fall through
case BadgeState::Modified: // fall through
case BadgeState::Added: // fall through
case BadgeState::Deleted: // fall through
case BadgeState::Untracked: // fall through
case BadgeState::Renamed: // fall through
return QPalette().color(QPalette::WindowText);
}

Expand Down Expand Up @@ -164,6 +171,8 @@ QColor Theme::commitEditor(CommitEditor color) {
case CommitEditor::LengthWarning:
return Qt::yellow;
}
throw std::runtime_error("unreachable; value=" +
std::to_string(static_cast<int>(color)));
}

QColor Theme::diff(Diff color) {
Expand Down Expand Up @@ -192,6 +201,8 @@ QColor Theme::diff(Diff color) {
case Diff::Error:
return "#7E494B";
}
throw std::runtime_error("unreachable; value=" +
std::to_string(static_cast<int>(color)));
}

switch (color) {
Expand All @@ -218,6 +229,8 @@ QColor Theme::diff(Diff color) {
case Diff::Error:
return "#FF0000";
}
throw std::runtime_error("unreachable; value=" +
std::to_string(static_cast<int>(color)));
}

QColor Theme::heatMap(HeatMap color) {
Expand All @@ -228,6 +241,8 @@ QColor Theme::heatMap(HeatMap color) {
return mDark ? QPalette().color(QPalette::Inactive, QPalette::Highlight)
: QPalette().color(QPalette::Mid);
}
throw std::runtime_error("unreachable; value=" +
std::to_string(static_cast<int>(color)));
}

QColor Theme::remoteComment(Comment color) {
Expand All @@ -241,6 +256,8 @@ QColor Theme::remoteComment(Comment color) {
case Comment::Timestamp:
return QPalette().color(QPalette::WindowText);
}
throw std::runtime_error("unreachable; value=" +
std::to_string(static_cast<int>(color)));
}

QColor Theme::star() { return QPalette().color(QPalette::Highlight); }
Expand Down
53 changes: 28 additions & 25 deletions src/conf/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "Settings.h"
#include "ConfFile.h"
#include "Debug.h"
#include "qtsupport.h"
#include <QCoreApplication>
#include <QDir>
#include <QSettings>
Expand All @@ -23,18 +24,18 @@

namespace {

const QString kIgnoreWsKey = "diff/whitespace/ignore";
const QString kLastPathKey = "lastpath";
const QString kIgnoreWsKey("diff/whitespace/ignore");
const QString kLastPathKey("lastpath");

// Look up variant at key relative to root.
QVariant lookup(const QVariantMap &root, const QString &key) {
QStringList list = key.split("/", QString::SkipEmptyParts);
QStringList list(key.split("/", Qt::SkipEmptyParts));
if (list.isEmpty())
return root;

QVariantMap map = root;
QVariantMap map(root);
while (map.contains(list.first())) {
QVariant result = map.value(list.takeFirst());
QVariant result(map.value(list.takeFirst()));
if (list.isEmpty())
return result;
map = result.toMap();
Expand Down Expand Up @@ -63,7 +64,7 @@ QVariant Settings::value(const QString &key,
const QVariant &defaultValue) const {
QSettings settings;
settings.beginGroup(group());
QVariant result = settings.value(key, defaultValue);
QVariant result(settings.value(key, defaultValue));
settings.endGroup();
return result;
}
Expand Down Expand Up @@ -107,13 +108,13 @@ QString Settings::lexer(const QString &filename) {
return "null";

QFileInfo info(filename);
QString name = info.fileName();
QString suffix = info.suffix().toLower();
QString name(info.fileName());
QString suffix(info.suffix().toLower());

// Try all patterns first.
QVariantMap lexers = mDefaults.value("lexers").toMap();
QVariantMap lexers(mDefaults.value("lexers").toMap());
foreach (const QString &key, lexers.keys()) {
QVariantMap map = lexers.value(key).toMap();
QVariantMap map(lexers.value(key).toMap());
if (map.contains("patterns")) {
foreach (QString pattern, map.value("patterns").toString().split(",")) {
QRegExp regExp(pattern, CS, QRegExp::Wildcard);
Expand All @@ -125,7 +126,7 @@ QString Settings::lexer(const QString &filename) {

// Try to match by extension.
foreach (const QString &key, lexers.keys()) {
QVariantMap map = lexers.value(key).toMap();
QVariantMap map(lexers.value(key).toMap());
if (map.contains("extensions")) {
foreach (QString ext, map.value("extensions").toString().split(",")) {
if (suffix == ext)
Expand All @@ -138,8 +139,8 @@ QString Settings::lexer(const QString &filename) {
}

QString Settings::kind(const QString &filename) {
QString key = lexer(filename);
QVariantMap lexers = mDefaults.value("lexers").toMap();
QString key(lexer(filename));
QVariantMap lexers(mDefaults.value("lexers").toMap());
return lexers.value(key).toMap().value("name").toString();
}

Expand Down Expand Up @@ -171,6 +172,8 @@ QString Settings::promptDescription(Prompt::Kind kind) const {
case Prompt::Kind::LargeFiles:
return tr("Prompt to stage large files");
}
throw std::runtime_error("unreachable; value=" +
std::to_string(static_cast<int>(kind)));
}

void Settings::setHotkey(const QString &action, const QString &hotkey) {
Expand Down Expand Up @@ -221,31 +224,31 @@ QDir Settings::confDir() {
#if !defined(NDEBUG)
QDir dir(SRC_CONF_DIR);
#else
QDir dir = rootDir();
QDir dir(rootDir());
if (!dir.cd("Resources")) {
if (!dir.cd(CONF_DIR))
dir = SRC_CONF_DIR;
dir.setPath(SRC_CONF_DIR);
}
#endif
return dir;
}

QDir Settings::l10nDir() {
#if !defined(NDEBUG)
QDir dir = QDir(SRC_L10N_DIR);
QDir dir(QDir(SRC_L10N_DIR));
#else
QDir dir = confDir();
QDir dir(confDir());
if (!dir.cd("l10n")) {
dir = rootDir();
if (!dir.cd(L10N_DIR))
dir = SRC_L10N_DIR;
dir.setPath(SRC_L10N_DIR);
}
#endif
return dir;
}

QDir Settings::dictionariesDir() {
QDir dir = confDir();
QDir dir(confDir());
dir.cd("dictionaries");
return dir;
}
Expand All @@ -254,24 +257,24 @@ QDir Settings::lexerDir() {
#if !defined(NDEBUG)
QDir dir(SRC_SCINTILLUA_LEXERS_DIR);
#else
QDir dir = confDir();
QDir dir(confDir());
if (!dir.cd("lexers")) {
dir = rootDir();
if (!dir.cd(SCINTILLUA_LEXERS_DIR))
dir = SRC_SCINTILLUA_LEXERS_DIR;
dir.setPath(SRC_SCINTILLUA_LEXERS_DIR);
}
#endif
return dir;
}

QDir Settings::themesDir() {
QDir dir = confDir();
QDir dir(confDir());
dir.cd("themes");
return dir;
}

QDir Settings::pluginsDir() {
QDir dir = confDir();
QDir dir(confDir());
dir.cd("plugins");
return dir;
}
Expand All @@ -281,8 +284,8 @@ QDir Settings::userDir() {
}

QDir Settings::tempDir() {
QString name = QCoreApplication::applicationName();
QDir dir = QDir::temp();
QString name(QCoreApplication::applicationName());
QDir dir(QDir::temp());
dir.mkpath(name);
dir.cd(name);
return dir;
Expand Down
3 changes: 2 additions & 1 deletion src/cred/CredentialHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "CredentialHelper.h"
#include "Cache.h"
#include "GitCredential.h"
#include "qtsupport.h"
#include "Store.h"
#include "conf/Settings.h"
#include "git/Config.h"
Expand Down Expand Up @@ -98,5 +99,5 @@ void CredentialHelper::log(const QString &text) {
return;

QString time = QTime::currentTime().toString(Qt::ISODateWithMs);
QTextStream(&file) << time << " - " << text << endl;
QTextStream(&file) << time << " - " << text << Qt::endl;
}
Loading

0 comments on commit 820c0fd

Please sign in to comment.