You may fancy me mad, but this is my standard python pre-commit stack: end-of-file-fixer trailing-whitespace fix-byte-order-marker mixed-line-ending name-tests-test no-commit-to-branch autoflake args: [ "--in-place", "--remove-unused-variables", "--remove-all-unused-imports" ] isort black cspell doc8 args: [ "--max-line-length", "112", "--file-encoding", "utf-8" ] flake8 additional_dependencies: [ flake8-pytest-style, flake8-bugbear, flake8-comprehensions, flake8-print, darglint ] bandit pylint Answer from Grintor on reddit.com
GitHub
github.com › astral-sh › ruff-pre-commit
GitHub - astral-sh/ruff-pre-commit: A pre-commit hook for Ruff. · GitHub
{ id = "ruff-format", types_or = ["python", "pyi"] }, ] See the section above on pre-commit for guidance on hook order when using --fix.
Starred by 1.9K users
Forked by 99 users
Languages Python
Astral
docs.astral.sh › ruff › integrations
Integrations | Ruff
.base_ruff: stage: build interruptible: .../code-quality-report.json Ruff Format: extends: .base_ruff script: - ruff format --diff · Ruff can be used as a pre-commit hook via ruff-pre-commit:...
What are your favourite pre-commit hooks and why?
You may fancy me mad, but this is my standard python pre-commit stack: end-of-file-fixer trailing-whitespace fix-byte-order-marker mixed-line-ending name-tests-test no-commit-to-branch autoflake args: [ "--in-place", "--remove-unused-variables", "--remove-all-unused-imports" ] isort black cspell doc8 args: [ "--max-line-length", "112", "--file-encoding", "utf-8" ] flake8 additional_dependencies: [ flake8-pytest-style, flake8-bugbear, flake8-comprehensions, flake8-print, darglint ] bandit pylint More on reddit.com
python - Different results from Ruff between CLI and pre-commit hook - Stack Overflow
I've set up a pre-commit hook for using Ruff to handle linting in my project. I've configured the hook as per the documentation: - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.4.9 ... More on stackoverflow.com
How to use Ruff?
You run it separately until you develop a set of rules you are comfortable with it enforcing, and a subset you are comfortable with it fixing. Given that any decent IDE will integrate it, I would assume it's very rare that any developer ever runs it manually. More on reddit.com
Migrating from black and flake8 to ruff
The problem with pre-commit hooks like this is that they don’t sync with your project dependencies and can go out of date easily. What I’ve done at my company is run bash invocations in the precommit hooks of pyinvoke tasks that call whatever formatting or linting libraries we have defined in our dev dependencies. As for ruff, I would try to pin the version to whatever is closest to the behavior of black and flake8 that was used on your repo. If it were me though I would just push for updating to the latest version and accepting whatever formatting and linting changes arise from that. More on reddit.com
Videos
35:47
Python Tutorial: Ruff - A Fast Linter & Formatter to Replace Multiple ...
04:45
Boost Your Python Code Quality: Pre-commit Tutorial (UV & Ruff) ...
04:52
How to Run a Python Script Upon Commit Using a Pre-Commit Hook ...
Increase Python code quality with pre-commit
09:20
Python Pre-Commit Hooks Setup in a single video! - YouTube
Reddit
reddit.com › r/python › what are your favourite pre-commit hooks and why?
r/Python on Reddit: What are your favourite pre-commit hooks and why?
April 24, 2024 -
Just getting started with pre-commit and I think it's awesome. Looking to find out what other code automation tools people are using. Let me know what works for you and why. Thanks!
Top answer 1 of 24
65
black Particularly useful on projects with multiple collaborators because everyone’s code will be formatted identically.
2 of 24
53
You may fancy me mad, but this is my standard python pre-commit stack: end-of-file-fixer trailing-whitespace fix-byte-order-marker mixed-line-ending name-tests-test no-commit-to-branch autoflake args: [ "--in-place", "--remove-unused-variables", "--remove-all-unused-imports" ] isort black cspell doc8 args: [ "--max-line-length", "112", "--file-encoding", "utf-8" ] flake8 additional_dependencies: [ flake8-pytest-style, flake8-bugbear, flake8-comprehensions, flake8-print, darglint ] bandit pylint
PyPI
pypi.org › project › ruff › 0.0.191
ruff · PyPI
This is useful for pre-commit, which explicitly passes all changed files to the ruff-pre-commit plugin, regardless of whether they're marked as excluded by Ruff's own settings. ... The style in which violation messages should be formatted: "text" (default), "grouped" (group messages by file), "json" (machine-readable), "junit" (machine-readable XML), or "github" (GitHub Actions annotations).
» pip install ruff
Published Dec 22, 2022
Version 0.0.191
Directed Ignorance
directedignorance.com › blog › ruff-sorting-imports-with-pre-commit
Ruff: Sorting Imports With pre-commit - Directed Ignorance
May 13, 2024 - After some searching, I found that you could sort the imports with ruff as follows [1]: ... Looks good! I’d have liked to have one command instead of two, and it would have been nice if I didn’t need to run check with a specific rule selected, but hey, this is still pretty easy to do. The only thing left was to figure out how to cajole it to a pre-commit hook.
GitHub
github.com › astral-sh › ruff-pre-commit › blob › main › README.md
ruff-pre-commit/README.md at main · astral-sh/ruff-pre-commit
{ id = "ruff-format", types_or = ["python", "pyi"] }, ] See the section above on pre-commit for guidance on hook order when using --fix.
Author astral-sh
GitHub
github.com › astral-sh › ruff › blob › main › .pre-commit-config.yaml
ruff/.pre-commit-config.yaml at main · astral-sh/ruff
March 17, 2026 - language: python # means renovate will also update `additional_dependencies` additional_dependencies: - mdformat-mkdocs==5.1.4 · - mdformat-footnote==0.1.3 · exclude: | (?x)^( docs/formatter/black\.md · | docs/\w+\.md · )$ priority: 0 · · - repo: https://github.com/astral-sh/ruff-pre-commit ·
Author astral-sh
GitHub
github.com › astral-sh › ruff
GitHub - astral-sh/ruff: An extremely fast Python linter and code formatter, written in Rust. · GitHub
March 14, 2026 - - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. rev: v0.15.12 hooks: # Run the linter. - id: ruff-check args: [ --fix ] # Run the formatter.
Starred by 47.4K users
Forked by 2K users
Languages Rust 96.5% | Python 2.6% | TypeScript 0.8% | Shell 0.1% | CSS 0.0% | HTML 0.0%
Stack Overflow
stackoverflow.com › questions › 78637149 › different-results-between-cli-and-pre-commit
python - Different results from Ruff between CLI and pre-commit hook - Stack Overflow
- repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.4.9 hooks: - id: ruff args: [ --fix ] - id: ruff-format
Ukaea
ukaea.github.io › PROCESS › development › pre-commit
Pre-commit - PROCESS
Although not required, the ruff VSCode extension will ensure that all the Python files you save will be ruff-compliant and, as such, won't need to modified by pre-commit. Open or create the file .vscode/settings.json and add/modify the following settings:
Astral
docs.astral.sh › ruff › tutorial
Tutorial | Ruff
This tutorial has focused on Ruff's command-line interface, but Ruff can also be used as a pre-commit hook via ruff-pre-commit:
GitHub
github.com › charliermarsh › ruff-pre-commit › blob › main › .pre-commit-hooks.yaml
ruff-pre-commit/.pre-commit-hooks.yaml at main · astral-sh/ruff-pre-commit
types_or: [python, pyi, jupyter] args: [] require_serial: true · additional_dependencies: [] minimum_pre_commit_version: "2.9.2" · # Legacy alias · - id: ruff · name: ruff (legacy alias) description: "Run 'ruff check' for extremely fast Python linting" entry: ruff check --force-exclude ·
Author astral-sh
Hotosm
docs.hotosm.org › dev-guide › repo-management › pre-commit
Pre-Commit - HOTOSM Docs
repos: # Versioning: Commit messages ... Python code - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. rev: "v0.5.4" hooks: # Run the linter - id: ruff args: [--fix, --exit-non-zero-on-fix] # Run the formatter - id: ruff-format # Autoformat: YAML, JSON, Markdown, ...
Medium
medium.com › @gnetkov › automating-code-quality-control-with-pre-commit-hooks-fdbc1ec5cfea
Automating Code Quality Control with Pre-commit Hooks | by Fedor GNETKOV | Medium
January 1, 2025 - We have created a project with fully configured pre-commit hooks that check code quality and run tests for both the backend and frontend. This project can be used with any Python framework (Django, Flask, FastAPI) and JavaScript/TypeScript frameworks (ReactJS, VueJS, Angular, Svelte). You may need to make minor adjustments to the configuration to suit your specific needs. Additionally, you can modify and fine-tune the configurations for Ruff...
Reddit
reddit.com › r/learnpython › how to use ruff?
r/learnpython on Reddit: How to use Ruff?
February 11, 2026 -
I'm mainly just a hobby programmer but I'm trying to up my CI/CD game. I'm comfortable with mypy and pytest and I'm now looking to integrate ruff. Obviously I know how to launch it, but I'm confused about how its used in practice.
For example, running as:
ruff check ruff format --check
And then manually addressing objections? Or, do you just let ruff make its changes:
ruff check --fix ruff format
...or something else entirely? Thanks.
Top answer 1 of 5
3
You run it separately until you develop a set of rules you are comfortable with it enforcing, and a subset you are comfortable with it fixing. Given that any decent IDE will integrate it, I would assume it's very rare that any developer ever runs it manually.
2 of 5
2
I would just have it fail your pipelines for now. Then later on as you get comfortable with it, you can let it do its thing automatically.
Scientific Python Development
learn.scientific-python.org › development › guides › style
Style & static checks - Scientific Python Development Guide
Ruff, the powerful Rust-based linter, has a formatter that is designed with the help of some of the Black authors to look 99.9% like Black, but run 30x faster. Here is the snippet to add the formatter to your .pre-commit-config.yml (combine with the Ruff linter below):
Stefanie Molin
stefaniemolin.com › articles › devx › pre-commit › setup-guide
How to Set Up Pre-Commit Hooks | Stefanie Molin
December 7, 2025 - In order to have consistent configuration across our CI workflow, pre-commit hooks, and in-editor checks/extensions, we must use a configuration file instead of args. Let’s go ahead and add the following to our pyproject.toml file. This will configure the ruff, ruff-format, and numpydoc-validation hooks.