Last active
September 14, 2018 11:43
-
-
Save yn-misaki/8c2b00326fa675d1b1ec9e3c5ab847a3 to your computer and use it in GitHub Desktop.
コミット前に自動でRubocopを実行する(仮想開発環境編) ref: https://qiita.com/yn-misaki/items/adbc9a02be226bc10354
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app/model/query.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bundle exec rubocop -RDa app/model/query.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cd ${workspace_path} && bundle exec rubocop -RDa ${files} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ vim .git/hooks/pre-commit | |
=========================== | |
if [ -e ${vagrant_path} ]; then | |
cd ${vagrant_path} && vagrant ssh -c "cd ${workspace_path} && bundle exec rubocop -RDa ${files}" | |
else | |
bundle exec rubocop -RDa ${files} | |
fi | |
=========================== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cd <Railsプロジェクトのディレクトリ> | |
$ vim .git/hooks/pre-commit | |
=========================== | |
#!/bin/bash | |
vagrant_path="<vagrantのディレクトリ>" | |
workspace_path="<Vagrant上のRailsプロジェクトディレクトリ>" | |
files=`git diff --cached --name-only --diff-filter=AM | grep '.rb$' | tr '\n' ' '` --- (1) | |
# 実行するファイルがなければ、何もしない | |
if [ ! -n "${files}" ]; then | |
exit | |
fi | |
echo 変更があったファイルにrubocopを実行します。 | |
cd ${vagrant_path} && vagrant ssh -c "cd ${workspace_path} && bundle exec rubocop -RDa ${files}" --- (2) | |
echo rubocopの実行が完了しました。 | |
exit $? | |
=========================== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
yn-misaki$ git commit -m ":cop: テスト用" | |
変更があったファイルにrubocopを実行します。 | |
Inspecting 1 file | |
. | |
1 file inspected, no offenses detected | |
rubocopの実行が完了しました。 | |
[rubocop_test 5502ea0] :cop: テスト用 | |
2 files changed, 9 insertions(+), 1 deletion(-) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment