Skip to content

Commit a6bd3c8

Browse files
committed
chore: Standardize on clang-format/clang-tidy 18 and improve code quality
This commit consolidates several improvements to code formatting and quality: - Upgrade to clang-format/clang-tidy version 18 for consistency - CI now explicitly installs LLVM 18 to match local development - Added Makefile variable to override clang-format path - Updated docs to include LLVM 18 installation instructions - Increase line length limit from 100 to 120 characters - Updated .clang-format ColumnLimit to 120 - Reformatted entire codebase with new settings - Improve clang-tidy configuration - Configure to exclude dependency warnings via header-filter - Add run-clang-tidy.sh script for consistent checks - Update VS Code settings to use project config - Update documentation (English and Japanese) - Added detailed LLVM 18 setup instructions for macOS and Linux - Explain why version 18 is required (consistency) - Updated troubleshooting sections This ensures consistent formatting between local development and CI, preventing spurious formatting errors.
1 parent 5575e15 commit a6bd3c8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1921
-1429
lines changed

.clang-format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
BasedOnStyle: Google
33
Language: Cpp
44
Standard: c++17
5-
ColumnLimit: 100
5+
ColumnLimit: 120
66
IndentWidth: 2
77
TabWidth: 2
88
UseTab: Never

.clang-tidy

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,17 @@
22
Checks: >
33
clang-diagnostic-*,
44
clang-analyzer-*,
5+
-clang-analyzer-cplusplus.NewDeleteLeaks,
56
cppcoreguidelines-*,
67
modernize-*,
78
performance-*,
89
readability-*,
9-
-cppcoreguidelines-avoid-magic-numbers,
10-
-readability-magic-numbers,
10+
-readability-function-cognitive-complexity,
1111
-modernize-use-trailing-return-type,
12-
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
13-
-cppcoreguidelines-pro-type-reinterpret-cast,
14-
-modernize-concat-nested-namespaces
12+
-modernize-use-nodiscard
1513
WarningsAsErrors: ''
16-
HeaderFilterRegex: '^(?!.*(_deps|third_party|build)).*$'
14+
HeaderFilterRegex: '.*/src/.*'
1715
FormatStyle: file
1816
CheckOptions:
19-
- key: readability-identifier-naming.ClassCase
20-
value: CamelCase
21-
- key: readability-identifier-naming.FunctionCase
22-
value: CamelCase
23-
- key: readability-identifier-naming.VariableCase
24-
value: lower_case
25-
- key: readability-identifier-naming.ConstantCase
26-
value: CamelCase
27-
- key: readability-identifier-naming.ConstantPrefix
28-
value: 'k'
29-
- key: readability-identifier-naming.MemberCase
30-
value: lower_case
31-
- key: readability-identifier-naming.MemberSuffix
32-
value: '_'
33-
- key: readability-identifier-naming.StructCase
34-
value: CamelCase
35-
- key: readability-identifier-naming.PublicMemberCase
36-
value: lower_case
37-
- key: readability-identifier-naming.PublicMemberSuffix
38-
value: ''
17+
- key: SystemHeaderFilterRegex
18+
value: '.*(_deps|build|third_party)/.*'

.github/workflows/ci.yml

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
build-essential \
3636
libmysqlclient-dev \
3737
libicu-dev \
38+
libreadline-dev \
3839
pkg-config
3940
4041
- name: Install dependencies (macOS)
@@ -44,6 +45,7 @@ jobs:
4445
cmake \
4546
mysql-client@8.4 \
4647
icu4c \
48+
readline \
4749
pkg-config
4850
4951
- name: Configure CMake
@@ -101,29 +103,30 @@ jobs:
101103
run: |
102104
sudo apt-get update
103105
sudo apt-get install -y \
104-
clang-format \
105-
clang-tidy \
106+
wget \
107+
lsb-release \
108+
software-properties-common \
109+
gnupg \
106110
cmake \
107111
build-essential \
108112
libmysqlclient-dev \
109113
libicu-dev \
114+
libreadline-dev \
110115
pkg-config
111116
112-
- name: Check code formatting
113-
run: |
114-
find src tests -name "*.cpp" -o -name "*.h" | \
115-
xargs clang-format --dry-run --Werror
117+
# Install LLVM/Clang 18 for clang-format and clang-tidy
118+
wget https://apt.llvm.org/llvm.sh
119+
chmod +x llvm.sh
120+
sudo ./llvm.sh 18
121+
sudo apt-get install -y clang-format-18 clang-tidy-18
122+
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-18 100
123+
sudo update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-18 100
116124
117-
- name: Configure for clang-tidy
118-
run: |
119-
mkdir -p build
120-
cd build
121-
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
125+
- name: Check code formatting
126+
run: make format-check
122127

123128
- name: Run clang-tidy
124-
run: |
125-
find src -name "*.cpp" | \
126-
xargs clang-tidy -p build --warnings-as-errors='*'
129+
run: make lint
127130

128131
docker-build:
129132
name: Docker Build Test
@@ -174,6 +177,7 @@ jobs:
174177
build-essential \
175178
libmysqlclient-dev \
176179
libicu-dev \
180+
libreadline-dev \
177181
pkg-config \
178182
lcov
179183

.github/workflows/docker-release.yml

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -125,38 +125,3 @@ jobs:
125125
prerelease: false
126126
env:
127127
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
128-
129-
test-image:
130-
name: Test Docker Image
131-
needs: build-and-push
132-
runs-on: ubuntu-latest
133-
134-
steps:
135-
- name: Log in to GitHub Container Registry
136-
uses: docker/login-action@v3
137-
with:
138-
registry: ${{ env.REGISTRY_GHCR }}
139-
username: ${{ github.actor }}
140-
password: ${{ secrets.GITHUB_TOKEN }}
141-
142-
- name: Pull and test image
143-
run: |
144-
docker pull ${{ env.REGISTRY_GHCR }}/${{ env.IMAGE_NAME }}:${GITHUB_REF#refs/tags/}
145-
146-
# Test help command
147-
echo "Testing --help..."
148-
docker run --rm ${{ env.REGISTRY_GHCR }}/${{ env.IMAGE_NAME }}:${GITHUB_REF#refs/tags/} --help
149-
150-
# Test version command
151-
echo "Testing --version..."
152-
docker run --rm ${{ env.REGISTRY_GHCR }}/${{ env.IMAGE_NAME }}:${GITHUB_REF#refs/tags/} --version
153-
154-
# Test config generation and validation
155-
echo "Testing config generation..."
156-
docker run --rm \
157-
-e MYSQL_HOST=testdb \
158-
-e TABLE_NAME=test \
159-
${{ env.REGISTRY_GHCR }}/${{ env.IMAGE_NAME }}:${GITHUB_REF#refs/tags/} \
160-
test-config
161-
162-
echo "Docker image test passed!"

.vscode/settings.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"clangd.onConfigChanged": "ignore",
1010

1111
// When ready to use clangd, uncomment these lines:
12+
// Note: clangd automatically uses .clang-tidy from project root
1213
// "C_Cpp.intelliSenseEngine": "disabled",
1314
// "clangd.path": "/opt/homebrew/opt/llvm/bin/clangd", // or "/usr/bin/clangd" on Linux
1415
// "clangd.arguments": [
@@ -38,7 +39,10 @@
3839
"C_Cpp.codeAnalysis.clangTidy.path": "/opt/homebrew/opt/llvm/bin/clang-tidy",
3940
"C_Cpp.codeAnalysis.clangTidy.useBuildPath": true,
4041
"C_Cpp.codeAnalysis.clangTidy.config": "",
41-
"C_Cpp.codeAnalysis.clangTidy.args": [],
42+
"C_Cpp.codeAnalysis.clangTidy.args": [
43+
"--config-file=.clang-tidy",
44+
"--header-filter=src/.*"
45+
],
4246
"C_Cpp.codeAnalysis.runAutomatically": true,
4347
"C_Cpp.codeAnalysis.updateDelay": 500, // Fast response like ESLint
4448

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ RUN apt-get update && apt-get install -y \
1313
pkg-config \
1414
libmysqlclient-dev \
1515
libicu-dev \
16+
libreadline-dev \
1617
ca-certificates \
1718
&& rm -rf /var/lib/apt/lists/*
1819

@@ -42,6 +43,7 @@ RUN apt-get update && apt-get install -y \
4243
libstdc++6 \
4344
libmysqlclient21 \
4445
libicu70 \
46+
libreadline8 \
4547
ca-certificates \
4648
&& rm -rf /var/lib/apt/lists/*
4749

Makefile

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
# MygramDB Makefile
22
# Convenience wrapper for CMake build system
33

4-
.PHONY: help build test clean rebuild install uninstall format configure run docker-build docker-up docker-down docker-logs docker-test
4+
.PHONY: help build test clean rebuild install uninstall format format-check lint configure run docker-build docker-up docker-down docker-logs docker-test
55

66
# Build directory
77
BUILD_DIR := build
88

99
# Install prefix (can be overridden: make PREFIX=/opt/mygramdb install)
1010
PREFIX ?= /usr/local
1111

12+
# clang-format command (can be overridden: make CLANG_FORMAT=clang-format-18 format)
13+
CLANG_FORMAT ?= clang-format
14+
1215
# Default target
1316
.DEFAULT_GOAL := build
1417

@@ -22,7 +25,9 @@ help:
2225
@echo " make rebuild - Clean and rebuild"
2326
@echo " make install - Install binaries and files"
2427
@echo " make uninstall - Uninstall binaries and files"
25-
@echo " make format - Format code with clang-format"
28+
@echo " make format - Format code with clang-format"
29+
@echo " make format-check - Check code formatting (CI)"
30+
@echo " make lint - Check code with clang-tidy"
2631
@echo " make configure - Configure CMake (for changing options)"
2732
@echo " make run - Build and run mygramdb"
2833
@echo " make help - Show this help message"
@@ -96,9 +101,19 @@ uninstall:
96101
# Format code with clang-format
97102
format:
98103
@echo "Formatting code..."
99-
@find src tests -name "*.cpp" -o -name "*.h" | xargs clang-format -i
104+
@find src tests -name "*.cpp" -o -name "*.h" | xargs $(CLANG_FORMAT) -i
100105
@echo "Format complete!"
101106

107+
# Check code formatting (CI mode - fails on formatting issues)
108+
format-check:
109+
@echo "Checking code formatting..."
110+
@find src tests -name "*.cpp" -o -name "*.h" | xargs $(CLANG_FORMAT) --dry-run --Werror
111+
@echo "Format check passed!"
112+
113+
# Check code with clang-tidy
114+
lint: build
115+
@bash scripts/run-clang-tidy.sh
116+
102117
# Build and run mygramdb
103118
run: build
104119
@echo "Running MygramDB..."

0 commit comments

Comments
 (0)