0
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?

More than 1 year has passed since last update.

モノレポ構成でsimple-git-hooksが動作しなかった原因

Last updated at Posted at 2024-08-16

simple-git-hooksを使用してGitフックを設定し、コミット時にLintやフォーマッターを自動で実行する仕組みにしようと思った。
設定したものの、フックが正常に動作しない問題に直面したので記録します。

前提

使用ツール: Git, Yarn, simple-git-hooks, lint-staged
プロジェクト構成: モノレポ構成で、frontとapiディレクトリがあり、frontディレクトリ内にLintやフォーマッターの設定が含まれています。
目的: コミット時にlint-stagedを実行し、コードの自動チェックを行う。

内容

frontディレクトリ内のpackage.jsonに必要な記述を行い、試しにコミットを実行したところ下記のエラー文が。

npm ERR! Missing script: "lint-staged"

結論、プロジェクトルートでsimple-git-hooksをインストールしていなかったことが原因だった。

ディレクトリ構成

project
|-api
|-front
docker-compose.yml

frontディレクトリにsimple-git-hooksをインストールすればいいと思っていたが、ルートで実行されるものなのでルートにインストールする必要があった。
インストール後、無事にコミットが成功しリントチェックも機能していたことを確認できた。

0
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
0
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?