Skip to content

Commit

Permalink
Ruff documentation (scikit-bio#1932)
Browse files Browse the repository at this point in the history
* DOC: Add documentation for utilizing Ruff via pre-commit hooks

* DEV: Removed --fix option from Ruff's lint pre-commit hook

* DOC: Add space before code block and correct code type to bash
  • Loading branch information
mataton authored Feb 7, 2024
1 parent b2eccb8 commit 1a06277
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
33 changes: 33 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,36 @@ Getting help with git
---------------------

If you're new to GitHub, you'll probably find the [GitHub Docs](https://docs.github.com/) helpful.

Automating code quality: integrating Ruff's autoformatter and linter with pre-commit hooks
------------------------------------------------------------------------------------------

[Ruff](https://github.com/astral-sh/ruff) is a valuable autoformatter and linter tool that ensures code consistency and quality. Integrating Ruff with [pre-commit](https://pre-commit.com/) hooks empowers developers to automatically format and lint their code before each commit, promoting adherence to project standards and best practices.

### "Installation"

In your development environment, install Ruff and pre-commit using:

```bash
conda install -c conda-forge --file ci/requirements.lint.txt
```

Alternatively, install both packages individually.

```bash
conda install -c conda-forge ruff pre-commit
```

### "Initialize pre-commit hooks"

Scikit-bio streamlines the installation process by including Ruff's linter and formatter via Astral's [ruff-pre-commit](https://github.com/astral-sh/ruff-pre-commit), referenced in the `.pre-commit-config.yaml` file. Activate the pre-commit hooks with the following command:

```bash
pre-commit install
```

Once installed, the pre-commit hooks will automatically execute every time you commit changes. By default, they enforce Ruff's formatter and linter rules, ensuring code consistency and adherence to standards.

### "Make necessary changes and commit"

After the hooks have executed, address any errors flagged by Ruff. Once resolved, you can proceed to commit and push your changes to your branch as usual.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ repos:
hooks:
# Run the linter with the fix option enabled.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format

0 comments on commit 1a06277

Please sign in to comment.