Skip to content
프로젝트

소개

Ruff용 pre-commit 훅입니다.

개발 도구

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
+3
in 15 days
+3
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

ruff-pre-commit

Ruff image image image Actions status

A pre-commit hook for Ruff.

Distributed as a standalone repository to enable installing Ruff via prebuilt wheels from PyPI.

Using Ruff with pre-commit

To run Ruff's linter and formatter (available as of Ruff v0.0.289) via pre-commit, add the following to your .pre-commit-config.yaml:

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
  # Ruff version.
  rev: v0.17.4
  hooks:
    # Run the linter.
    - id: ruff-check
    # Run the formatter.
    - id: ruff-format

By default, the format hook also formats Python code blocks in Markdown files.

To enable lint fixes, add the --fix argument to the lint hook:

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
  # Ruff version.
  rev: v0.17.4
  hooks:
    # Run the linter.
    - id: ruff-check
      args: [ --fix ]
    # Run the formatter.
    - id: ruff-format

To select or ignore specific rules, pass the relevant Ruff arguments through args. When using inline YAML lists, quote arguments that contain commas:

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
  # Ruff version.
  rev: v0.17.4
  hooks:
    # Run the linter.
    - id: ruff-check
      args: [ --fix, "--extend-select=I,E", "--ignore=F401" ]

To avoid running on Jupyter Notebooks, remove jupyter from the list of allowed filetypes:

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
  # Ruff version.
  rev: v0.17.4
  hooks:
    # Run the linter.
    - id: ruff-check
      types_or: [ python, pyi ]
      args: [ --fix ]
    # Run the formatter.
    - id: ruff-format
      types_or: [ python, pyi, markdown ]

To lint pyproject.toml, add pyproject to the list of allowed filetypes (requires identify>=2.6.18):

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
  # Ruff version.
  rev: v0.17.4
  hooks:
    # Run the linter.
    - id: ruff-check
      types_or: [ python, pyi, jupyter, pyproject ]
      args: [ --fix ]
    # Run the formatter.
    - id: ruff-format

To format Python code blocks in Quarto documents that use the .qmd extension, configure Ruff to map the qmd extension to the markdown file type, and add quarto to the list of allowed file types in your .pre-commit-config.yaml configuration (requires identify>=2.6.20):

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
  # Ruff version.
  rev: v0.17.4
  hooks:
    # Run the formatter.
    - id: ruff-format
      types_or: [ python, pyi, jupyter, markdown, quarto ]

When running with --fix, Ruff's lint hook should be placed before Ruff's formatter hook, and before Black, isort, and other formatting tools, as Ruff's fix behavior can output code changes that require reformatting.

When running without --fix, Ruff's formatter hook can be placed before or after Ruff's lint hook.

(As long as your Ruff configuration avoids any linter-formatter incompatibilities, ruff format should never introduce new lint errors, so it's safe to run Ruff's format hook after ruff check --fix.)

Using Ruff with prek

If you prefer using prek instead of pre-commit, you can define a prek.toml file with your hooks. Here's an example equivalent to the .pre-commit-config.yaml configuration:

[[repos]]
repo = "https://github.com/astral-sh/ruff-pre-commit"
rev = "v0.17.4" # Ruff version.
hooks = [
  # Run the linter.
  { id = "ruff-check", args = ["--fix"], types_or = ["python", "pyi"] },

  # Run the formatter.
  { id = "ruff-format", types_or = ["python", "pyi", "markdown"] },
]

See the section above on pre-commit for guidance on hook order when using --fix.

License

ruff-pre-commit is licensed under either of

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in ruff-pre-commit by you, as defined in the Apache-2.0 license, shall be dually licensed as above, without any additional terms or conditions.

관련 프로젝트 살펴보기

불러오는 중…