From 86bebd948c140b513836b630490645c3d2658d2b Mon Sep 17 00:00:00 2001 From: Artem Sheptunov <106321977+Infindery@users.noreply.github.com> Date: Fri, 26 Sep 2025 15:24:27 +0500 Subject: [PATCH 1/7] refactor(lint): #34: move C/C++ extension configuration, add new parameters --- .devcontainer/devcontainer.json | 7 +------ .vscode/c_cpp_properties.json | 16 ++++++++++++++++ .vscode/settings.json | 13 +++++++++++++ 3 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/settings.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 4796385..fd58d96 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -20,12 +20,7 @@ "extensions": [ "ms-vscode.cmake-tools", "ms-vscode.cpptools" - ], - "settings": { - "C_Cpp.formatting": "clangFormat", - "C_Cpp.codeAnalysis.clangTidy.enabled": true, - "editor.formatOnSave": true - } + ] } }, "features": { diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..6de4d25 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,16 @@ +{ + "configurations": [ + { + "name": "DevContainer", + "includePath": [ + "${workspaceFolder}/**", + "/root/.conan2/**" + ], + "defines": [], + "compilerPath": "/usr/bin/clang", + "intelliSenseMode": "linux-clang-x64", + "cppStandard": "c++20" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..60dbb41 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,13 @@ +{ + "editor.formatOnSave": true, + "C_Cpp.formatting": "clangFormat", + "C_Cpp.codeAnalysis.clangTidy.enabled": true, + "C_Cpp.codeAnalysis.exclude": { + "build/**": true, + "**/odb-gen/*.cxx": true, + "**/odb-gen/*.hxx": true, + "**/odb-gen/*.ixx": true, + "**/.conan2/**": true, + }, + "C_Cpp.autoAddFileAssociations": false +} \ No newline at end of file From 3abac6b2cac36e66b52d09870203513118027c9f Mon Sep 17 00:00:00 2001 From: Artem Sheptunov <106321977+Infindery@users.noreply.github.com> Date: Fri, 26 Sep 2025 15:24:57 +0500 Subject: [PATCH 2/7] refactor(lint): #34: C++ standard version update --- .clang-format | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.clang-format b/.clang-format index 6f64d25..9ae1d4e 100644 --- a/.clang-format +++ b/.clang-format @@ -76,6 +76,6 @@ SpacesInCStyleCastParentheses: false SpacesInContainerLiterals: false SpacesInParentheses: false SpacesInSquareBrackets: false -Standard: c++17 +Standard: c++20 TabWidth: 4 UseTab: Never From 2c105753f39f3ec3a035fd2491d028f70f9d72de Mon Sep 17 00:00:00 2001 From: Artem Sheptunov <106321977+Infindery@users.noreply.github.com> Date: Fri, 26 Sep 2025 15:25:51 +0500 Subject: [PATCH 3/7] refactor(lint): #34: remove the WarningsAsErrors property from the clang-tidy configuration --- .clang-tidy | 1 - 1 file changed, 1 deletion(-) diff --git a/.clang-tidy b/.clang-tidy index d6cf774..f9aeba8 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -34,5 +34,4 @@ Checks: >- -modernize-avoid-c-arrays, -bugprone-easily-swappable-parameters, -misc-const-correctness -WarningsAsErrors: '*' HeaderFilterRegex: '.*' From 603786cdf97363f819aa0e934e37f741212c581a Mon Sep 17 00:00:00 2001 From: Artem Sheptunov <106321977+Infindery@users.noreply.github.com> Date: Fri, 26 Sep 2025 15:26:45 +0500 Subject: [PATCH 4/7] feat(lint): #34: add a snippet to disable clang-tidy checking --- .vscode/cpp.code-snippets | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .vscode/cpp.code-snippets diff --git a/.vscode/cpp.code-snippets b/.vscode/cpp.code-snippets new file mode 100644 index 0000000..f0199d7 --- /dev/null +++ b/.vscode/cpp.code-snippets @@ -0,0 +1,9 @@ +{ + "NOLINTNEXTLINE": { + "prefix": "nolint", + "body": [ + "// NOLINTNEXTLINE" + ], + "description": "Add NOLINTNEXTLINE comment" + } +} \ No newline at end of file From f041302c9c9971f43fb1508629adbfbb93eeb071 Mon Sep 17 00:00:00 2001 From: Artem Sheptunov <106321977+Infindery@users.noreply.github.com> Date: Fri, 26 Sep 2025 15:27:14 +0500 Subject: [PATCH 5/7] refactor: #34: remove redundant code --- src/main.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 8bdedd1..be21213 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,12 +1,4 @@ -#include "data/commands/todo-commands.h" -#include "data/queries/todo-queries.h" -#include #include -#include -#include -#include -#include -#include int main() { From 71b154f509f3cc6b943eb8ac55dd2a3ddec5dd98 Mon Sep 17 00:00:00 2001 From: Artem Sheptunov <106321977+Infindery@users.noreply.github.com> Date: Mon, 29 Sep 2025 14:10:35 +0500 Subject: [PATCH 6/7] refactor: #34: formatter fixes --- src/data/commands/todo-commands.cpp | 2 +- src/data/models/to-do.h | 15 +++++++++------ src/data/queries/todo-queries.cpp | 2 +- src/data/queries/todo-queries.h | 5 +++-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/data/commands/todo-commands.cpp b/src/data/commands/todo-commands.cpp index c6a3e21..edf2423 100644 --- a/src/data/commands/todo-commands.cpp +++ b/src/data/commands/todo-commands.cpp @@ -1,7 +1,7 @@ #include "todo-commands.h" #include "data/models/odb-gen/to-do-odb.hxx" -#include #include +#include uint64_t ToDoCommands::create_todo(const std::string& name, std::time_t createdAtUtc) { diff --git a/src/data/models/to-do.h b/src/data/models/to-do.h index ee5b535..2631294 100644 --- a/src/data/models/to-do.h +++ b/src/data/models/to-do.h @@ -1,9 +1,9 @@ #pragma once -#include #include #include #include +#include #pragma db object table("todo") class ToDo @@ -11,7 +11,10 @@ class ToDo public: ToDo() = default; ToDo(const std::string& name, std::time_t createdAtUtc) - : name_(name), createdAtUtc_(createdAtUtc), deletedAtUtc_() {} + : name_(name), + createdAtUtc_(createdAtUtc), + deletedAtUtc_() + {} std::uint64_t id() const { return id_; } const std::string& name() const { return name_; } @@ -25,14 +28,14 @@ class ToDo private: friend class odb::access; - #pragma db id auto +#pragma db id auto std::uint64_t id_; std::string name_; - #pragma db type("BIGINT") +#pragma db type("BIGINT") std::time_t createdAtUtc_; - #pragma db null - #pragma db type("BIGINT") +#pragma db null +#pragma db type("BIGINT") odb::nullable deletedAtUtc_; }; \ No newline at end of file diff --git a/src/data/queries/todo-queries.cpp b/src/data/queries/todo-queries.cpp index 5ed6df7..aecb7ed 100644 --- a/src/data/queries/todo-queries.cpp +++ b/src/data/queries/todo-queries.cpp @@ -1,7 +1,7 @@ #include "todo-queries.h" #include "data/models/odb-gen/to-do-odb.hxx" -#include #include +#include std::shared_ptr> ToDoQueries::get_all_todos() { diff --git a/src/data/queries/todo-queries.h b/src/data/queries/todo-queries.h index 4920224..504e571 100644 --- a/src/data/queries/todo-queries.h +++ b/src/data/queries/todo-queries.h @@ -8,8 +8,9 @@ class ToDoQueries { public: - ToDoQueries -(odb::database& db) : db_(db) {} + ToDoQueries(odb::database& db) + : db_(db) + {} std::shared_ptr> get_all_todos(); std::shared_ptr get_todo_by_id(int id); From 6fc673ec1093a095886ce823bdd740ade12bcf3a Mon Sep 17 00:00:00 2001 From: Artem Sheptunov <106321977+Infindery@users.noreply.github.com> Date: Mon, 29 Sep 2025 15:25:44 +0500 Subject: [PATCH 7/7] docs(lint): #34: update instructions for working with linters --- README.md | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 5a4f0e4..09b1886 100644 --- a/README.md +++ b/README.md @@ -38,12 +38,27 @@ When the project configuration is finished, click Build to build the project. To launch the executable, click Launch in the CMake extension.

cmakeLaunch

-## How to run clang-tidy static code analyzer +## Linters -To run clang-tidy, run the following command: -``` -find ./src -name "*.cpp" -not -path "*/build/*" -exec echo "Checking {}..." \; -exec clang-tidy --config-file=.clang-tidy {} -- -I./include -std=c++20 \; -``` +The project includes the `clang-tidy` code analyzer and the `clang-format` formatter. Configuration files are located in the project root: `.clang-tidy` and `.clang-format`, respectively. + +To use linters you need to install: +- [VSCode](https://code.visualstudio.com/) +- [C/C++ VSCode Extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) + +### Clang-format + +Clang-format code formatting occurs automatically when saving a file using the CodeAnalysis C/C++ extension. + +To start manually, you need to run the command `find ./src -name "*.cpp" -o -name "*.h" | xargs clang-format --dry-run`, while in the root of the project. + +To automatically fix errors, run `find ./src -name "*.cpp" -o -name "*.h" | xargs clang-format -i` from the project root. + +### Clang-tidy + +Clang-tidy code checking occurs in the background using the CodeAnalysis C/C++ extension. + +To start manually, you need to run the command `find ./src -name "*.cpp" -o -name "*.h" | xargs clang-tidy -p ./build/Debug | grep "error:"`, while in the root of the project. ## Tests run