Thank you for your interest in contributing to ColorKit! This document outlines our coding standards and guidelines to help maintain consistency across the codebase.
- Write clear, self-documenting code
- Follow Swift's official style guide
- Keep functions focused and single-purpose
- Use meaningful variable and function names
- Add comments for complex logic or non-obvious decisions
- Keep the code DRY (Don't Repeat Yourself)
- Use PascalCase for types (structs, classes, enums, protocols)
- Use camelCase for properties, methods, and variables
- Use UPPER_SNAKE_CASE for constants
- Prefix boolean properties with verbs (is, has, should, etc.)
- Use descriptive names that indicate purpose rather than type
// Good
struct ColorPalette {
let primaryColor: Color
let secondaryColors: [Color]
var isEnabled: Bool
}
// Avoid
struct Colors {
let color: Color
let colors: [Color]
var enabled: Bool
}- Group related properties and methods together
- Use MARK comments to organize code sections
- Keep files focused and under 500 lines when possible
- Use extensions to organize protocol conformance
- Place private properties and methods at the bottom of the type
struct ColorKit {
// MARK: - Public Properties
// MARK: - Private Properties
// MARK: - Initialization
// MARK: - Public Methods
// MARK: - Private Methods
}We use SwiftLint to enforce code style. Here are some key rules and their rationale:
force_unwrapping: Avoid force unwrapping (!) - use optional binding or nil coalescingforce_cast: Avoid force casting (as!) - use optional casting (as?)trailing_whitespace: Keep files clean of trailing whitespacesorted_imports: Keep imports organized alphabeticallyvertical_whitespace_closing_braces: Maintain consistent spacing
line_length: We allow longer lines (up to 120 characters) for better readabilitytype_body_length: Complex types may need more than 400 linesfunction_body_length: Some functions may need more than 100 linescyclomatic_complexity: We trust developers to keep complexity reasonable
- Document public APIs using Swift-style documentation comments
- Include parameter descriptions and return value information
- Add examples for complex functionality
- Keep documentation up to date with code changes
/// Creates a new color with the specified RGB components.
///
/// - Parameters:
/// - red: The red component (0-255)
/// - green: The green component (0-255)
/// - blue: The blue component (0-255)
///
/// - Returns: A new Color instance
///
/// - Example:
/// ```
/// let red = Color(r: 255, g: 0, b: 0)
/// ```
func color(r: UInt8, g: UInt8, b: UInt8) -> Color- Write unit tests for new functionality
- Follow the Arrange-Act-Assert pattern in tests
- Use descriptive test names that explain the scenario
- Keep tests focused and independent
- Use appropriate test doubles (mocks, stubs) when needed
func testColorInitialization() {
// Arrange
let red: UInt8 = 255
let green: UInt8 = 0
let blue: UInt8 = 0
// Act
let color = Color(r: red, g: green, b: blue)
// Assert
XCTAssertEqual(color.red, red)
XCTAssertEqual(color.green, green)
XCTAssertEqual(color.blue, blue)
}- Write clear, descriptive commit messages
- Keep commits focused and atomic
- Use feature branches for new work
- Update documentation when making API changes
- Follow the existing PR review process
- Fork the repository
- Create a feature branch
- Make your changes following these guidelines
- Run SwiftLint locally to check for style issues
- Write or update tests as needed
- Submit a pull request
If you have any questions about these guidelines or need clarification, please open an issue or reach out to the maintainers.