Go wrapper for clang-format with Protocol Buffers formatting capabilities.
🎯 Intelligent Proto Formatting: Smart clang-format wrapper with Google style defaults
⚡ Dual Operation Modes: Both preview (DryRun) and in-place formatting support
🔄 Batch Processing: Recursive project-wide .proto file formatting
🌍 Configurable Styles: Customizable formatting styles with JSON configuration
📋 Comprehensive Logging: Detailed operation logs with structured output
go install github.com/go-xlan/clang-format@latest
Install clang-format on your system:
# macOS
brew install clang-format
# Ubuntu/Debian
sudo apt-get install clang-format
# Verify installation
clang-format --version
package main
import (
"fmt"
"github.com/go-xlan/clang-format/protoformat"
"github.com/yyle88/must"
"github.com/yyle88/osexec"
"github.com/yyle88/rese"
)
func main() {
execConfig := osexec.NewExecConfig()
style := protoformat.NewStyle()
// Preview .proto file formatting (DryRun)
output := rese.V1(protoformat.DryRun(execConfig, "example.proto", style))
fmt.Println(string(output))
// Format single .proto file
rese.V1(protoformat.Format(execConfig, "example.proto", style))
// Format entire project (batch processing)
must.Done(protoformat.FormatProject(execConfig, "./proto-project", style))
}
customStyle := &clangformat.Style{
BasedOnStyle: "LLVM",
IndentWidth: 4,
ColumnLimit: 80,
AlignConsecutiveAssignments: true,
}
output := rese.V1(protoformat.DryRun(execConfig, "example.proto", customStyle))
import "github.com/go-xlan/clang-format/clangformat"
// Format C/C++ files
output := rese.V1(clangformat.DryRun(execConfig, "example.cpp", style))
must.Done(clangformat.Format(execConfig, "example.cpp", style))
NewStyle()
- Creates default Google-based style configurationDryRun(config, path, style)
- Preview formatting without file modificationFormat(config, path, style)
- Apply formatting directly to file
NewStyle()
- Creates Protocol Buffers optimized style configurationDryRun(config, path, style)
- Preview .proto file formattingFormat(config, path, style)
- Format single .proto fileFormatProject(config, path, style)
- Batch format all .proto files in project
type Style struct {
BasedOnStyle string // "Google", "LLVM", "Chromium", etc.
IndentWidth int // Number of spaces for indentation
ColumnLimit int // Maximum line length (0 = no limit)
AlignConsecutiveAssignments bool // Align assignments at equal signs
}
MIT License. See LICENSE.
Contributions are welcome! Report bugs, suggest features, and contribute code:
- 🐛 Found a bug? Open an issue on GitHub with reproduction steps
- 💡 Have a feature idea? Create an issue to discuss the suggestion
- 📖 Documentation confusing? Report it so we can improve
- 🚀 Need new features? Share your use cases to help us understand requirements
- ⚡ Performance issue? Help us optimize by reporting slow operations
- 🔧 Configuration problem? Ask questions about complex setups
- 📢 Follow project progress? Watch the repo for new releases and features
- 🌟 Success stories? Share how this package improved your workflow
- 💬 General feedback? All suggestions and comments are welcome
New code contributions, follow this process:
- Fork: Fork the repo on GitHub (using the webpage interface).
- Clone: Clone the forked project (
git clone https://github.com/yourname/repo-name.git
). - Navigate: Navigate to the cloned project (
cd repo-name
) - Branch: Create a feature branch (
git checkout -b feature/xxx
). - Code: Implement your changes with comprehensive tests
- Testing: (Golang project) Ensure tests pass (
go test ./...
) and follow Go code style conventions - Documentation: Update documentation for user-facing changes and use meaningful commit messages
- Stage: Stage changes (
git add .
) - Commit: Commit changes (
git commit -m "Add feature xxx"
) ensuring backward compatible code - Push: Push to the branch (
git push origin feature/xxx
). - PR: Open a pull request on GitHub (on the GitHub webpage) with detailed description.
Please ensure tests pass and include relevant documentation updates.
Welcome to contribute to this project by submitting pull requests and reporting issues.
Project Support:
- ⭐ Give GitHub stars if this project helps you
- 🤝 Share with teammates and (golang) programming friends
- 📝 Write tech blogs about development tools and workflows - we provide content writing support
- 🌟 Join the ecosystem - committed to supporting open source and the (golang) development scene
Happy Coding with this package! 🎉