Contributing to FSWatcher
August 13, 2025 ยท View on GitHub
Thank you for your interest in contributing to FSWatcher! This guide will help you get started.
Code of Conduct
By participating in this project, you agree to abide by our Code of Conduct. Please treat all contributors with respect and kindness.
Getting Started
Prerequisites
- Xcode 14.0 or later
- Swift 5.9 or later
- macOS 12.0 or later for development
Setting up the Development Environment
-
Fork the repository on GitHub
-
Clone your fork locally:
git clone https://github.com/YOUR_USERNAME/FSWatcher.git cd FSWatcher -
Open the project in Xcode or use Swift Package Manager:
swift build
Development Guidelines
Code Style
- Follow Swift API Design Guidelines
- Use meaningful variable and function names
- Add documentation comments for all public APIs
- Keep functions focused and concise
- Prefer composition over inheritance
Example of well-documented code
/// Creates a new directory watcher for monitoring file system changes.
///
/// - Parameters:
/// - url: The directory URL to watch. Must be an existing directory.
/// - configuration: Configuration options for the watcher.
/// - Throws: `FSWatcherError` if the directory cannot be watched.
/// - Returns: A configured directory watcher instance.
public init(url: URL, configuration: Configuration = Configuration()) throws {
// Implementation here
}
Architecture Principles
- Event-driven: Use DispatchSource for efficient monitoring
- Thread-safe: All public APIs should be thread-safe
- Resource management: Automatic cleanup of system resources
- Testable: Write testable code with dependency injection
- Performance: Optimize for low resource usage
File Organization
- Core functionality goes in
Sources/FSWatcher/Core/ - Utility classes in
Sources/FSWatcher/Utils/ - Extensions in
Sources/FSWatcher/Extensions/ - Tests in
Tests/FSWatcherTests/ - Examples in
Examples/
Making Changes
Branch Naming
Use descriptive branch names:
feature/recursive-watchingbugfix/memory-leak-in-watcherdocs/api-documentation
Commit Messages
Write clear commit messages:
- Use the imperative mood ("Add feature" not "Added feature")
- Keep the first line under 50 characters
- Reference issues when applicable
Example:
Add predictive ignoring for transform operations
This change allows watchers to predict output files based on
transformation rules, preventing infinite loops in processing
pipelines.
Fixes #123
Testing Requirements
All changes must include appropriate tests:
- Unit Tests: Test individual components
- Integration Tests: Test component interactions
- Performance Tests: For performance-critical changes
Running Tests
# Run all tests
swift test
# Run specific test
swift test --filter DirectoryWatcherTests
# Run with verbose output
swift test --verbose
Writing Tests
func testWatcherDetectsFileCreation() throws {
let tempDir = createTempDirectory()
let watcher = try DirectoryWatcher(url: tempDir)
let expectation = XCTestExpectation(description: "File creation detected")
watcher.onDirectoryChange = { url in
XCTAssertEqual(url, tempDir)
expectation.fulfill()
}
watcher.start()
// Create test file
let testFile = tempDir.appendingPathComponent("test.txt")
try "content".write(to: testFile, atomically: true, encoding: .utf8)
wait(for: [expectation], timeout: 2.0)
}
Documentation
API Documentation
- All public APIs must have complete documentation
- Include parameter descriptions and return values
- Provide usage examples for complex APIs
- Document error conditions
README Updates
Update the README.md when adding new features:
- Add to feature list if applicable
- Update code examples
- Add new use cases
Documentation Files
Maintain documentation in the docs/ directory:
API.md- Complete API referenceAdvanced.md- Advanced usage patternsPerformance.md- Performance optimization
Submitting Changes
Pull Request Process
- Create a focused PR: One feature or fix per PR
- Write a clear description: Explain what changes and why
- Include tests: All changes must be tested
- Update documentation: Keep docs in sync with code
- Check CI: Ensure all checks pass
PR Template
## Description
Brief description of changes
## Type of Change
- [ ] Bug fix
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation update
## Testing
- [ ] Unit tests added/updated
- [ ] Integration tests added/updated
- [ ] Manual testing performed
## Checklist
- [ ] Code follows style guidelines
- [ ] Self-review completed
- [ ] Documentation updated
- [ ] No new warnings introduced
Code Review Process
- Automated checks: CI must pass
- Peer review: At least one approval required
- Maintainer review: For significant changes
- Testing: Verify tests cover the changes
Issue Guidelines
Reporting Bugs
Include the following information:
- macOS/iOS version
- Xcode version
- Swift version
- Minimal reproducible example
- Expected vs actual behavior
Feature Requests
- Describe the use case
- Explain why it's needed
- Suggest possible implementation approaches
- Consider backwards compatibility
Bug Report Template
**Environment:**
- macOS version:
- iOS version (if applicable):
- Xcode version:
- FSWatcher version:
**Description:**
A clear description of the bug.
**Reproduction Steps:**
1.
2.
3.
**Expected Behavior:**
What you expected to happen.
**Actual Behavior:**
What actually happened.
**Code Sample:**
```swift
// Minimal code to reproduce the issue
Additional Context: Any other relevant information.
## Performance Guidelines
### Performance Testing
- Benchmark before and after changes
- Test with realistic workloads
- Monitor memory usage and CPU utilization
- Test with large directory structures
### Memory Management
- Use `weak` references to avoid retain cycles
- Implement proper cleanup in `deinit`
- Monitor memory leaks with Instruments
### Threading
- Ensure thread safety for all public APIs
- Use appropriate queues for different workloads
- Avoid blocking the main thread
## Security Guidelines
- Never commit secrets or credentials
- Validate all file paths and URLs
- Handle permission errors gracefully
- Follow secure coding practices
## Release Process
### Version Numbering
We follow Semantic Versioning (SemVer):
- **MAJOR**: Breaking changes
- **MINOR**: New features (backwards compatible)
- **PATCH**: Bug fixes
### Release Checklist
- [ ] All tests pass
- [ ] Documentation updated
- [ ] CHANGELOG updated
- [ ] Version bumped
- [ ] Release notes prepared
- [ ] Tag created
## Getting Help
- **GitHub Issues**: For bugs and feature requests
- **Discussions**: For questions and general discussion
- **Documentation**: Check existing docs first
- **Examples**: Look at example code
## Recognition
Contributors will be acknowledged in:
- CHANGELOG.md
- GitHub contributors list
- Release notes (for significant contributions)
Thank you for contributing to FSWatcher! ๐