diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..6df3916 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,34 @@ +# Pre-commit hooks configuration +# See https://pre-commit.com for more information + +repos: + # General file checks + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-toml + - id: check-merge-conflict + - id: check-added-large-files + args: ['--maxkb=1000'] + - id: mixed-line-ending + + # Rust formatting + - repo: https://github.com/doublify/pre-commit-rust + rev: v1.0 + hooks: + - id: fmt + name: cargo fmt + description: Format Rust code with rustfmt + - id: cargo-check + name: cargo check + description: Check Rust code compilation + - id: clippy + name: cargo clippy + description: Lint Rust code with clippy + args: ['--all-features', '--', '-D', 'warnings'] + +# Optional: run on all files when config changes +default_install_hook_types: [pre-commit, pre-push] diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fe12a3e..d9e4975 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -32,15 +32,14 @@ Unsure where to begin contributing to Owlen? You can start by looking through `g The process for submitting a pull request is as follows: 1. **Fork the repository** and create your branch from `main`. -2. **Make your changes.** -3. **Ensure the code lints and formats correctly.** - - `cargo fmt --all` - - `cargo clippy --all -- -D warnings` +2. **Set up pre-commit hooks** (see [Development Setup](#development-setup) above). This will automatically format and lint your code. +3. **Make your changes.** 4. **Run the tests.** - `cargo test --all` -5. **Add a clear, concise commit message.** We follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) specification. -6. **Push to your fork** and submit a pull request to Owlen's `main` branch. -7. **Include a clear description** of the problem and solution. Include the relevant issue number if applicable. +5. **Commit your changes.** The pre-commit hooks will automatically run `cargo fmt`, `cargo check`, and `cargo clippy`. If you need to bypass the hooks (not recommended), use `git commit --no-verify`. +6. **Add a clear, concise commit message.** We follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) specification. +7. **Push to your fork** and submit a pull request to Owlen's `main` branch. +8. **Include a clear description** of the problem and solution. Include the relevant issue number if applicable. ## Development Setup @@ -52,6 +51,46 @@ cd owlen cargo build ``` +### Pre-commit Hooks + +We use [pre-commit](https://pre-commit.com/) to automatically run formatting and linting checks before each commit. This helps maintain code quality and consistency. + +**Install pre-commit:** + +```sh +# Arch Linux +sudo pacman -S pre-commit + +# Other Linux/macOS +pip install pre-commit + +# Verify installation +pre-commit --version +``` + +**Setup the hooks:** + +```sh +cd owlen +pre-commit install +``` + +Once installed, the hooks will automatically run on every commit. You can also run them manually: + +```sh +# Run on all files +pre-commit run --all-files + +# Run on staged files only +pre-commit run +``` + +The pre-commit hooks will check: +- Code formatting (`cargo fmt`) +- Compilation (`cargo check`) +- Linting (`cargo clippy --all-features`) +- General file hygiene (trailing whitespace, EOF newlines, etc.) + ## Coding Style - We use `cargo fmt` for automated code formatting. Please run it before committing your changes.