Go package for clang-format with Protocol Buffers and C/C++ batch formatting capabilities.
π― Intelligent Proto Formatting: Smart clang-format package with Google style defaults
β‘ Two 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 get github.com/go-xlan/clang-format@latest
go install github.com/go-xlan/clang-format/cmd/clang-format-batch@latest
Setup clang-format as requirement:
# macOS
brew install clang-format
# Ubuntu/Debian
sudo apt-get install clang-format
# Verify installation
clang-format --version
# Format all .proto files in current project
clang-format-batch --extensions=".proto"
# Format C/C++ files
clang-format-batch --extensions=".c,.cpp,.h"
# Format multiple file types
clang-format-batch --extensions=".proto,.c,.cpp,.h"
# Use short flag
clang-format-batch -e ".proto,.cc,.hh"
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)
- Use formatting on 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 // Count of spaces for indentation
ColumnLimit int // Maximum line length (0 = no limit)
AlignConsecutiveAssignments bool // Align assignments at assignment 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 the use cases to help us understand requirements
- β‘ Performance issue? Help us optimize through reporting slow operations
- π§ Configuration problem? Ask questions about complex setups
- π’ Follow project progress? Watch the repo to get new releases and features
- π Success stories? Share how this package improved the workflow
- π¬ Feedback? We welcome suggestions and comments
New code contributions, follow this process:
- Fork: Fork the repo on GitHub (using the webpage UI).
- 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 the changes with comprehensive tests
- Testing: (Golang project) Ensure tests pass (
go test ./...
) and follow Go code style conventions - Documentation: Update documentation to support client-facing changes and use significant 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 via submitting merge 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
Have Fun Coding with this package! π