Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add clang-tidy to lint files #112

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
Checks: '-*,bugprone-*,-bugprone-suspicious-include,-bugprone-narrowing-conversions,cppcoreguidelines-*,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-avoid-magic-numbers,-cppcoreguidelines-owning-memory,-cppcoreguidelines-macro-usage,-cppcoreguidelines-avoid-c-arrays,-cppcoreguidelines-pro-type-static-cast-downcast,-cppcoreguidelines-narrowing-conversions,-cppcoreguidelines-special-member-functions,-cppcoreguidelines-pro-type-union-access,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-avoid-non-const-global-variables,-cppcoreguidelines-pro-type-vararg,modernize-*,-modernize-use-trailing-return-type,-modernize-use-auto,-modernize-avoid-c-arrays,performance-*,-performance-no-automatic-move,readability-*,-readability-magic-numbers,-readability-braces-around-statements,-readability-implicit-bool-conversion,-readability-implicit-bool-conversion,-readability-redundant-access-specifiers,-readability-isolate-declaration,-readability-else-after-return,-readability-static-accessed-through-instance'
HeaderFilterRegex: '^src\/(?!forms)\/?.*$'
WarningsAsErrors: '*'
AnalyzeTemporaryDtors: false
FormatStyle: file
...
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ option(BUILD_DEB "Build deb format package" OFF)
LEMONLOG(BUILD_DEB)
option(BUILD_RPM "Build rpm format package" OFF)
LEMONLOG(BUILD_RPM)
option(USE_CLANG_TIDY "Use clang-tidy to lint the files" OFF)
LEMONLOG(USE_CLANG_TIDY)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTORCC ON)
Expand Down Expand Up @@ -89,6 +91,11 @@ if(UNIX AND NOT APPLE)
endif()
LEMONLOG(LSB_RELEASE_ID_SHORT)

if(USE_CLANG_TIDY)
set(CMAKE_CXX_CLANG_TIDY "clang-tidy")
message(STATUS "clang-tidy checks will be performed")
endif()

# ==================================================================================
# Lemon Build Info
# ==================================================================================
Expand Down
2 changes: 1 addition & 1 deletion makespec/BUILDVERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
118
120
8 changes: 4 additions & 4 deletions src/base/LemonBaseApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ using namespace Lemon;

auto LemonBaseApplication::Initialize() -> bool {
QString errorMessage;
bool canContinue;
bool canContinue = false;
const auto hasError = parseCommandLine(&canContinue, &errorMessage);
if (hasError) {
// LOG("Command line: " + A(errorMessage));
if (! canContinue) {
if (canContinue) {
LOG("Non-fatal error, LemonLime will continue starting up.");
} else {
LOG("Fatal Error, LemonLime cannot continue.");
return false;
} else {
LOG("Non-fatal error, LemonLime will continue starting up.");
}
}

Expand Down
1 change: 1 addition & 0 deletions src/base/LemonConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace Lemon::base::config {
QJsonArray _compilerList = json["compilerList"].toArray();
compilerList.clear();
compilerList.reserve(_compilerList.size());
// NOLINTNEXTLINE
for (int compilerIndex = 0; compilerIndex < _compilerList.size(); ++compilerIndex) {
QJsonObject compilerObject = _compilerList[compilerIndex].toObject();
Compiler *compiler = new Compiler;
Expand Down
7 changes: 4 additions & 3 deletions src/core/contestant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ void Contestant::readFromStream(QDataStream &in) {
Qt::TimeSpec(judgingTime_timespec));
int count = 0;
int _count = 0;
int __count = 0;
int ___count = 0; // NOLINT
// FIXME: using semantic variables
int tmp = 0;
in >> count;

Expand All @@ -252,9 +253,9 @@ void Contestant::readFromStream(QDataStream &in) {

for (int j = 0; j < _count; j++) {
result[i].append(QList<ResultState>());
in >> __count;
in >> ___count;

for (int k = 0; k < __count; k++) {
for (int k = 0; k < ___count; k++) {
in >> tmp;
result[i][j].append(ResultState(tmp));
}
Expand Down
23 changes: 12 additions & 11 deletions src/core/judgingthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <Psapi.h>
#endif

// NOLINTNEXTLINE
JudgingThread::JudgingThread(QObject *parent) : QThread(parent) {
moveToThread(this);
// checkRejudgeMode = false;
Expand Down Expand Up @@ -148,10 +149,10 @@ void JudgingThread::compareLineByLine(const QString &contestantOutput) {
if (chk1)
chk1 = false;

str1[len1++] = ch;
str1[len1++] = ch; // NOLINT
}

str1[len1++] = '\0';
str1[len1++] = '\0'; // NOLINT
chkEof1 = ch == EOF;
len2 = 0;

Expand Down Expand Up @@ -185,10 +186,10 @@ void JudgingThread::compareLineByLine(const QString &contestantOutput) {
if (chk2)
chk2 = false;

str2[len2++] = ch;
str2[len2++] = ch; // NOLINT
}

str2[len2++] = '\0';
str2[len2++] = '\0'; // NOLINT
chkEof2 = ch == EOF;

if (len1 != len2 || strcmp(str1, str2) != 0) {
Expand Down Expand Up @@ -395,28 +396,28 @@ void JudgingThread::compareIgnoreSpaces(const QString &contestantOutput) {

while (len1 < 20) {
if (ch1 != ' ' && ch1 != '\t' && ch1 != '\n' && ch1 != '\r' && ch1 != EOF) {
str1[len1++] = ch1;
str1[len1++] = ch1; // NOLINT
} else {
break;
}

ch1 = static_cast<char>(fgetc(contestantOutputFile));
}

str1[len1] = '\0';
str1[len1] = '\0'; // NOLINT
int len2 = 0;

while (len2 < 20) {
if (ch2 != ' ' && ch2 != '\t' && ch2 != '\n' && ch2 != '\r' && ch2 != EOF) {
str2[len2++] = ch2;
str2[len2++] = ch2; // NOLINT
} else {
break;
}

ch2 = static_cast<char>(fgetc(standardOutputFile));
}

str2[len2] = '\0';
str2[len2] = '\0'; // NOLINT

if (len1 != len2 || strcmp(str1, str2) != 0) {
if (len1 <= 0) {
Expand Down Expand Up @@ -511,7 +512,7 @@ void JudgingThread::compareRealNumbers(const QString &contestantOutput) {
int cnt1 = fscanf(contestantOutputFile, "%Lf", &a);
int cnt2 = fscanf(standardOutputFile, "%Lf", &b);

char temps = fgetc(standardOutputFile);
char temps = static_cast<char>(fgetc(standardOutputFile));

if (cnt1 == 0) {
score = 0;
Expand Down Expand Up @@ -557,8 +558,8 @@ void JudgingThread::compareRealNumbers(const QString &contestantOutput) {
score = 0;
result = WrongAnswer;
message = tr(R"(On line %3, Read "%1" but expect "%2")")
.arg(a, 0, 'g', 18)
.arg(b, 0, 'g', 18)
.arg(a, 0, 'g', 18) // NOLINT
.arg(b, 0, 'g', 18) // NOLINT
.arg(nowRow);
fclose(contestantOutputFile);
fclose(standardOutputFile);
Expand Down
2 changes: 1 addition & 1 deletion src/core/testcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void TestCase::readFromStream(QDataStream &in) {
if (i.endsWith("_lemon_SUbtaskDEPENDENCE_fLAg")) {
int temp(0);

for (auto *itr = i.constBegin(); *itr != '_'; ++itr)
for (const auto *itr = i.constBegin(); *itr != '_'; ++itr)
(temp *= 10) += itr->toLatin1() ^ '0';

dependenceSubtask.push_back(temp);
Expand Down
2 changes: 1 addition & 1 deletion src/exttestcasetable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ void ExtTestCaseTable::whenItemSelectionChanged() {
if (haveSub.size() >= 2 && resSub.empty())
isCanMerge = true;

if (haveSub.size() >= 1 && resSub.empty())
if (haveSub.size() >= 1 && resSub.empty()) // NOLINT
isCanSplit = true;

emit testCaseSelectionChanged();
Expand Down
2 changes: 1 addition & 1 deletion src/exttestcaseupdaterdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
ExtTestCaseUpdaterDialog::ExtTestCaseUpdaterDialog(QWidget *parent, Task *nowTask,
const Settings *nowSettings, int nowCaseNumber,
int editScore, int editData, int editTime, int editMemory,
int editDepend, QList<int> tempDepends)
int editDepend, const QList<int> &tempDepends)
: QDialog(parent), ui(new Ui::ExtTestCaseUpdaterDialog), nowTask(nowTask), nowSettings(nowSettings),
nowCaseNumber(nowCaseNumber), editScore(editScore), editData(editData), editTime(editTime),
editMemory(editMemory), editDepend(editDepend) {
Expand Down
2 changes: 1 addition & 1 deletion src/exttestcaseupdaterdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ExtTestCaseUpdaterDialog : public QDialog {
const Settings *nowSettings = nullptr, int nowCaseNumber = 0,
int editScore = NO_EDIT, int editData = NO_EDIT, int editTime = NO_EDIT,
int editMemory = NO_EDIT, int editDepend = NO_EDIT,
QList<int> tempDepends = QList<int>());
const QList<int> &tempDepends = QList<int>());
~ExtTestCaseUpdaterDialog();

int getScore() const;
Expand Down
2 changes: 1 addition & 1 deletion src/summarytree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ SummaryTree::SummaryTree(QWidget *parent) : QTreeWidget(parent) {
addTestCaseKeyAction->setShortcutContext(Qt::WidgetShortcut);
deleteTaskKeyAction->setShortcutContext(Qt::WidgetShortcut);
deleteTestCaseKeyAction->setShortcutContext(Qt::WidgetShortcut);
addTaskKeyAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Insert));
addTaskKeyAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Insert)); // NOLINT: Qt issue
addTestCaseKeyAction->setShortcut(QKeySequence(Qt::Key_Insert));
deleteTaskKeyAction->setShortcut(QKeySequence(Qt::Key_Delete));
deleteTestCaseKeyAction->setShortcut(QKeySequence(Qt::Key_Delete));
Expand Down