diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..7ea33a6 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,40 @@ +# Code of Conduct + +## Our Pledge + +We are committed to providing a friendly, safe, and welcoming environment for all contributors, regardless of level of experience, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, nationality, or other similar characteristics. + +## Our Standards + +Examples of behavior that contributes to a positive environment: + +- **Be respectful** and considerate in your communication +- **Be collaborative** and constructive in your feedback +- **Be patient** with newcomers and those learning +- **Focus on what is best** for the community and project +- **Show empathy** towards other community members + +Examples of unacceptable behavior: + +- Harassment, discrimination, or prejudicial comments +- Personal attacks or insults +- Trolling or deliberately inflammatory comments +- Public or private harassment +- Publishing others' private information without permission +- Other conduct that could reasonably be considered inappropriate + +## Enforcement + +Project maintainers are responsible for clarifying standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. + +Project maintainers have the right to remove, edit, or reject comments, commits, code, issues, and other contributions that are not aligned with this Code of Conduct. + +## Reporting + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting the project maintainers directly. + +All complaints will be reviewed and investigated promptly and fairly. All project maintainers are obligated to respect the privacy and security of the reporter of any incident. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org), version 2.1. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..a8442dd --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,212 @@ +# Contributing to swift-ui-debug-scan + +Thank you for your interest in contributing to swift-ui-debug-scan! This document provides guidelines and information for contributors. + +## Table of Contents + +- [Getting Started](#getting-started) +- [Development Environment](#development-environment) +- [Making Contributions](#making-contributions) +- [Testing](#testing) +- [Code Standards](#code-standards) +- [Pull Request Process](#pull-request-process) +- [Platform Support](#platform-support) + +## Getting Started + +### Prerequisites + +- **Xcode**: Version 15.4+ (Swift 5.9+) or 16.1+ (Swift 6.0+) +- **macOS**: 13+ recommended for full platform testing +- **Swift**: 6.0+ (as specified in Package.swift) +- **Git**: For version control + +### Cloning the Repository + +```bash +git clone https://github.com/ConsultingMD/swift-ui-debug-scan.git +cd swift-ui-debug-scan +``` + +### Initial Setup + +The project uses Swift Package Manager, so no additional setup is required beyond cloning. + +```bash +# Verify the package builds correctly +swift build + +# Run the test suite +swift test +``` + +## Development Environment + +### IDE Recommendations + +- **Xcode**: Primary development environment +- **VS Code**: With Swift extensions for lighter editing +- **Any editor**: That supports Swift syntax highlighting + +### Package Structure + +``` +swift-ui-debug-scan/ +├── Sources/ +│ └── SwiftUIDebugScan/ +│ └── DebugScan.swift # Main implementation +├── Tests/ +│ └── SwiftUIDebugScanTests/ # Test suite +├── Package.swift # Package definition +├── README.md # Project documentation +├── CHANGELOG.md # Release history +└── CI_SETUP.md # CI/CD documentation +``` + +## Making Contributions + +### Types of Contributions + +We welcome: + +- **Bug fixes**: Resolving issues or unexpected behavior +- **Feature enhancements**: Improving existing functionality +- **New features**: Adding capabilities that align with the project's goals +- **Documentation improvements**: Enhancing clarity and completeness +- **Performance optimizations**: Making the library faster or more efficient +- **Test coverage**: Adding or improving tests + +### Before You Start + +1. **Check existing issues**: Look for related issues or discussions +2. **Open an issue**: For significant changes, discuss the approach first +3. **Fork the repository**: Create your own fork to work in +4. **Create a branch**: Use a descriptive name (`feature/improved-logging`, `fix/memory-leak`, etc.) + +## Testing + +### Running Tests + +```bash +# Run all tests +swift test + +# Run tests with verbose output +swift test --verbose + +# Run tests with debug scan verbose mode +SWIFTUI_DEBUG_SCAN_VERBOSE=1 swift test + +# Run tests for specific platform (if using Xcode) +xcodebuild test -scheme SwiftUIDebugScan -destination 'platform=iOS Simulator,name=iPhone 15' +``` + +### Test Requirements + +- **Code Coverage**: Maintain at least 80% test coverage (project target) +- **Platform Testing**: Ensure tests pass on all supported platforms: + - iOS 15+ + - macOS 12+ + - tvOS 15+ + - watchOS 8+ + - visionOS 1+ + +### Writing Tests + +- Place tests in the `Tests/SwiftUIDebugScanTests/` directory +- Follow existing naming conventions (`*Tests.swift`) +- Use descriptive test method names +- Test edge cases and error conditions + +### Test Categories + +Current test files cover: +- **FileParsingTests**: File path and module extraction +- **IntegrationTests**: End-to-end functionality +- **RenderStateTests**: State management and render counting +- **StringDemanglingTests**: Swift symbol demangling +- **ViewInspectorTests**: SwiftUI view testing with ViewInspector + +## Code Standards + +### Swift Style Guide + +- **Swift 6**: Use modern Swift 6 features and syntax +- **Strict Concurrency**: Follow Swift 6 concurrency guidelines + +### Specific Guidelines + +#### Debug Mode Only Features +```swift +#if DEBUG +// Debug-only code here +#endif +``` + +## Pull Request Process + +### Before Submitting + +1. **Update documentation**: If you've changed functionality +2. **Add tests**: For new features or bug fixes +3. **Run the full test suite**: Ensure all tests pass +4. **Check code coverage**: Maintain or improve coverage +5. **Update CHANGELOG.md**: Add entry for your changes + +### PR Requirements + +- **Clear Title**: Descriptive and concise +- **Description**: Explain what changes were made and why +- **Issue Reference**: Link to related issues +- **Testing**: Describe how the changes were tested +- **Breaking Changes**: Clearly identify any breaking changes + +### Review Process + +1. **Automated Checks**: CI must pass (build, test, coverage) +2. **Code Review**: At least one maintainer review required +3. **Platform Testing**: Verify functionality across supported platforms +4. **Documentation**: Ensure documentation is updated if needed + +### CI/CD Pipeline + +The project uses GitHub Actions with comprehensive testing: + +- **Build Validation**: Swift package builds successfully +- **Multi-Platform Testing**: iOS, macOS, tvOS, watchOS, visionOS +- **Code Coverage**: Codecov integration with 80% target +- **Package Validation**: Dependency resolution and structure checks + +## Platform Support + +### Supported Platforms + +- **iOS**: 15.0+ +- **macOS**: 12.0+ +- **tvOS**: 15.0+ +- **watchOS**: 8.0+ +- **visionOS**: 1.0+ + +### Platform-Specific Considerations + +- **Performance**: Consider platform limitations (watchOS memory, etc.) +- **API Availability**: Use appropriate availability checks +- **Testing**: Ensure functionality works across all platforms + +## Getting Help + +- **Issues**: Open a GitHub issue for bugs or feature requests +- **Discussions**: Use GitHub discussions for questions +- **Documentation**: Check README.md and CI_SETUP.md for additional information + +## Code of Conduct + +Please be respectful and professional in all interactions. We strive to maintain a welcoming and inclusive environment for all contributors. + +## Recognition + +Contributors are recognized in release notes and commit history. Significant contributions may be highlighted in the README or other project documentation. + +--- + +Thank you for contributing to swift-ui-debug-scan! Your efforts help make SwiftUI debugging better for the entire Swift community. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c953e4d --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 ConsultingMD + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 03d1cc8..a0eb60c 100644 --- a/README.md +++ b/README.md @@ -6,19 +6,9 @@ [![Swift Package Manager](https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager) [![Platforms](https://img.shields.io/badge/platforms-iOS%20%7C%20macOS%20%7C%20tvOS%20%7C%20watchOS%20%7C%20visionOS-lightgrey.svg)](https://github.com/ConsultingMD/swift-ui-debug-scan) -A Swift package designed to enhance your debugging experience with SwiftUI views by providing detailed and structured debug logging. +**Enhanced SwiftUI debugging with structured view insights and render tracking.** - -## Why use swift-ui-debug-scan? - -Debugging SwiftUI can often feel like navigating a maze, especially when trying to trace metadata such as the file a view belongs to, the module it was declared in, or how often it gets redrawn. This lack of visibility can be particularly challenging in large, server-driven UI applications where static data is sparse, and the codebase is unfamiliar. - -swift-ui-debug-scan bridges this gap by offering structured, actionable insights into your SwiftUI views. With this tool, you can easily track view metadata, redraw counts, and other runtime information, making it easier to debug and optimize your SwiftUI applications. - - -## How it Works - -The `.debugScan(_ label: String)` view modifier is the core of this library. By applying this modifier to your SwiftUI views, you can log structured debug information about the view's lifecycle and runtime behavior. +## Quick Start ```swift import SwiftUI @@ -26,72 +16,72 @@ import SwiftUIDebugScan struct ContentView: View { var body: some View { - Text("Some feature").debugScan("Content") + Text("Hello World").debugScan("MainView") } } ``` -## Sample Debug Output - -When running your app in debug mode, you'll see logs like the following in the console: - +**Console Output:** ``` -🧩 [Content] +🧩 [MainView] • 📂 file: ContentView.swift • 📚 module: MyApp • 🎨 redraws: 1 • ⏱️ timestamp: 2025-07-21 14:05:40 +0000 ``` -## When to use `.debugScan`? +## Why Use This? -Apply the `.debugScan(_ label: String)` modifier to root views rather than leaf views. This ensures you capture meaningful data about the overall structure and behavior of your app without overwhelming your logs with excessive detail. +- 🔍 **View Metadata**: Track file, module, and render counts +- 🐛 **Debug Complex UIs**: Essential for large, server-driven applications +- ⚡ **Performance Insights**: Identify over-rendering and optimization opportunities +- 🎯 **Targeted Debugging**: Focus on root views without log noise -For example: -- Use `.debugScan(_ label: String)` on the root view of a screen or a major container view. -- Avoid applying it to small, frequently updated views unless necessary. +## Usage Best Practices + +**✅ Apply to root views:** +```swift +NavigationView { + HomeScreen() +}.debugScan("HomeNavigation") +``` -## Verbose Mode +**❌ Avoid on leaf views:** +```swift +// Don't do this - too much noise +Text("Button").debugScan("ButtonText") +``` -For even more detailed logging, enable verbose mode by setting the `SWIFTUI_DEBUG_SCAN_VERBOSE` environment variable to true, yes, or 1. This will include additional runtime information such as: +**💡 Recommended targets:** +- Screen root views +- Major container views +- Complex custom components +- Views with performance concerns -- Call stack symbols -- Thread details -- System memory and processor usage -- Uptime and elapsed time +## Advanced Features -Verbose mode is especially useful for diagnosing complex issues in large applications. +### Verbose Mode +Set `SWIFTUI_DEBUG_SCAN_VERBOSE=1` for detailed diagnostics: +- 🧵 Call stack and thread info +- 💾 Memory and CPU usage +- ⏱️ Performance timing +- 📊 System metrics ## Installation -Add this package to your project using Swift Package Manager: - +**Swift Package Manager:** ```swift dependencies: [ .package(url: "https://github.com/ConsultingMD/swift-ui-debug-scan", from: "0.1.0") ] ``` -Then add the dependency to your target: - -```swift -.target( - name: "YourTarget", - dependencies: [ - .product(name: "SwiftUIDebugScan", package: "swift-ui-debug-scan") - ] -) -``` - -Alternatively, you can add the package directly in Xcode: - -1. Open your project in Xcode. -2. Navigate to `File > Add Packages`. -3. Enter the repository URL: `https://github.com/ConsultingMD/swift-ui-debug-scan`. -4. Choose the version or branch you want to use. -5. Add the package to your desired target. +**Xcode:** `File > Add Packages` → Enter URL above ## Contributing -Contributions are welcome! If you have ideas for new features, improvements, or bug fixes, feel free to open an issue or submit a pull request. +Contributions welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines. + +**Quick fixes:** Fork → Change → Test → PR +**New features:** Open issue first to discuss