Thank you for your interest in contributing to witr-rs! This document provides guidelines and information for contributors.
- Be respectful and constructive
- Focus on what is best for the project and community
- Show empathy towards other contributors
- Rust 1.88 or later
- Git
- Familiarity with Clean Architecture principles
# Clone the repository
git clone https://github.com/rewrite-everything-in-rust/witr-rs.git
cd witr-rs
# Build the project
cargo build
# Run tests
cargo test --all
# Run the tool
cargo run -- --help-
Follow Rust conventions
- Use
cargo fmtbefore committing - Run
cargo clippyand fix all warnings - Follow the Rust API Guidelines
- Use
-
File size limit
- No file should exceed 300 lines
- Split large files into logical modules
- Use the
modsystem to organize code
-
Comments
- Write self-documenting code with clear naming
- Only add comments for non-obvious logic or public APIs
- Use Rust doc comments (
///) for public items - Avoid TODO comments in completed code
-
Error handling
- Use
Result<T, E>for operations that can fail - Use custom error types (defined in
ports.rs) - Provide meaningful error messages
- Use
witr-rs follows Clean Architecture (Ports & Adapters):
src/
├── core/ # Business logic (no external dependencies)
│ ├── models/ # Domain entities
│ ├── ports.rs # Interface definitions (traits)
│ ├── service.rs # Business logic orchestration
│ └── ...
├── adapters/ # Infrastructure (OS-specific implementations)
│ ├── system.rs # Main system adapter
│ └── ...
└── main.rs # CLI entry point
Rules:
- Core should never depend on adapters
- Adapters implement traits defined in core/ports.rs
- Keep platform-specific code in adapters with
#[cfg(target_os = "...")]
- Check the TODO list in README.md
- Create an issue describing what you want to implement
- Discuss the approach before starting major work
- Write tests first (TDD approach recommended)
- Implement the feature following the architecture
- Update documentation (README, code comments)
All new code must include tests:
# Run all tests
cargo test --all
# Run specific test
cargo test test_name
# Run with output
cargo test -- --nocaptureTest requirements:
- Unit tests for all core business logic
- Integration tests for adapter implementations
- Test coverage should not decrease
- All tests must pass on Linux, Windows, and macOS (if possible)
Writing tests:
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_descriptive_name() {
// Arrange
let input = setup_test_data();
// Act
let result = function_under_test(input);
// Assert
assert_eq!(result, expected_output);
}
}Use conditional compilation for platform-specific features:
#[cfg(target_os = "linux")]
pub fn linux_specific_function() {
// Linux implementation
}
#[cfg(target_os = "windows")]
pub fn windows_specific_function() {
// Windows implementation
}
#[cfg(target_os = "macos")]
pub fn macos_specific_function() {
// macOS implementation
}-
Fork the repository
-
Create a feature branch
git checkout -b feature/your-feature-name
-
Make your changes
- Write code
- Add tests
- Update documentation
-
Verify everything works
cargo fmt cargo clippy -- -D warnings cargo test --all cargo build --release -
Commit your changes
git add . git commit -m "feat: add descriptive commit message"
Commit message format:
feat: description- New featurefix: description- Bug fixdocs: description- Documentation onlytest: description- Adding testsrefactor: description- Code refactoringperf: description- Performance improvement
-
Push to your fork
git push origin feature/your-feature-name
-
Create a Pull Request
- Provide a clear description of your changes
- Reference any related issues
- Ensure CI passes
- All PRs require at least one approval
- Maintainers may request changes
- Be responsive to feedback
- Keep PRs focused and reasonably sized
- models/ - Domain entities (Process, Source, Result, etc.)
- ports.rs - Interface definitions (SystemProvider trait)
- service.rs - Business logic (WitrService)
- ancestry.rs - Ancestry tree operations
- time.rs - Time formatting utilities
- color.rs - Color output utilities
- system.rs - Main system adapter implementation
- socketstate.rs - Network socket detection
- boot.rs - Boot time detection
- cmdline.rs - Command-line parsing
- fd.rs - File descriptor handling
- filecontext.rs - File context detection
- resource.rs - Resource context (macOS)
- user.rs - User resolution
- Create
src/adapters/your_adapter.rs - Implement necessary functions with platform guards
- Add module to
src/adapters/mod.rs - Use in
system.rswhere needed - Write unit tests
- Update README if it adds user-facing features
- Add field to
Argsstruct inmain.rs - Update CLI help text
- Implement handler logic in
main() - Add tests
- Update README usage section
- Create formatter function (e.g.,
print_yaml) - Add flag to
Argsstruct - Add condition in main display logic
- Write tests
- Update documentation
- Identify missing functionality for specific OS
- Research platform-specific APIs/commands
- Implement in appropriate adapter with
#[cfg(...)] - Add unit tests (use mocking if necessary)
- Test on actual platform if possible
- Questions: Open a discussion on GitHub
- Bugs: Create an issue with reproduction steps
- Feature ideas: Open an issue for discussion first
Contributors will be acknowledged in release notes and the project README.
Thank you for contributing to witr-rs!