> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coderabbit.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Ruff

> CodeRabbit runs Ruff to find issues in Python code and Jupyter Notebooks.

[Ruff](https://docs.astral.sh/ruff/) is a linter for Python and Jupyter Notebooks. CodeRabbit runs Ruff version 0.16.7.

## Files

Ruff will run on files with the following extensions:

* `.py`
* `.ipynb` (using nbQA)

## Configuration

Ruff is enabled by default. Enable or disable it with `.coderabbit.yaml` or the CodeRabbit web UI:

<Tabs>
  <Tab title=".coderabbit.yaml">
    ```yaml .coderabbit.yaml theme={null}
    reviews:
      tools:
        ruff:
          enabled: true
          config_file: "pyproject.toml"
    ```
  </Tab>

  <Tab title="Web UI">
    Go to **Reviews → Tools → Ruff** in your organization or repository settings to toggle Ruff `on` or `off` and set **Config File**.
  </Tab>
</Tabs>

Ruff supports the following configuration option:

* `config_file` (default: unset): Optional path to a Ruff configuration file relative to the repository. When set, CodeRabbit uses this configuration for every reviewed Python or notebook file instead of Ruff's closest-config discovery. URLs, absolute paths, paths containing `..`, and paths that do not exist are rejected, and CodeRabbit skips Ruff for the review.

Ruff supports the following config files:

* `pyproject.toml`
* `ruff.toml`
* `.ruff.toml`

When `config_file` is unset, Ruff finds the closest applicable configuration for each reviewed file by searching its directory hierarchy. If no repository configuration applies, CodeRabbit uses an isolated fallback configuration based on the selected review profile.

Ruff runs inside the CodeRabbit sandbox. Repository configuration is parsed there by Ruff; CodeRabbit does not load user-provided plugins or Python init hooks.

## When we skip Ruff

CodeRabbit will skip running Ruff when:

* Ruff is already running in GitHub Actions, GitLab CI, CircleCI, or Azure Pipelines.

## Ignored codes

The following Ruff codes are automatically ignored:

* `I001` - unsorted imports
* `F401` - unused imports
* `F405` - undefined name from star import
* `W291` - trailing whitespace
* `W293` - blank line contains whitespace
* `Q000` - bad quotes
* `ANN001` - missing type annotation
* `ANN201` - missing return type annotation
* `UP006` - deprecated type alias
* `UP045` - deprecated import
* `E501` - line too long
* `S101` - use of assert detected
* `EXE001` - Shebang is present but file is not executable
* `RUF100` - unused `noqa` directive
* `PT009` - pytest unittest assertion
* `LOG015` - root logger call
* `PLR2004` - magic-value-comparison
* `PLR0913` - too-many-arguments
* `PLR0917` - too-many-positional-arguments
* `F841` - unused-variable
* `F811` - redefinition-of-unused-name
* `PIE794` - duplicate class field definition

When CodeRabbit generates a fallback configuration, it also ignores `E402` in `__init__.py` and `conftest.py` files.

## Profile behavior

These rule selections apply to CodeRabbit's generated fallback configuration. A repository configuration or an explicit `config_file` supplies its own rule selections; CodeRabbit still filters the [ignored codes](#ignored-codes) from review comments.

In **Chill** mode, Ruff uses a focused set of rule codes including Pyflakes (F), flake8-bugbear (B), flake8-bandit (S), flake8-blind-except (BLE), flake8-debugger (T10), flake8-executable (EXE), Ruff-specific bug rules (RUF), Pylint error checks (PLE), flake8-builtins (A), and selected pycodestyle checks.

In **Assertive** mode, Ruff additionally enables:

* `ANN` - flake8-annotations (type annotations)
* `ASYNC` - flake8-async (async/await issues)
* `FBT` - flake8-boolean-trap
* `C4` - flake8-comprehensions
* `DTZ` - flake8-datetimez (timezone issues)
* `DJ` - flake8-django
* `ISC` - flake8-implicit-str-concat
* `LOG` - flake8-logging
* `G` - flake8-logging-format
* `PIE` - flake8-pie
* `PT` - flake8-pytest-style
* `FLY` - flynt (f-string opportunities)
* `UP` - pyupgrade (upgrade opportunities)
* `PLR` - Pylint refactor checks
* `SIM` - flake8-simplify
* `PERF` - perflint
* `RET` - flake8-return
* `ARG` - flake8-unused-arguments
* `TRY` - tryceratops
* `PLW` - Pylint warning checks

## Links

* [Ruff Configuration](https://docs.astral.sh/ruff/configuration/)
* [nbQA Documentation](https://github.com/nbQA-dev/nbQA)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.