Skip to content

Commit cc6564d

Browse files
committed
优化测试逻辑
1 parent fc7ac5b commit cc6564d

File tree

12 files changed

+890
-72
lines changed

12 files changed

+890
-72
lines changed

README.md

Lines changed: 181 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,183 @@
11
# clang-format
2-
Using Clang-Format in Golang
32

4-
## proto-format
5-
Format Protobuf File Using Clang-Format in Golang
3+
Go wrapper for clang-format with Protocol Buffers formatting capabilities.
4+
5+
---
6+
7+
## CHINESE README
8+
9+
[中文说明](README.zh.md)
10+
11+
## Key Features
12+
13+
🎯 **Intelligent Proto Formatting**: Smart clang-format wrapper with Google style defaults
14+
**Dual Operation Modes**: Both preview (DryRun) and in-place formatting support
15+
🔄 **Batch Processing**: Recursive project-wide .proto file formatting
16+
🌍 **Configurable Styles**: Customizable formatting styles with JSON configuration
17+
📋 **Comprehensive Logging**: Detailed operation logs with structured output
18+
19+
## Install
20+
21+
```bash
22+
go install github.com/go-xlan/clang-format@latest
23+
```
24+
25+
## Prerequisites
26+
27+
Install clang-format on your system:
28+
29+
```bash
30+
# macOS
31+
brew install clang-format
32+
33+
# Ubuntu/Debian
34+
sudo apt-get install clang-format
35+
36+
# Verify installation
37+
clang-format --version
38+
```
39+
40+
## Usage
41+
42+
### Protocol Buffers Formatting (Primary Use Case)
43+
44+
```go
45+
package main
46+
47+
import (
48+
"fmt"
49+
"github.com/go-xlan/clang-format/protoformat"
50+
"github.com/yyle88/must"
51+
"github.com/yyle88/osexec"
52+
"github.com/yyle88/rese"
53+
)
54+
55+
func main() {
56+
execConfig := osexec.NewExecConfig()
57+
style := protoformat.NewStyle()
58+
59+
// Preview .proto file formatting (DryRun)
60+
output := rese.V1(protoformat.DryRun(execConfig, "example.proto", style))
61+
fmt.Println(string(output))
62+
63+
// Format single .proto file
64+
rese.V1(protoformat.Format(execConfig, "example.proto", style))
65+
66+
// Format entire project (batch processing)
67+
must.Done(protoformat.FormatProject(execConfig, "./proto-project", style))
68+
}
69+
```
70+
71+
### Custom Style Configuration
72+
73+
```go
74+
customStyle := &clangformat.Style{
75+
BasedOnStyle: "LLVM",
76+
IndentWidth: 4,
77+
ColumnLimit: 80,
78+
AlignConsecutiveAssignments: true,
79+
}
80+
81+
output := rese.V1(protoformat.DryRun(execConfig, "example.proto", customStyle))
82+
```
83+
84+
### General File Formatting (C/C++ Support)
85+
86+
```go
87+
import "github.com/go-xlan/clang-format/clangformat"
88+
89+
// Format C/C++ files
90+
output := rese.V1(clangformat.DryRun(execConfig, "example.cpp", style))
91+
must.Done(clangformat.Format(execConfig, "example.cpp", style))
92+
```
93+
94+
## API Reference
95+
96+
### clangformat Package
97+
98+
- `NewStyle()` - Creates default Google-based style configuration
99+
- `DryRun(config, path, style)` - Preview formatting without file modification
100+
- `Format(config, path, style)` - Apply formatting directly to file
101+
102+
### protoformat Package
103+
104+
- `NewStyle()` - Creates Protocol Buffers optimized style configuration
105+
- `DryRun(config, path, style)` - Preview .proto file formatting
106+
- `Format(config, path, style)` - Format single .proto file
107+
- `FormatProject(config, path, style)` - Batch format all .proto files in project
108+
109+
### Style Configuration
110+
111+
```go
112+
type Style struct {
113+
BasedOnStyle string // "Google", "LLVM", "Chromium", etc.
114+
IndentWidth int // Number of spaces for indentation
115+
ColumnLimit int // Maximum line length (0 = no limit)
116+
AlignConsecutiveAssignments bool // Align assignments at equal signs
117+
}
118+
```
119+
120+
<!-- TEMPLATE (EN) BEGIN: STANDARD PROJECT FOOTER -->
121+
122+
## 📄 License
123+
124+
MIT License. See [LICENSE](LICENSE).
125+
126+
---
127+
128+
## 🤝 Contributing
129+
130+
Contributions are welcome! Report bugs, suggest features, and contribute code:
131+
132+
- 🐛 **Found a bug?** Open an issue on GitHub with reproduction steps
133+
- 💡 **Have a feature idea?** Create an issue to discuss the suggestion
134+
- 📖 **Documentation confusing?** Report it so we can improve
135+
- 🚀 **Need new features?** Share your use cases to help us understand requirements
136+
-**Performance issue?** Help us optimize by reporting slow operations
137+
- 🔧 **Configuration problem?** Ask questions about complex setups
138+
- 📢 **Follow project progress?** Watch the repo for new releases and features
139+
- 🌟 **Success stories?** Share how this package improved your workflow
140+
- 💬 **General feedback?** All suggestions and comments are welcome
141+
142+
---
143+
144+
## 🔧 Development
145+
146+
New code contributions, follow this process:
147+
148+
1. **Fork**: Fork the repo on GitHub (using the webpage interface).
149+
2. **Clone**: Clone the forked project (`git clone https://github.com/yourname/repo-name.git`).
150+
3. **Navigate**: Navigate to the cloned project (`cd repo-name`)
151+
4. **Branch**: Create a feature branch (`git checkout -b feature/xxx`).
152+
5. **Code**: Implement your changes with comprehensive tests
153+
6. **Testing**: (Golang project) Ensure tests pass (`go test ./...`) and follow Go code style conventions
154+
7. **Documentation**: Update documentation for user-facing changes and use meaningful commit messages
155+
8. **Stage**: Stage changes (`git add .`)
156+
9. **Commit**: Commit changes (`git commit -m "Add feature xxx"`) ensuring backward compatible code
157+
10. **Push**: Push to the branch (`git push origin feature/xxx`).
158+
11. **PR**: Open a pull request on GitHub (on the GitHub webpage) with detailed description.
159+
160+
Please ensure tests pass and include relevant documentation updates.
161+
162+
---
163+
164+
## 🌟 Support
165+
166+
Welcome to contribute to this project by submitting pull requests and reporting issues.
167+
168+
**Project Support:**
169+
170+
-**Give GitHub stars** if this project helps you
171+
- 🤝 **Share with teammates** and (golang) programming friends
172+
- 📝 **Write tech blogs** about development tools and workflows - we provide content writing support
173+
- 🌟 **Join the ecosystem** - committed to supporting open source and the (golang) development scene
174+
175+
**Happy Coding with this package!** 🎉
176+
177+
<!-- TEMPLATE (EN) END: STANDARD PROJECT FOOTER -->
178+
179+
---
180+
181+
## GitHub Stars
182+
183+
[![Stargazers](https://starchart.cc/go-xlan/clang-format.svg?variant=adaptive)](https://starchart.cc/go-xlan/clang-format)

README.zh.md

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
# clang-format
2+
3+
clang-format 的 Go 封装工具,专为 Protocol Buffers 格式化而设计。
4+
5+
## 英文文档
6+
7+
[ENGLISH README](README.md)
8+
9+
## 核心特性
10+
11+
🎯 **智能 Proto 格式化**: 智能的 clang-format 包装器,默认使用 Google 样式
12+
**双重操作模式**: 支持预览(DryRun)和就地格式化两种模式
13+
🔄 **批量处理**: 递归的项目级 .proto 文件格式化
14+
🌍 **可配置样式**: 支持 JSON 配置的自定义格式化样式
15+
📋 **全面日志**: 详细的操作日志和结构化输出
16+
17+
## 安装
18+
19+
```bash
20+
go install github.com/go-xlan/clang-format@latest
21+
```
22+
23+
## 前置要求
24+
25+
在系统中安装 clang-format:
26+
27+
```bash
28+
# macOS
29+
brew install clang-format
30+
31+
# Ubuntu/Debian
32+
sudo apt-get install clang-format
33+
34+
# 验证安装
35+
clang-format --version
36+
```
37+
38+
## 使用方法
39+
40+
### Protocol Buffers 格式化(主要功能)
41+
42+
```go
43+
package main
44+
45+
import (
46+
"fmt"
47+
"github.com/go-xlan/clang-format/protoformat"
48+
"github.com/yyle88/must"
49+
"github.com/yyle88/osexec"
50+
"github.com/yyle88/rese"
51+
)
52+
53+
func main() {
54+
execConfig := osexec.NewExecConfig()
55+
style := protoformat.NewStyle()
56+
57+
// 预览 .proto 文件格式化 (DryRun)
58+
output := rese.V1(protoformat.DryRun(execConfig, "example.proto", style))
59+
fmt.Println(string(output))
60+
61+
// 格式化单个 .proto 文件
62+
rese.V1(protoformat.Format(execConfig, "example.proto", style))
63+
64+
// 格式化整个项目(批量处理)
65+
must.Done(protoformat.FormatProject(execConfig, "./proto-project", style))
66+
}
67+
```
68+
69+
### 自定义样式配置
70+
71+
```go
72+
customStyle := &clangformat.Style{
73+
BasedOnStyle: "LLVM",
74+
IndentWidth: 4,
75+
ColumnLimit: 80,
76+
AlignConsecutiveAssignments: true,
77+
}
78+
79+
output := rese.V1(protoformat.DryRun(execConfig, "example.proto", customStyle))
80+
```
81+
82+
### 通用文件格式化(C/C++ 支持)
83+
84+
```go
85+
import "github.com/go-xlan/clang-format/clangformat"
86+
87+
// 格式化 C/C++ 文件
88+
output := rese.V1(clangformat.DryRun(execConfig, "example.cpp", style))
89+
must.Done(clangformat.Format(execConfig, "example.cpp", style))
90+
```
91+
92+
## API 参考
93+
94+
### clangformat 包
95+
96+
- `NewStyle()` - 创建默认的基于 Google 的样式配置
97+
- `DryRun(config, path, style)` - 预览格式化而不修改文件
98+
- `Format(config, path, style)` - 直接对文件应用格式化
99+
100+
### protoformat 包
101+
102+
- `NewStyle()` - 创建针对 Protocol Buffers 优化的样式配置
103+
- `DryRun(config, path, style)` - 预览 .proto 文件格式化
104+
- `Format(config, path, style)` - 格式化单个 .proto 文件
105+
- `FormatProject(config, path, style)` - 批量格式化项目中的所有 .proto 文件
106+
107+
### 样式配置
108+
109+
```go
110+
type Style struct {
111+
BasedOnStyle string // "Google", "LLVM", "Chromium" 等
112+
IndentWidth int // 缩进空格数
113+
ColumnLimit int // 最大行长度 (0 = 无限制)
114+
AlignConsecutiveAssignments bool // 在等号处对齐赋值
115+
}
116+
```
117+
118+
<!-- TEMPLATE (ZH) BEGIN: STANDARD PROJECT FOOTER -->
119+
120+
## 📄 许可证类型
121+
122+
MIT 许可证。详见 [LICENSE](LICENSE)
123+
124+
---
125+
126+
## 🤝 项目贡献
127+
128+
非常欢迎贡献代码!报告 BUG、建议功能、贡献代码:
129+
130+
- 🐛 **发现问题?** 在 GitHub 上提交问题并附上重现步骤
131+
- 💡 **功能建议?** 创建 issue 讨论您的想法
132+
- 📖 **文档疑惑?** 报告问题,帮助我们改进文档
133+
- 🚀 **需要功能?** 分享使用场景,帮助理解需求
134+
-**性能瓶颈?** 报告慢操作,帮助我们优化性能
135+
- 🔧 **配置困扰?** 询问复杂设置的相关问题
136+
- 📢 **关注进展?** 关注仓库以获取新版本和功能
137+
- 🌟 **成功案例?** 分享这个包如何改善工作流程
138+
- 💬 **意见反馈?** 欢迎所有建议和宝贵意见
139+
140+
---
141+
142+
## 🔧 代码贡献
143+
144+
新代码贡献,请遵循此流程:
145+
146+
1. **Fork**:在 GitHub 上 Fork 仓库(使用网页界面)
147+
2. **克隆**:克隆 Fork 的项目(`git clone https://github.com/yourname/repo-name.git`
148+
3. **导航**:进入克隆的项目(`cd repo-name`
149+
4. **分支**:创建功能分支(`git checkout -b feature/xxx`
150+
5. **编码**:实现您的更改并编写全面的测试
151+
6. **测试**:(Golang 项目)确保测试通过(`go test ./...`)并遵循 Go 代码风格约定
152+
7. **文档**:为面向用户的更改更新文档,并使用有意义的提交消息
153+
8. **暂存**:暂存更改(`git add .`
154+
9. **提交**:提交更改(`git commit -m "Add feature xxx"`)确保向后兼容的代码
155+
10. **推送**:推送到分支(`git push origin feature/xxx`
156+
11. **PR**:在 GitHub 上打开 Pull Request(在 GitHub 网页上)并提供详细描述
157+
158+
请确保测试通过并包含相关的文档更新。
159+
160+
---
161+
162+
## 🌟 项目支持
163+
164+
非常欢迎通过提交 Pull Request 和报告问题来为此项目做出贡献。
165+
166+
**项目支持:**
167+
168+
-**给予星标**如果项目对您有帮助
169+
- 🤝 **分享项目**给团队成员和(golang)编程朋友
170+
- 📝 **撰写博客**关于开发工具和工作流程 - 我们提供写作支持
171+
- 🌟 **加入生态** - 致力于支持开源和(golang)开发场景
172+
173+
**使用这个包快乐编程!** 🎉
174+
175+
<!-- TEMPLATE (ZH) END: STANDARD PROJECT FOOTER -->
176+
177+
---
178+
179+
## GitHub 标星点赞
180+
181+
[![Stargazers](https://starchart.cc/go-xlan/clang-format.svg?variant=adaptive)](https://starchart.cc/go-xlan/clang-format)

0 commit comments

Comments
 (0)