Skip to content
Open
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
22 changes: 12 additions & 10 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
---
Language: Cpp
BasedOnStyle: Google
Language: Cpp
BasedOnStyle: Google
IndentWidth: 4
ColumnLimit: 100

#IncludeBlocks: Preserve # 保持头文件分组结构
SortIncludes: CaseInsensitive # 开启排序(但通过分组控制例外)
SortIncludes: CaseInsensitive # 开启排序(但通过分组控制例外)
AlignConsecutiveDeclarations: true # 开启对连续声明的对齐。
AlignConsecutiveAssignments: true
AlignTrailingComments: true

IncludeCategories:
# 1. 优先排序标准库头文件(尖括号)
- Regex: '^<[a-z_]+>'
Priority: 1
- Regex: "^<[a-z_]+>"
Priority: 1

# 2. 禁止排序第三方库(通过低优先级 + 不排序同一分组)
- Regex: '^<*.*>' # 匹配第三方路径
Priority: 2
- Regex: "^<*.*>" # 匹配第三方路径
Priority: 2

# 3. 其他头文件(如项目自有头文件)
- Regex: '^".*"'
Priority: 3
- Regex: '^".*"'
Priority: 3
...
54 changes: 45 additions & 9 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Checks:
HeaderFilterRegex: 'src/.*'

Checks: >
-*,
bugprone-undelegated-constructor,
bugprone-argument-comment,
Expand Down Expand Up @@ -47,16 +49,24 @@ Checks:
bugprone-exception-escape,
bugprone-missing-return,

performance-avoid-endl,
performance-faster-string-find,
performance-for-range-copy,
performance-implicit-conversion-in-loop,
performance-inefficient-algorithm,
performance-inefficient-string-concatenation,
performance-inefficient-vector-operation,
performance-move-const-arg,
performance-move-constructor-init,
performance-no-automatic-move,
performance-no-int-to-ptr,
performance-noexcept-destructor,
performance-noexcept-move-constructor,
performance-noexcept-swap,
performance-trivially-destructible,
performance-type-promotion-in-math-fn,
performance-unnecessary-copy-initialization,
performance-move-const-arg,
performance-unnecessary-value-param,

modernize-avoid-bind,
modernize-loop-convert,
Expand All @@ -68,30 +78,47 @@ Checks:
modernize-replace-random-shuffle,
modernize-use-auto,
modernize-use-bool-literals,
modernize-use-nullptr,
modernize-use-using,
modernize-use-override,
modernize-use-constraints,
modernize-use-default-member-init,
modernize-use-designated-initializers,
modernize-use-emplace,
modernize-use-equals-default,
modernize-use-equals-delete,
modernize-use-integer-sign-comparison,
modernize-use-nodiscard,
modernize-use-noexcept,
modernize-use-nullptr,
modernize-use-override,
modernize-use-ranges,
modernize-use-scoped-lock,
modernize-use-starts-ends-with,
modernize-use-std-format,
modernize-use-std-numbers,
modernize-use-std-print,
modernize-use-transparent-functors,
modernize-use-uncaught-exceptions,
modernize-use-using,

misc-throw-by-value-catch-by-reference,
misc-definitions-in-headers,
misc-header-include-cycle,
misc-misplaced-const,
misc-unconventional-assign-operator,
misc-redundant-expression,
misc-static-assert,
misc-throw-by-value-catch-by-reference,
misc-unconventional-assign-operator,
misc-uniqueptr-reset-release,
misc-unused-alias-decls,
misc-unused-parameters,
misc-unused-using-decls,
misc-definitions-in-headers
misc-use-internal-linkage,

readability-avoid-const-params-in-decls
readability-const-return-type,
readability-container-size-empty,
readability-delete-null-pointer,
readability-deleted-default,
readability-misplaced-array-index,
readability-make-member-function-const,
readability-non-const-parameter,
readability-redundant-control-flow,
readability-redundant-function-ptr-dereference,
Expand All @@ -111,11 +138,20 @@ Checks:
cert-mem57-cpp,
cert-oop58-cpp,
cert-err34-c,

google-build-explicit-make-pair,
google-runtime-operator,

hicpp-exception-baseclass,
hicpp-uppercase-literal-suffix,

cppcoreguidelines-misleading-capture-default-by-value,
cppcoreguidelines-missing-std-forward,
cppcoreguidelines-no-suspend-with-lock,
cppcoreguidelines-pro-type-member-init,
cppcoreguidelines-rvalue-reference-param-not-moved,
cppcoreguidelines-virtual-class-destructor,

security-api-misuse,

FormatStyle: 'file'
FormatStyle: "file"
22 changes: 17 additions & 5 deletions .clangd
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
Index:
Background: Build

CompileFlags:
Add: [-xc++, -Wall, -std=c++20]
Index:
Background: Build

CompileFlags:
Add: [-xc++, -Wall, -std=c++20]

Diagnostics:
UnusedIncludes: Strict
MissingIncludes: Strict
ClangTidy:
Add: []
Remove: []

Includes:
IgnoreHeader:
- "wx/.*"
- "opencv2/.*"
70 changes: 51 additions & 19 deletions .github/workflows/cpp-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,75 @@ name: cpp-linter
on:
pull_request:
branches: [main]
paths: ['**.c', '**.cpp', '**.h', '**.hpp', '**.cxx', '**.hxx', '**.cc', '**.hh', '**CMakeLists.txt', 'meson.build', '**.cmake']
paths:
[
"**.c",
"**.cpp",
"**.h",
"**.hpp",
"**.cxx",
"**.hxx",
"**.cc",
"**.hh",
"**CMakeLists.txt",
"meson.build",
"**.cmake",
]
push:
branches: [main]
paths: ['**.c', '**.cpp', '**.h', '**.hpp', '**.cxx', '**.hxx', '**.cc', '**.hh', '**CMakeLists.txt', 'meson.build', '**.cmake']
paths:
[
"**.c",
"**.cpp",
"**.h",
"**.hpp",
"**.cxx",
"**.hxx",
"**.cc",
"**.hh",
"**CMakeLists.txt",
"meson.build",
"**.cmake",
]

jobs:
cpp-linter:
runs-on: ubuntu-latest
runs-on: windows-latest
steps:
- uses: actions/checkout@v5

- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
libwxgtk3.2-dev \
libopencv-dev \
libeigen3-dev \
libomp-dev \
build-essential

- name: Setup MSYS2
uses: msys2/setup-msys2@v2
with:
msystem: CLANG64
update: true
install: >-
mingw-w64-clang-x86_64-cmake
mingw-w64-clang-x86_64-toolchain
mingw-w64-clang-x86_64-cereal
mingw-w64-clang-x86_64-wxwidgets3.3-common
mingw-w64-clang-x86_64-wxwidgets3.3-common-libs
mingw-w64-clang-x86_64-wxwidgets3.3-msw
mingw-w64-clang-x86_64-wxwidgets3.3-msw-libs
mingw-w64-clang-x86_64-opencv
mingw-w64-clang-x86_64-eigen3

- name: Generate Compilation Database
shell: msys2 {0}
run: |
cmake -S . -B build \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCMAKE_BUILD_TYPE=Debug

-DCMAKE_EXPORT_COMPILE_COMMANDS=ON

- uses: cpp-linter/cpp-linter-action@v2
id: linter
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
style: 'file' # Use .clang-format config file
tidy-checks: '' # Use .clang-tidy config file
style: "file" # Use .clang-format config file
tidy-checks: "" # Use .clang-tidy config file
# only 'update' a single comment in a pull request thread.
thread-comments: ${{ github.event_name == 'pull_request' && 'update' }}
database: 'build'
database: "build"

- name: Fail fast?!
if: steps.linter.outputs.checks-failed > 0
Expand Down
9 changes: 9 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Launch",
"program": "${workspaceFolder}/build/Croplines.exe",
"args": [],
"cwd": "${workspaceFolder}/build",
"preLaunchTask": "CMake: 生成",
},
{
"name": "(gdb) 启动",
"type": "cppdbg",
Expand Down
10 changes: 10 additions & 0 deletions .zed/debug.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"label": "Debug",
"cwd": "./build",
"program": "Croplines.exe",
"request": "launch",
"adapter": "GDB",
"build": "CMake build debug"
}
]
26 changes: 8 additions & 18 deletions .zed/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,14 @@
"clangd": {
"binary": {
"arguments": [
"--query-driver=D:\\MSYS2\\ucrt64\\bin\\g*",
"--all-scopes-completion", // 全局补全(补全建议会给出在当前作用域不可见的索引,插入后自动补充作用域标识符),例如在main()中直接写cout,即使没有`#include <iostream>`,也会给出`std::cout`的建议,配合"--header-insertion=iwyu",还可自动插入缺失的头文件
"--background-index", // 后台分析并保存索引文件
"--clang-tidy", // 启用 Clang-Tidy 以提供「静态检查」,下面设置 clang tidy 规则
"--clang-tidy-checks=performance-*, bugprone-*, misc-*, google-*, modernize-*, readability-*, portability-*",
"--compile-commands-dir=./build/", // 编译数据库(例如 compile_commands.json 文件)的目录位置
"--completion-parse=auto", // 当 clangd 准备就绪时,用它来分析建议
"--completion-style=detailed", // 建议风格:打包(重载函数只会给出一个建议);还可以设置为 detailed
"--enable-config", // 启用配置文件(YAML格式)项目配置文件是在项目文件夹里的“.clangd”,用户配置文件是“clangd/config.yaml”,该文件来自:Windows: %USERPROFILE%\AppData\Local || MacOS: ~/Library/Preferences/ || Others: $XDG_CONFIG_HOME, usually ~/.config
"--function-arg-placeholders=true", // 补全函数时,将会给参数提供占位符,键入后按 Tab 可以切换到下一占位符,乃至函数末
"--header-insertion-decorators", // 输入建议中,已包含头文件的项与还未包含头文件的项会以圆点加以区分
"--header-insertion=iwyu", // 插入建议时自动引入头文件 iwyu
"--include-cleaner-stdlib", // 为标准库头文件启用清理功能(不成熟!!!)
"--log=verbose", // 让 Clangd 生成更详细的日志
"--pch-storage=memory", // pch 优化的位置(Memory 或 Disk,前者会增加内存开销,但会提升性能)
"--pretty", // 输出的 JSON 文件更美观
"--ranking-model=decision_forest", // 建议的排序方案:hueristics (启发式), decision_forest (决策树)
"-j=12" // 同时开启的任务数量
"--query-driver=D:/MSYS2/ucrt64/bin/g++.exe",
"--background-index",
"--all-scopes-completion",
"--completion-style=detailed",
"--clang-tidy",
"--pch-storage=memory",
"--compile-commands-dir=./build/",
"-j=12"
]
}
}
Expand Down
20 changes: 20 additions & 0 deletions .zed/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"label": "CMake build debug",
"command": "cmake --build build --config Debug --target all -j 20 --",
"use_new_terminal": false,
"allow_concurrent_runs": false,
"reveal": "always",
"hide": "never",
"shell": "system",
},
{
"label": "CMake build release",
"command": "cmake --build build -j 20 --config Release",
"use_new_terminal": false,
"allow_concurrent_runs": false,
"reveal": "always",
"hide": "never",
"shell": "system",
},
]
Loading
Loading