Skip to content

Contributing

Chris W edited this page Dec 9, 2024 · 2 revisions

Contributing to Goshot

Thank you for your interest in contributing to Goshot! This guide will help you get started with contributing to the project.

Code of Conduct

By participating in this project, you are expected to uphold our Code of Conduct:

  • Be respectful and inclusive
  • Exercise consideration and empathy
  • Focus on what is best for the community
  • Use welcoming and inclusive language
  • Be collaborative
  • Gracefully accept constructive criticism

πŸ“ Project Structure

.
β”œβ”€β”€ cmd/
β”‚   β”œβ”€β”€ goshot/          # CLI implementation
β”‚   └── examples/        # Example code and demos
β”œβ”€β”€ pkg/
β”‚   β”œβ”€β”€ background/      # Background processing
β”‚   β”‚   β”œβ”€β”€ background.go # Main background interface
β”‚   β”‚   β”œβ”€β”€ color.go     # Solid color backgrounds
β”‚   β”‚   β”œβ”€β”€ gradient.go  # Gradient backgrounds
β”‚   β”‚   β”œβ”€β”€ image.go     # Image backgrounds
β”‚   β”‚   └── shadow.go    # Shadow effects
β”‚   β”œβ”€β”€ chrome/          # Window styling and rendering
β”‚   β”‚   β”œβ”€β”€ chrome.go    # Window chrome interface
β”‚   β”‚   β”œβ”€β”€ mac.go       # macOS window chrome
β”‚   β”‚   β”œβ”€β”€ windows.go   # Windows window chrome
β”‚   β”‚   β”œβ”€β”€ gnome.go     # GNOME window chrome
β”‚   β”‚   └── utils.go     # Utility functions
β”‚   β”œβ”€β”€ content/         # Content rendering
β”‚   β”‚   β”œβ”€β”€ content.go   # Content interface
β”‚   β”‚   β”œβ”€β”€ code/        # Code rendering
β”‚   β”‚   β”‚   β”œβ”€β”€ code.go      # Code renderer
β”‚   β”‚   β”‚   β”œβ”€β”€ formatter.go # Code formatting
β”‚   β”‚   β”‚   β”œβ”€β”€ redactor.go  # Code redaction
β”‚   β”‚   β”‚   └── themes/      # Syntax themes
β”‚   β”‚   └── term/        # Terminal rendering
β”‚   β”‚       β”œβ”€β”€ term.go      # Terminal renderer
β”‚   β”‚       └── themes/      # Terminal themes
β”‚   β”œβ”€β”€ fonts/           # Font loading and management
β”‚   β”‚   β”œβ”€β”€ fonts.go     # Core font functionality
β”‚   β”‚   β”œβ”€β”€ embedded/    # Embedded fonts
β”‚   β”‚   └── utils.go     # Font utilities
β”‚   β”œβ”€β”€ render/          # Final image composition
β”‚   β”‚   β”œβ”€β”€ canvas.go    # Main rendering canvas
β”‚   β”‚   └── export.go    # Export functionality
β”‚   β”œβ”€β”€ utils/           # Shared utilities
β”‚   └── version/         # Version information
β”œβ”€β”€ go.mod
β”œβ”€β”€ go.sum
└── README.md

Getting Started

  1. Fork the Repository

    • Visit Goshot on GitHub
    • Click the "Fork" button in the top-right corner
    • Clone your fork locally:
      git clone https://github.com/YOUR_USERNAME/goshot.git
      cd goshot
  2. Set Up Development Environment

    • Install Go (1.21 or later)
    • Install required dependencies:
      go mod download
  3. Create a Branch

    • Create a branch for your work:
      git checkout -b feature/your-feature-name
      # or
      git checkout -b fix/your-bug-fix

Development Workflow

  1. Make Your Changes

    • Write clear, concise commit messages
    • Follow the existing code style
    • Add tests for new functionality
    • Update documentation as needed
  2. Test Your Changes

    # Run tests
    go test ./...
    
    # Run linter
    go vet ./...
  3. Submit a Pull Request

    • Push your changes to your fork
    • Create a Pull Request from your branch
    • Fill out the PR template with all relevant information
    • Link any related issues

Coding Guidelines

  1. Code Style

    • Follow standard Go code formatting (go fmt)
    • Use meaningful variable and function names
    • Add comments for complex logic
    • Keep functions focused and concise
  2. Error Handling

    • Return errors instead of panicking
    • Use descriptive error messages
    • Wrap errors with context when appropriate
    if err != nil {
        return fmt.Errorf("failed to render code: %w", err)
    }
  3. Interface Design

    • Keep interfaces small and focused
    • Use the With* pattern for option methods
    • Provide sensible defaults
    type Renderer interface {
        Render() (image.Image, error)
    }
    
    func (r *MyRenderer) WithOption(opt string) *MyRenderer {
        r.option = opt
        return r
    }

Testing Guidelines

  1. Unit Tests

    • Write tests for new functionality
    • Follow table-driven test patterns
    • Use meaningful test names
    func TestRenderer_WithOption(t *testing.T) {
        tests := []struct {
            name     string
            option   string
            expected string
        }{
            {
                name:     "valid option",
                option:   "test",
                expected: "test",
            },
        }
    
        for _, tt := range tests {
            t.Run(tt.name, func(t *testing.T) {
                r := NewRenderer()
                r.WithOption(tt.option)
                if r.option != tt.expected {
                    t.Errorf("got %v, want %v", r.option, tt.expected)
                }
            })
        }
    }
  2. Visual Testing

    • Add example images for visual changes
    • Test with different themes and configurations
    • Consider accessibility in visual designs

Documentation Guidelines

  1. Code Documentation

    • Document all exported types and functions
    • Include examples for complex functionality
    • Keep comments up to date with code changes
  2. Wiki Documentation

    • Update relevant wiki pages
    • Include code examples
    • Add visual examples where appropriate
    • Keep the sidebar up to date
  3. Examples

    • Add examples for new features
    • Update existing examples
    • Include comments explaining the code

Best Practices

  1. Performance

    • Profile code for performance bottlenecks
    • Optimize image operations
    • Reuse objects when possible
    • Close resources properly
  2. Memory Management

    • Be mindful of large image allocations
    • Clean up resources in defer statements
    • Use appropriate buffer sizes
  3. Compatibility

    • Test on different platforms
    • Consider font availability
    • Handle different color spaces
    • Support various image formats

License

This project is licensed under the MIT License - see the LICENSE file for details.