Skip to content

Fix clang tidy errors #201

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

Merged
merged 11 commits into from
Oct 31, 2024
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
tidy-checks: ''
step-summary: true
file-annotations: true
ignore: subprojects|build|android|assets|recordings|docs|toolchains|platforms|wrapper|src/libs/core/hash-library|src/lobby/curl_client.*
ignore: subprojects|build|android|assets|recordings|docs|toolchains|platforms|wrapper|src/libs/core/hash-library|tests|src/lobby/curl_client.*

- name: Fail CI run if linter checks failed
if: steps.linter.outputs.checks-failed != 0
Expand Down
2 changes: 1 addition & 1 deletion src/discord/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] const discord::Activity& get_raw() const;
};

struct DiscordInstance {

Check warning on line 108 in src/discord/core.hpp

View workflow job for this annotation

GitHub Actions / C++ lints(clang-format + clang-tidy)

src/discord/core.hpp:108:8 [cppcoreguidelines-special-member-functions]

class 'DiscordInstance' defines a destructor, a move constructor and a move assignment operator but does not define a copy constructor or a copy assignment operator
private:
std::unique_ptr<discord::Core> m_core;
std::unique_ptr<discord::User> m_current_user;

DiscordInstance(discord::Core* core);
explicit DiscordInstance(discord::Core* core);

public:
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] static helper::expected<DiscordInstance, std::string> initialize();
Expand Down
9 changes: 5 additions & 4 deletions src/executables/game/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void Application::update() {
if (scene_change) {

std::visit(
helper::overloaded{
helper::Overloaded{
[this, index](const scenes::Scene::Pop&) {
m_scene_stack.erase(
m_scene_stack.begin()
Expand All @@ -201,10 +201,11 @@ void Application::update() {
},
[this](const scenes::Scene::Switch& scene_switch) {
spdlog::info(
"switching to scene {}", magic_enum::enum_name(scene_switch.target_scene)
"switching to scene {}", magic_enum::enum_name(scene_switch.m_target_scene)
);
auto scene = scenes::create_scene(
*this, scene_switch.m_target_scene, scene_switch.m_layout
);
auto scene =
scenes::create_scene(*this, scene_switch.target_scene, scene_switch.layout);

// only clear, after the construction was successful
m_scene_stack.clear();
Expand Down
3 changes: 2 additions & 1 deletion src/executables/game/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <memory>
#include <vector>

struct Application final : public EventListener, public ServiceProvider {

Check warning on line 21 in src/executables/game/application.hpp

View workflow job for this annotation

GitHub Actions / C++ lints(clang-format + clang-tidy)

src/executables/game/application.hpp:21:8 [cppcoreguidelines-special-member-functions]

class 'Application' defines a copy constructor and a copy assignment operator but does not define a destructor, a move constructor or a move assignment operator
private:
static constexpr auto num_audio_channels = u8{ 2 };

Expand All @@ -45,7 +45,8 @@
#endif

protected:
EventDispatcher m_event_dispatcher;
EventDispatcher
m_event_dispatcher; //NOLINT(misc-non-private-member-variables-in-classes,cppcoreguidelines-non-private-member-variables-in-classes)

private:
std::vector<std::unique_ptr<scenes::Scene>> m_scene_stack;
Expand Down
57 changes: 29 additions & 28 deletions src/executables/utility/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,51 @@
#include <filesystem>
#include <iostream>

void print_info(const recorder::RecordingReader& recording_reader) noexcept {
//TODO(Totto): Implement, print basic information and final result for each simulation
UNUSED(recording_reader);
std::cerr << "NOT IMPLEMENTED\n";
}
namespace {
void print_info(const recorder::RecordingReader& recording_reader) noexcept {
//TODO(Totto): Implement, print basic information and final result for each simulation
UNUSED(recording_reader);
std::cerr << "NOT IMPLEMENTED\n";
}

void dump_json(const recorder::RecordingReader& recording_reader, bool pretty_print, bool ensure_ascii) noexcept {
void dump_json(const recorder::RecordingReader& recording_reader, bool pretty_print, bool ensure_ascii) noexcept {

auto result = json::try_convert_to_json<recorder::RecordingReader>(recording_reader);
auto result = json::try_convert_to_json<recorder::RecordingReader>(recording_reader);

if (not result.has_value()) {
std::cerr << fmt::format("An error occurred during converting to json: {}\n", result.error());
std::exit(1);
}
if (not result.has_value()) {
std::cerr << fmt::format("An error occurred during converting to json: {}\n", result.error());
std::exit(1);
}


int indent = -1;
char indent_char = ' ';
int indent = -1;
char indent_char = ' ';

if (pretty_print) {
indent = 1;
indent_char = '\t';
}
if (pretty_print) {
indent = 1;
indent_char = '\t';
}

try {
try {

std::cout << result.value().dump(indent, indent_char, ensure_ascii);
std::cout << result.value().dump(indent, indent_char, ensure_ascii);

} catch (const std::exception& error) {
std::cerr << error.what();
std::exit(1);
}
} catch (const std::exception& error) {
std::cerr << error.what();
std::exit(1);
}

if (pretty_print) {
std::cout << "\n";
if (pretty_print) {
std::cout << "\n";
}
}
}

} // namespace

int main(int argc, char** argv) noexcept {

try {


auto arguments_result = CommandLineArguments::from_args(argc, argv);

if (not arguments_result.has_value()) {
Expand Down Expand Up @@ -80,7 +81,7 @@ int main(int argc, char** argv) noexcept {
const auto recording_reader = std::move(parsed.value());

std::visit(
helper::overloaded{ [&recording_reader](const Dump& dump) {
helper::Overloaded{ [&recording_reader](const Dump& dump) {
dump_json(recording_reader, dump.pretty_print, dump.ensure_ascii);
},
[&recording_reader](const Info& /* info */) { print_info(recording_reader); } },
Expand Down
4 changes: 3 additions & 1 deletion src/game/bag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
Bag::Bag(Random& random) : m_tetromino_sequence{} {
// initialize array with invalid tetromino type
for (helper::TetrominoType& type : m_tetromino_sequence) {
type = static_cast<helper::TetrominoType>(static_cast<int>(helper::TetrominoType::LastType) + 1);
type = static_cast<helper::TetrominoType>( //NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange)
static_cast<int>(helper::TetrominoType::LastType) + 1
);
}

// fill in the sequence with random order
Expand Down
8 changes: 4 additions & 4 deletions src/game/grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Grid::Grid(const ui::Layout& layout, bool is_top_level)
: ui::Widget{ layout, ui::WidgetType::Component, is_top_level } {

const u32 total_x_tiles = grid::preview_extends.x * 2 + 2 + grid::width_in_tiles;
const u32 total_x_tiles = (grid::preview_extends.x * 2) + 2 + grid::width_in_tiles;
constexpr u32 total_y_tiles = grid::height_in_tiles;

const u32 tile_size_x = layout.get_rect().width() / total_x_tiles;
Expand Down Expand Up @@ -86,7 +86,7 @@ void Grid::draw_background(const ServiceProvider& service_provider, GridRect gri

for (u32 column = 0; column <= grid_rect.width(); ++column) {
const auto start = top_left + shapes::UPoint{ column * m_tile_size, 0 };
const auto end = shapes::UPoint{ start.x, start.y + grid_rect.height() * m_tile_size };
const auto end = shapes::UPoint{ start.x, start.y + (grid_rect.height() * m_tile_size) };
service_provider.renderer().draw_line(start, end, grid_color);
service_provider.renderer().draw_line(start - shapes::UPoint{ 1, 0 }, end - shapes::UPoint{ 1, 0 }, grid_color);
}
Expand All @@ -100,8 +100,8 @@ void Grid::draw_background(const ServiceProvider& service_provider, GridRect gri

const auto outline_top_left = top_left - shapes::UPoint{ 2, 2 };
const auto outline_bottom_right = shapes::UPoint{
top_left.x + grid_rect.width() * m_tile_size + 1,
top_left.y + grid_rect.height() * m_tile_size + 1,
top_left.x + (grid_rect.width() * m_tile_size) + 1,
top_left.y + (grid_rect.height() * m_tile_size) + 1,
};

const auto outline_rect = shapes::URect{
Expand Down
2 changes: 1 addition & 1 deletion src/game/tetrion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Tetrion::Tetrion(
: ui::Widget{ layout , ui::WidgetType::Component ,is_top_level},
SimulatedTetrion{tetrion_index,random_seed,starting_level, service_provider,std::move(recording_writer)},
m_main_layout{
utils::size_t_identity<2>(),
utils::SizeIdentity<2>(),
0,
ui::Direction::Vertical,
{ 0.85 },
Expand Down
6 changes: 3 additions & 3 deletions src/graphics/rect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ namespace shapes {
constexpr AbstractRect(Point top_left, Point bottom_right) // NOLINT(bugprone-easily-swappable-parameters)
: top_left{ top_left },
bottom_right{ bottom_right } { }
constexpr AbstractRect(T x, T y, T width, T height)
: top_left{ x, y },
bottom_right{ x + width - 1, y + height - 1 } { }
constexpr AbstractRect(T x_pos, T y_pos, T width, T height)
: top_left{ x_pos, y_pos },
bottom_right{ x_pos + width - 1, y_pos + height - 1 } { }

[[nodiscard]] constexpr T width() const {
return static_cast<T>(bottom_right.x - top_left.x + 1);
Expand Down
41 changes: 21 additions & 20 deletions src/graphics/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,35 +91,36 @@ void Renderer::draw_self_computed_circle_impl(const shapes::IPoint& center, i32

const i32 radius = diameter / 2;

i32 x = radius - 1;
i32 y = 0;
i32 tx = 1;
i32 ty = 1;
i32 error = tx - diameter;
i32 x_pos = radius - 1;
i32 y_pos = 0;
i32 tx_pos = 1;
i32 ty_pos = 1;
i32 error = tx_pos - diameter;

while (x >= y) {
while (x_pos >= y_pos) {
// Each of the following renders an octant of the circle
SDL_RenderDrawPoint(
m_renderer, center_x + x, center_y - y // NOLINT(clang-analyzer-core.UndefinedBinaryOperatorResult)
m_renderer, center_x + x_pos, // NOLINT(clang-analyzer-core.UndefinedBinaryOperatorResult)
center_y - y_pos
);
SDL_RenderDrawPoint(m_renderer, center_x + x, center_y + y);
SDL_RenderDrawPoint(m_renderer, center_x - x, center_y - y);
SDL_RenderDrawPoint(m_renderer, center_x - x, center_y + y);
SDL_RenderDrawPoint(m_renderer, center_x + y, center_y - x);
SDL_RenderDrawPoint(m_renderer, center_x + y, center_y + x);
SDL_RenderDrawPoint(m_renderer, center_x - y, center_y - x);
SDL_RenderDrawPoint(m_renderer, center_x - y, center_y + x);
SDL_RenderDrawPoint(m_renderer, center_x + x_pos, center_y + y_pos);
SDL_RenderDrawPoint(m_renderer, center_x - x_pos, center_y - y_pos);
SDL_RenderDrawPoint(m_renderer, center_x - x_pos, center_y + y_pos);
SDL_RenderDrawPoint(m_renderer, center_x + y_pos, center_y - x_pos);
SDL_RenderDrawPoint(m_renderer, center_x + y_pos, center_y + x_pos);
SDL_RenderDrawPoint(m_renderer, center_x - y_pos, center_y - x_pos);
SDL_RenderDrawPoint(m_renderer, center_x - y_pos, center_y + x_pos);

if (error <= 0) {
++y;
error += ty;
ty += 2;
++y_pos;
error += ty_pos;
ty_pos += 2;
}

if (error > 0) {
--x;
tx += 2;
error += (tx - diameter);
--x_pos;
tx_pos += 2;
error += (tx_pos - diameter);
}
}
}
4 changes: 2 additions & 2 deletions src/graphics/renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <filesystem>
#include <string>

struct Renderer final {

Check warning on line 15 in src/graphics/renderer.hpp

View workflow job for this annotation

GitHub Actions / C++ lints(clang-format + clang-tidy)

src/graphics/renderer.hpp:15:8 [cppcoreguidelines-special-member-functions]

class 'Renderer' defines a destructor, a copy constructor and a copy assignment operator but does not define a move constructor or a move assignment operator
public:
enum class VSync : u8 {
Enabled,
Expand Down Expand Up @@ -73,9 +73,9 @@
}

template<typename S, typename T>
void draw_texture(const Texture& texture, const shapes::AbstractRect<S>& from, const shapes::AbstractRect<T>& to)
void draw_texture(const Texture& texture, const shapes::AbstractRect<S>& from, const shapes::AbstractRect<T>& dest)
const {
texture.render(m_renderer, from, to);
texture.render(m_renderer, from, dest);
}

OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] Texture load_image(const std::filesystem::path& image_path) const;
Expand Down
4 changes: 2 additions & 2 deletions src/graphics/texture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ struct Texture {
}

template<typename T>
void render(SDL_Renderer* renderer, const shapes::AbstractRect<T>& from, const shapes::URect& to) const {
void render(SDL_Renderer* renderer, const shapes::AbstractRect<T>& from, const shapes::URect& dest) const {
const SDL_Rect from_rect_sdl = from.to_sdl_rect();
const SDL_Rect to_rect_sdl = to.to_sdl_rect();
const SDL_Rect to_rect_sdl = dest.to_sdl_rect();
SDL_RenderCopy(renderer, m_raw_texture, &from_rect_sdl, &to_rect_sdl);
}

Expand Down
2 changes: 2 additions & 0 deletions src/helper/message_box.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

#pragma once

#include <core/helper/types.hpp>

#include <SDL.h>
#include <string>

#include <core/helper/types.hpp>

Check warning on line 10 in src/helper/message_box.hpp

View workflow job for this annotation

GitHub Actions / C++ lints(clang-format + clang-tidy)

src/helper/message_box.hpp:10:1 [readability-duplicate-include]

duplicate include

#include "./windows.hpp"

Expand Down
4 changes: 2 additions & 2 deletions src/helper/music_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
namespace utils {


template<usize data_size>
template<usize DataSize>
constexpr auto get_supported_music_extension(
const char( // NOLINT(modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays)
&name
)[data_size]
)[DataSize]
) {

#if not defined(AUDIO_PREFER_MP3) and not defined(AUDIO_PREFER_FLAC)
Expand Down
8 changes: 4 additions & 4 deletions src/helper/nfd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace {
auto* extensions = new nfdu8char_t[extension_list_size]; // NOLINT(cppcoreguidelines-owning-memory)
std::memcpy(extensions, extension_list.c_str(), extension_list_size * sizeof(nfdu8char_t));

filter_item.get()[i] = { name, extensions };
filter_item.get()[i] = { .name = name, .spec = extensions };
}
}

Expand All @@ -68,7 +68,7 @@ namespace {
} // namespace


helper::expected<std::filesystem::path, std::string> helper::openFileDialog(
helper::expected<std::filesystem::path, std::string> helper::open_file_dialog(
const std::vector<AllowedFile>& allowed_files,
std::optional<std::filesystem::path> default_path
) {
Expand Down Expand Up @@ -108,7 +108,7 @@ helper::expected<std::filesystem::path, std::string> helper::openFileDialog(
}


[[nodiscard]] helper::expected<std::vector<std::filesystem::path>, std::string> helper::openMultipleFilesDialog(
[[nodiscard]] helper::expected<std::vector<std::filesystem::path>, std::string> helper::open_multiple_files_dialog(
const std::vector<AllowedFile>& allowed_files,
std::optional<std::filesystem::path> default_path
) {
Expand Down Expand Up @@ -160,7 +160,7 @@ helper::expected<std::filesystem::path, std::string> helper::openFileDialog(
return helper::unexpected<std::string>{ "Error: " + std::string{ NFD::GetError() } };
}

[[nodiscard]] helper::expected<std::filesystem::path, std::string> helper::openFolderDialog(
[[nodiscard]] helper::expected<std::filesystem::path, std::string> helper::open_folder_dialog(
std::optional<std::filesystem::path> default_path
) {

Expand Down
6 changes: 3 additions & 3 deletions src/helper/nfd_include.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ namespace helper {


//NOTE: this API is blocking and can't be asynchronous, due to os (linux, windows, macos) restrictions, it HAS to be launched in the same thread NFD_Init() was launched /the main thread)
[[nodiscard]] helper::expected<std::filesystem::path, std::string> openFileDialog(
[[nodiscard]] helper::expected<std::filesystem::path, std::string> open_file_dialog(
const std::vector<AllowedFile>& allowed_files = {},
std::optional<std::filesystem::path> default_path = std::nullopt
);

[[nodiscard]] helper::expected<std::vector<std::filesystem::path>, std::string> openMultipleFilesDialog(
[[nodiscard]] helper::expected<std::vector<std::filesystem::path>, std::string> open_multiple_files_dialog(
const std::vector<AllowedFile>& allowed_files = {},
std::optional<std::filesystem::path> default_path = std::nullopt
);

[[nodiscard]] helper::expected<std::filesystem::path, std::string> openFolderDialog(
[[nodiscard]] helper::expected<std::filesystem::path, std::string> open_folder_dialog(
std::optional<std::filesystem::path> default_path = std::nullopt
);

Expand Down
3 changes: 2 additions & 1 deletion src/input/guid.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

#include <algorithm>
#include <core/helper/utils.hpp>

#include "guid.hpp"
Expand All @@ -7,7 +8,7 @@
#include <fmt/ranges.h>

sdl::GUID::GUID(const SDL_GUID& data) : m_guid{} {
std::copy(std::begin(data.data), std::end(data.data), std::begin(m_guid));
std::ranges::copy(data.data, std::begin(m_guid));
}

[[nodiscard]] helper::expected<sdl::GUID, std::string> sdl::GUID::from_string(const std::string& value) {
Expand Down
2 changes: 1 addition & 1 deletion src/input/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ namespace {


auto result = std::visit(
helper::overloaded{
helper::Overloaded{
[service_provider](const input::KeyboardSettings& keyboard_settings) mutable -> ReturnType {
auto* const event_dispatcher = &(service_provider->event_dispatcher());
return std::make_shared<input::KeyboardGameInput>(keyboard_settings, event_dispatcher);
Expand Down
Loading
Loading