Skip to content

Contributing

Adrian Thomas edited this page Oct 2, 2025 · 6 revisions

Contributing Guidelines

Welcome to symlinkit 2.0! We're excited that you want to contribute. This guide outlines our contribution process, requirements, and how to ensure your contributions meet our quality standards.

MANDATORY REQUIREMENT: ALL CONTRIBUTIONS MUST INCLUDE TESTS

NO PULL REQUESTS WILL BE APPROVED WITHOUT APPROPRIATE TESTS.

This policy ensures symlinkit remains reliable, prevents regressions, and maintains high code quality.


Quick Start for Contributors

  1. Fork the repository
  2. Clone your fork: git clone https://github.com/your-username/symlinkit.git
  3. Create a feature branch: git checkout -b feature/your-feature
  4. Make your changes (include tests!)
  5. Run tests: make test
  6. Run shellcheck: shellcheck scripts/symlinkit scripts/install.sh scripts/uninstall.sh tests/helpers.bash
  7. Commit and push
  8. Open a pull request

Testing Requirements

CRITICAL: All changes must include tests and pass CI/CD validation.

Before Submitting a PR

Run the following commands locally:

# 1. Run shellcheck
shellcheck scripts/symlinkit
shellcheck scripts/install.sh
shellcheck scripts/uninstall.sh
shellcheck tests/helpers.bash

# 2. Run test suite
make test

Both must pass before submitting your PR.

Platform Compatibility

symlinkit 2.0 must work on:

  • Linux (Bash 4+)
  • macOS (Bash 3.2)
  • WSL

Bash 3.2 Compatibility Rules:

  • ❌ NO mapfile / readarray (Bash 4+ only)
  • ❌ NO associative arrays (Bash 4+ only)
  • ❌ NO &>> redirect operator (Bash 4+ only)
  • ✅ USE while read loops instead of mapfile
  • ✅ USE [[ for conditionals
  • ✅ USE >> file 2>&1 for redirects

Types of Contributions

Bug Fixes

Requirements:

  1. Add a test that reproduces the bug
  2. Fix the bug
  3. Verify the test now passes
  4. Ensure all existing tests still pass

Example:

# 1. Add test for bug
print_test "Fix: operation flag required error"
output=$("$SYMLINKIT" ~/source 2>&1 || true)
assert_contains "$output" "No operation specified"

# 2. Fix the bug in symlinkit script
# 3. Verify test passes
./tests/simple_test.sh

New Features

Requirements:

  1. Tests for the new feature
  2. Tests for edge cases
  3. Tests for error conditions
  4. Update documentation (README, wiki, man page)
  5. All existing tests must still pass

Example workflow:

# Add new flag --your-flag
# 1. Implement feature
# 2. Add tests to tests/symlinkit.bats
# 3. Update docs
# 4. Run tests
make test

Refactoring

Requirements:

  1. All existing tests must pass unchanged
  2. If behavior changes, update tests
  3. Verify no regressions

Writing Tests

Test Structure

Tests are written using bats in tests/symlinkit.bats:

@test "Your test description" {
  run run_symlinkit [flags]
  [ "$status" -eq 0 ]
  [[ "$output" =~ "expected string" ]]
}

Test Examples

Testing flag behavior:

@test "Create mode dry-run" {
  run run_symlinkit --dry-run -c "$TMPDIR/source" "$TMPDIR/dest"
  [ "$status" -eq 0 ]
  [[ "$output" =~ "Would" ]]
}

Testing file operations:

@test "Create mode creates symlink" {
  run run_symlinkit -c "$TMPDIR/source/file.txt" "$TMPDIR/dest/link"
  [ "$status" -eq 0 ]
  [ -L "$TMPDIR/dest/link" ]
}

Testing error conditions:

@test "Create fails if destination exists" {
  ln -s "$TMPDIR/source/file.txt" "$TMPDIR/dest/existing"
  run run_symlinkit -c "$TMPDIR/source" "$TMPDIR/dest/existing"
  [ "$status" -ne 0 ]
  [[ "$output" =~ "exists" ]]
}

Test Guidelines

  1. One test, one behavior
  2. Clear test names: Describe what is being tested using @test "description"
  3. Clean up temp files: Handled automatically by bats setup/teardown
  4. Test edge cases: Empty directories, permission errors, etc.
  5. Cross-platform: Avoid platform-specific commands

Code Style

Follow Existing Patterns

symlinkit uses a natural, human-like coding style:

Good practices:

  • Minimal comments (only explain "why", not "what")
  • Mix of verbose and terse naming
  • Pragmatic over perfect
  • Copy-paste and adapt existing patterns

Avoid:

  • Over-commenting obvious code
  • Perfect consistency everywhere
  • Excessive abstractions
  • Maximum descriptiveness

Examples

Good:

validate_dir() {
  [[ -d "$1" ]] && return 0
  echo "Not a directory: $1" >&2
  return 1
}

Too formal (avoid):

# === INPUT VALIDATION ===
# Validates that the provided path is a valid directory
# Args:
#   $1 - The directory path to validate
# Returns:
#   0 if valid, 1 if invalid
validate_directory_path() {
  local directory_path="$1"
  if [[ -d "$directory_path" ]]; then
    return 0
  else
    return 1
  fi
}

Commit Messages

Use clear, concise commit messages:

Format:

type: brief description

Longer explanation if needed.

Types:

  • feat: New feature
  • fix: Bug fix
  • test: Add or update tests
  • docs: Documentation changes
  • refactor: Code refactoring

Examples:

feat: add operation flag requirement validation

test: add test for missing operation flag error

fix: resolve broken symlink detection edge case

docs: update wiki for 2.0 features

Pull Request Process

PR Checklist

Before submitting:

  • Tests added for new functionality
  • All tests pass locally (make test)
  • shellcheck scripts/symlinkit scripts/install.sh scripts/uninstall.sh tests/helpers.bash passes
  • Documentation updated (if needed)
  • Commit messages are clear
  • Branch is up to date with main

PR Template

## Description
Brief description of what this PR does.

## Type of Change
- [ ] Bug fix
- [ ] New feature
- [ ] Refactoring
- [ ] Documentation update

## Testing
- [ ] Added tests for new functionality in tests/symlinkit.bats
- [ ] All tests pass locally (make test)
- [ ] shellcheck passes (scripts/symlinkit, scripts/install.sh, scripts/uninstall.sh, tests/helpers.bash)

## Documentation
- [ ] README updated (if needed)
- [ ] Wiki updated (if needed)
- [ ] Man page updated (if needed)

## Screenshots (if applicable)

Review Process

  1. Automated checks: CI/CD runs on all PRs
  2. Code review: Maintainer reviews code and tests
  3. Feedback: Address any requested changes
  4. Approval: PR is approved
  5. Merge: Maintainer merges PR

Development Environment Setup

Prerequisites

Linux/WSL:

# Install shellcheck
sudo apt install shellcheck  # Debian/Ubuntu
sudo yum install shellcheck  # RHEL/CentOS

macOS:

# Install dependencies
brew install shellcheck coreutils

Testing Your Changes

# 1. Make changes to symlinkit
vim scripts/symlinkit

# 2. Run shellcheck
shellcheck scripts/symlinkit
shellcheck scripts/install.sh
shellcheck scripts/uninstall.sh
shellcheck tests/helpers.bash

# 3. Add/update tests
vim tests/symlinkit.bats

# 4. Run tests
make test

Common Pitfalls

1. Forgetting Tests

❌ Wrong:

# Make code changes
# Submit PR without tests

✅ Right:

# Make code changes
# Add tests
# Verify tests pass
# Submit PR

2. Using Bash 4+ Features

❌ Wrong (breaks macOS):

mapfile -t items < <(find . -type l)

✅ Right (works on all platforms):

items=()
while IFS= read -r line; do
  [[ -n "$line" ]] && items+=("$line")
done < <(find . -type l)

3. Not Running Tests Before Push

❌ Wrong:

# Make changes
# Push without testing
# CI fails

✅ Right:

# Run shellcheck
shellcheck scripts/symlinkit scripts/install.sh scripts/uninstall.sh tests/helpers.bash

# Run tests
make test

# Only push if tests pass

Questions or Issues?


License

By contributing, you agree that your contributions will be licensed under the MIT License.


Thank You!

Thank you for contributing to symlinkit 2.0! Your contributions help make symlink management better for everyone.

For more information, see:

Symlinkit Wiki Navigation

Getting Started

Features & Functionality

Development & Contributing

Clone this wiki locally