Skip to content

Commit fb3231a

Browse files
authored
perf: #34: improved linter performance
perf: #34: improved linter performance
2 parents ee165c9 + 6fc673e commit fb3231a

12 files changed

Lines changed: 74 additions & 31 deletions

File tree

.clang-format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,6 @@ SpacesInCStyleCastParentheses: false
7676
SpacesInContainerLiterals: false
7777
SpacesInParentheses: false
7878
SpacesInSquareBrackets: false
79-
Standard: c++17
79+
Standard: c++20
8080
TabWidth: 4
8181
UseTab: Never

.clang-tidy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,4 @@ Checks: >-
3434
-modernize-avoid-c-arrays,
3535
-bugprone-easily-swappable-parameters,
3636
-misc-const-correctness
37-
WarningsAsErrors: '*'
3837
HeaderFilterRegex: '.*'

.devcontainer/devcontainer.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@
2020
"extensions": [
2121
"ms-vscode.cmake-tools",
2222
"ms-vscode.cpptools"
23-
],
24-
"settings": {
25-
"C_Cpp.formatting": "clangFormat",
26-
"C_Cpp.codeAnalysis.clangTidy.enabled": true,
27-
"editor.formatOnSave": true
28-
}
23+
]
2924
}
3025
},
3126
"features": {

.vscode/c_cpp_properties.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "DevContainer",
5+
"includePath": [
6+
"${workspaceFolder}/**",
7+
"/root/.conan2/**"
8+
],
9+
"defines": [],
10+
"compilerPath": "/usr/bin/clang",
11+
"intelliSenseMode": "linux-clang-x64",
12+
"cppStandard": "c++20"
13+
}
14+
],
15+
"version": 4
16+
}

.vscode/cpp.code-snippets

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"NOLINTNEXTLINE": {
3+
"prefix": "nolint",
4+
"body": [
5+
"// NOLINTNEXTLINE"
6+
],
7+
"description": "Add NOLINTNEXTLINE comment"
8+
}
9+
}

.vscode/settings.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"C_Cpp.formatting": "clangFormat",
4+
"C_Cpp.codeAnalysis.clangTidy.enabled": true,
5+
"C_Cpp.codeAnalysis.exclude": {
6+
"build/**": true,
7+
"**/odb-gen/*.cxx": true,
8+
"**/odb-gen/*.hxx": true,
9+
"**/odb-gen/*.ixx": true,
10+
"**/.conan2/**": true,
11+
},
12+
"C_Cpp.autoAddFileAssociations": false
13+
}

README.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,27 @@ When the project configuration is finished, click Build to build the project.
3838
To launch the executable, click Launch in the CMake extension.
3939
<p style="text-align: center;"><img src="docs/images/cmakeLaunch.png" alt="cmakeLaunch" width="400"/></p>
4040

41-
## How to run clang-tidy static code analyzer
41+
## Linters
4242

43-
To run clang-tidy, run the following command:
44-
```
45-
find ./src -name "*.cpp" -not -path "*/build/*" -exec echo "Checking {}..." \; -exec clang-tidy --config-file=.clang-tidy {} -- -I./include -std=c++20 \;
46-
```
43+
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.
44+
45+
To use linters you need to install:
46+
- [VSCode](https://code.visualstudio.com/)
47+
- [C/C++ VSCode Extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools)
48+
49+
### Clang-format
50+
51+
Clang-format code formatting occurs automatically when saving a file using the CodeAnalysis C/C++ extension.
52+
53+
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.
54+
55+
To automatically fix errors, run `find ./src -name "*.cpp" -o -name "*.h" | xargs clang-format -i` from the project root.
56+
57+
### Clang-tidy
58+
59+
Clang-tidy code checking occurs in the background using the CodeAnalysis C/C++ extension.
60+
61+
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.
4762

4863
## Tests run
4964

src/data/commands/todo-commands.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "todo-commands.h"
22
#include "data/models/odb-gen/to-do-odb.hxx"
3-
#include <odb/transaction.hxx>
43
#include <memory>
4+
#include <odb/transaction.hxx>
55

66
uint64_t ToDoCommands::create_todo(const std::string& name, std::time_t createdAtUtc)
77
{

src/data/models/to-do.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
#pragma once
22

3-
#include <string>
43
#include <ctime>
54
#include <odb/core.hxx>
65
#include <odb/nullable.hxx>
6+
#include <string>
77

88
#pragma db object table("todo")
99
class ToDo
1010
{
1111
public:
1212
ToDo() = default;
1313
ToDo(const std::string& name, std::time_t createdAtUtc)
14-
: name_(name), createdAtUtc_(createdAtUtc), deletedAtUtc_() {}
14+
: name_(name),
15+
createdAtUtc_(createdAtUtc),
16+
deletedAtUtc_()
17+
{}
1518

1619
std::uint64_t id() const { return id_; }
1720
const std::string& name() const { return name_; }
@@ -25,14 +28,14 @@ class ToDo
2528
private:
2629
friend class odb::access;
2730

28-
#pragma db id auto
31+
#pragma db id auto
2932
std::uint64_t id_;
3033

3134
std::string name_;
32-
#pragma db type("BIGINT")
35+
#pragma db type("BIGINT")
3336
std::time_t createdAtUtc_;
3437

35-
#pragma db null
36-
#pragma db type("BIGINT")
38+
#pragma db null
39+
#pragma db type("BIGINT")
3740
odb::nullable<std::time_t> deletedAtUtc_;
3841
};

src/data/queries/todo-queries.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "todo-queries.h"
22
#include "data/models/odb-gen/to-do-odb.hxx"
3-
#include <odb/transaction.hxx>
43
#include <memory>
4+
#include <odb/transaction.hxx>
55

66
std::shared_ptr<std::vector<ToDo>> ToDoQueries::get_all_todos()
77
{

0 commit comments

Comments
 (0)