1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ruffにフォーマットされていないコードがコミットされるのを防ぎます。

pre-commit とは

pre-commit は GitHook スクリプトをコミット前に実行します。

以下のようなイメージである。
ステージング -> pre-commit -(コーディング規約を遵守していれば)-> コミット

ruff, pre-commitを追加する。

$ rye add -d pre-commit ruff
$ rye sync

pre-commit用の設定ファイルを作成します。

~\.pre-commit-config.yamlの例

repos:
  - repo: https://github.com/astral-sh/ruff-pre-commit
    # Ruff version.
    rev: v0.1.4
    hooks:
      # Run the Ruff linter.
      - id: ruff
        exclude: "(__init__\\.py|migrations/)"
      # Run the Ruff formatter.
      - id: ruff-format
        exclude: "(__init__\\.py|migrations/)"

__init__.pymigrations系のファイル群を例外に設定しています。

設定ファイルを適用します。

pre-commit install

これでフォーマッタが実行されていないコードのコミットは防げます。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?