Successfully implemented a lightweight, cross-platform pre-commit validation framework for mruby-based projects. This framework replaces the need for Python-based pre-commit tools and integrates seamlessly with the existing dotfiles system.
lib/pre_commit.rb- Main framework module with Config and Runner classeslib/pre_commit/validators/whitespace.rb- Whitespace cleaning validatorlib/pre_commit/validators/line_length.rb- Line length enforcement validatorlib/pre_commit/validators/syntax.rb- Basic Ruby syntax validator
bin/pre-commit- Git pre-commit hook scriptbin/setup-pre-commit- Hook installation/uninstallation scriptlib/pre_commit_example.rb- Usage examplestest_pre_commit.rb- Test script
lib/pre_commit/README.md- Comprehensive documentationPRE_COMMIT_FRAMEWORK.md- This summary document
- Works on Windows, macOS, and Linux
- Handles different line ending conventions
- Platform-aware file operations
- Whitespace Validator: Removes trailing whitespace, converts line endings, ensures final newline
- Line Length Validator: Enforces maximum line length with smart exclusions
- Syntax Validator: Basic Ruby syntax checking within mruby constraints
- Easy to add custom validators
- Configuration-based approach
- Automatic loading of .gitignore patterns
- Seamless hook installation
- Automatic staging area detection
- Proper exit codes for git workflow
ruby bin/setup-pre-commit installruby bin/pre-commitPreCommit.configure do |config|
config.add_validator(PreCommit::Validators::Whitespace.new)
config.add_validator(PreCommit::Validators::LineLength.new(79))
config.add_validator(PreCommit::Validators::Syntax.new)
config.exclude('vendor/**/*')
config.exclude('*.min.js')
endThis framework is designed to be part of the mruby-based build process:
- Pre-commit hooks - Automatic validation before commits
- Build validation - Can be called during build process
- CI/CD integration - Can be used in continuous integration
The framework has been successfully tested:
- ✅ Whitespace cleaning works correctly
- ✅ Automatic fixes are applied
- ✅ Error reporting functions properly
- ✅ Cross-platform file operations work
- Integrate with build system - Add to the main mruby build process
- Add more validators - Consider adding validators for specific file types
- Configuration files - Support for .pre-commit-config files
- Performance optimization - Optimize for large codebases
- Native mruby integration - No external dependencies
- Lighter weight - Minimal resource usage
- Better cross-platform support - No Python version conflicts
- Seamless dotfiles integration - Part of the existing ecosystem
This framework successfully addresses the original requirement for a pre-commit system while maintaining the mruby-based architecture of the dotfiles project.