-
Notifications
You must be signed in to change notification settings - Fork 0
Quality guard rails #1
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
Changes from all commits
8a0d38d
5d39a2c
9ab2b99
caf7e01
3f45451
887e50b
47447b7
07a6496
8cee9f7
e0af7f2
c2a525f
a9bcf8b
bfea8ce
3089d53
2774b16
a959915
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| --- | ||
| Checks: > | ||
| bugprone-*, | ||
| clang-analyzer-*, | ||
| -clang-analyzer-cplusplus.NewDelete, | ||
| -clang-analyzer-cplusplus.NewDeleteLeaks, | ||
| -bugprone-reserved-identifier, | ||
| -bugprone-easily-swappable-parameters, | ||
| -bugprone-narrowing-conversions | ||
|
|
||
| WarningsAsErrors: "*" | ||
| HeaderFilterRegex: "src/.*" | ||
| ExcludeHeaderFilterRegex: ".*(qcustomplot|ui_[a-z]+).h" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| # ModbusScope — Claude Code Guide | ||
|
|
||
| ## Build | ||
|
|
||
| ```bash | ||
| mkdir -p build && cd build | ||
| cmake -GNinja .. | ||
| ninja | ||
| ``` | ||
|
|
||
| Run tests: | ||
|
|
||
| ```bash | ||
| ctest --output-on-failure | ||
| ``` | ||
|
|
||
| Run pre-commit checks: | ||
|
|
||
| ```bash | ||
| ./scripts/pre-commit.sh | ||
| ``` | ||
|
|
||
| **Requirements:** Qt 6, C++20, Ninja. Compiler flags: `-Wall -Wextra -Werror`. | ||
|
|
||
| ## Project Structure | ||
|
|
||
| ``` | ||
| src/ | ||
| ├── communication/ Modbus protocol layer (ModbusPoll, ModbusMaster, ModbusConnection) | ||
| ├── models/ Data models (SettingsModel, GraphDataModel, DiagnosticModel, Device, Connection) | ||
| ├── datahandling/ Expression parsing, graph data processing | ||
| ├── importexport/ CSV export, MBS project files, MBC device config import | ||
| ├── dialogs/ UI dialogs and MainWindow | ||
| ├── customwidgets/ Qt custom widgets | ||
| ├── graphview/ Graph rendering (qcustomplot) | ||
| └── util/ Logging (ScopeLogging), formatting helpers | ||
| tests/ Google Test + Qt Test; test files named tst_*.cpp | ||
| libraries/ Vendored: qcustomplot, muparser | ||
| ``` | ||
|
|
||
| ## Architecture | ||
|
|
||
| - **SettingsModel** is the central config store — connections, devices, poll time | ||
| - **ModbusPoll** orchestrates polling: iterates connections, delegates to **ModbusMaster** per connection | ||
| - **ModbusMaster** manages one connection's read cycle via **ModbusConnection** (Qt Modbus) | ||
| - **GraphDataHandler** processes raw Modbus results and applies user expressions | ||
| - Models emit Qt signals; UI layers observe them — no direct model→UI calls | ||
|
|
||
| ## Code Style | ||
|
|
||
| Enforced by `.clang-format` (Mozilla-based, C++20): | ||
|
|
||
| - 4 spaces, no tabs; 120-char line limit | ||
| - Braces on new line for classes/functions | ||
| - Pointer left-aligned: `Type* ptr` | ||
| - Private members: `_camelCase`; pointer members: `_pName` | ||
| - Classes: `PascalCase`; methods: `camelCase` | ||
| - Use Qt doxygen style for comments | ||
|
|
||
| ## Key Conventions | ||
|
|
||
| - Prefer readability and maintainability over using the latest C++ features (avoid syntax sugar that may be less familiar to new contributors). | ||
| - Tests use `QCOMPARE` / `QTEST_GUILESS_MAIN` (Qt Test) | ||
| - Make sure to document public APIs with brief Doxygen comments | ||
| - Update json-rpc schema spec when updating json-rpc related code | ||
| - Only use early return for error handling, avoid deep nesting | ||
| - When fixing a bug, add a test that reproduces the issue before implementing the fix. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #!/bin/bash | ||
| set -euo pipefail | ||
|
|
||
| CHECK_MODE=false | ||
| if [ "${1:-}" = "--check" ]; then | ||
| CHECK_MODE=true | ||
| fi | ||
|
|
||
| CHANGED_FILES=$( | ||
| { git diff --name-only --diff-filter=d HEAD; git ls-files --others --exclude-standard; } \ | ||
| | grep -E '\.(cpp|h)$' \ | ||
| | sort -u \ | ||
| || true | ||
| ) | ||
|
|
||
| if [ -z "$CHANGED_FILES" ]; then | ||
| echo "No changed C++ files." | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "=== Files ===" | ||
| echo "$CHANGED_FILES" | ||
| echo "=== Running clang-format ===" | ||
|
|
||
| if [ "$CHECK_MODE" = true ]; then | ||
| echo "$CHANGED_FILES" | xargs clang-format --dry-run --Werror | ||
| else | ||
| echo "$CHANGED_FILES" | xargs clang-format -i | ||
| fi |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #!/bin/bash | ||
| set -euo pipefail | ||
|
|
||
| BUILD_DIR="${1:-build}" | ||
| QT_PREFIX="${2:-/opt/Qt/6.8.3/gcc_64}" | ||
|
|
||
| echo "=== Configuring (compile_commands.json) ===" | ||
| cmake -GNinja \ | ||
| -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ | ||
| -DCMAKE_PREFIX_PATH="${QT_PREFIX}" \ | ||
| -B "${BUILD_DIR}" | ||
|
|
||
| echo "=== Generating autogen headers ===" | ||
| ninja -C "${BUILD_DIR}" src/ScopeSource_autogen | ||
|
|
||
| echo "=== Running clang-tidy ===" | ||
| run-clang-tidy -quiet -p "${BUILD_DIR}" -j "$(nproc)" "$(pwd)/src/.*\.cpp\$" 2>/dev/null |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| #!/bin/bash | ||
| set -euo pipefail | ||
|
|
||
| BUILD_DIR="${1:-build}" | ||
| QT_PREFIX="${2:-/opt/Qt/6.8.3/gcc_64}" | ||
|
|
||
| echo "=== Configuring (compile_commands.json) ===" | ||
| cmake -GNinja \ | ||
| -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ | ||
| -DCMAKE_PREFIX_PATH="${QT_PREFIX}" \ | ||
| -B "${BUILD_DIR}" | ||
|
Comment on lines
+8
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Anchor all paths to the repository root instead of the caller’s working directory. Line 8 configures CMake without an explicit source dir, and Line 17 scans 🔧 Proposed fix #!/bin/bash
set -euo pipefail
-BUILD_DIR="${1:-build}"
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
+
+BUILD_DIR="${1:-build}"
QT_PREFIX="${2:-/opt/Qt/6.8.3/gcc_64}"
+
+if [[ "${BUILD_DIR}" != /* ]]; then
+ BUILD_DIR="${REPO_ROOT}/${BUILD_DIR}"
+fi
echo "=== Configuring (compile_commands.json) ==="
cmake -GNinja \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCMAKE_PREFIX_PATH="${QT_PREFIX}" \
+ -S "${REPO_ROOT}" \
-B "${BUILD_DIR}"
@@
echo "=== Running clazy ==="
-find "$(pwd)/src" -name "*.cpp" -print0 | \
+find "${REPO_ROOT}/src" -name "*.cpp" -print0 | \
xargs -0 -P "$(nproc)" -I{} clazy-standalone --only-qt --header-filter="src/.*" -p "${BUILD_DIR}" {}Also applies to: 17-18 🤖 Prompt for AI Agents |
||
|
|
||
| echo "=== Generating autogen headers ===" | ||
| ninja -C "${BUILD_DIR}" src/ScopeSource_autogen | ||
|
|
||
| echo "=== Running clazy ===" | ||
| find "$(pwd)/src" -name "*.cpp" -print0 | \ | ||
| xargs -0 -P "$(nproc)" -I{} clazy-standalone --only-qt --header-filter="src/.*" -p "${BUILD_DIR}" {} | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #!/bin/bash | ||
| set -uo pipefail | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| cd "${SCRIPT_DIR}/.." | ||
jgeudens marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| PASS=0 | ||
| FAIL=0 | ||
|
|
||
| run_check() | ||
| { | ||
| local name="$1" | ||
| shift | ||
| echo "=== $name ===" | ||
| if "$@"; then | ||
| echo "--- $name: PASS" | ||
| ((PASS++)) | ||
| else | ||
| echo "--- $name: FAIL" | ||
| ((FAIL++)) | ||
| fi | ||
| echo "" | ||
| } | ||
|
|
||
| run_check "clang-format" bash "${SCRIPT_DIR}/run_clang_format.sh" | ||
| run_check "clang-tidy" bash "${SCRIPT_DIR}/run_clang_tidy.sh" | ||
| run_check "clazy" bash "${SCRIPT_DIR}/run_clazy.sh" | ||
|
|
||
| echo "=== Results: ${PASS} passed, ${FAIL} failed ===" | ||
| [ "${FAIL}" -eq 0 ] | ||
Uh oh!
There was an error while loading. Please reload this page.