Skip to content
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 .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: c++17
Standard: c++20
TabWidth: 4
UseTab: Never
1 change: 0 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ Checks: >-
-modernize-avoid-c-arrays,
-bugprone-easily-swappable-parameters,
-misc-const-correctness
WarningsAsErrors: '*'
HeaderFilterRegex: '.*'
7 changes: 1 addition & 6 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
16 changes: 16 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -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
}
9 changes: 9 additions & 0 deletions .vscode/cpp.code-snippets
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"NOLINTNEXTLINE": {
"prefix": "nolint",
"body": [
"// NOLINTNEXTLINE"
],
"description": "Add NOLINTNEXTLINE comment"
}
}
13 changes: 13 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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
}
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
<p style="text-align: center;"><img src="docs/images/cmakeLaunch.png" alt="cmakeLaunch" width="400"/></p>

## 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

Expand Down
2 changes: 1 addition & 1 deletion src/data/commands/todo-commands.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "todo-commands.h"
#include "data/models/odb-gen/to-do-odb.hxx"
#include <odb/transaction.hxx>
#include <memory>
#include <odb/transaction.hxx>

uint64_t ToDoCommands::create_todo(const std::string& name, std::time_t createdAtUtc)
{
Expand Down
15 changes: 9 additions & 6 deletions src/data/models/to-do.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
#pragma once

#include <string>
#include <ctime>
#include <odb/core.hxx>
#include <odb/nullable.hxx>
#include <string>

#pragma db object table("todo")
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_; }
Expand All @@ -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<std::time_t> deletedAtUtc_;
};
2 changes: 1 addition & 1 deletion src/data/queries/todo-queries.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "todo-queries.h"
#include "data/models/odb-gen/to-do-odb.hxx"
#include <odb/transaction.hxx>
#include <memory>
#include <odb/transaction.hxx>

std::shared_ptr<std::vector<ToDo>> ToDoQueries::get_all_todos()
{
Expand Down
5 changes: 3 additions & 2 deletions src/data/queries/todo-queries.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
class ToDoQueries
{
public:
ToDoQueries
(odb::database& db) : db_(db) {}
ToDoQueries(odb::database& db)
: db_(db)
{}
std::shared_ptr<std::vector<ToDo>> get_all_todos();
std::shared_ptr<ToDo> get_todo_by_id(int id);

Expand Down
8 changes: 0 additions & 8 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
#include "data/commands/todo-commands.h"
#include "data/queries/todo-queries.h"
#include <ctime>
#include <drogon/HttpAppFramework.h>
#include <iomanip>
#include <iostream>
#include <odb/pgsql/database.hxx>
#include <string>
#include <vector>

int main()
{
Expand Down