Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Add lefhook git hooks manager to run rubocop on precommit

Christophe Bliard5951cf3e5fc8
diff --git a/.gitignore b/.gitignore
index 0268d401bef..902ce45be02 100644
--- a/.gitignore
+++ b/.gitignore
@@ -118,3 +118,6 @@ structure.sql
# Local development direnv files
/.envrc
/.direnv
+
+# lefthook.yml user override
+lefthook-local.yml
diff --git a/Gemfile b/Gemfile
index 8c7a4947c00..c8ba282773e 100644
--- a/Gemfile
+++ b/Gemfile
@@ -279,6 +279,9 @@ group :development, :test do
gem 'pry-rescue', '~> 1.5.2'
gem 'pry-stack_explorer', '~> 0.6.0'
+ # git hooks manager
+ gem 'lefthook'
+
# Brakeman scanner
gem 'brakeman', '~> 5.2.0'
gem 'danger-brakeman'
diff --git a/Gemfile.lock b/Gemfile.lock
index 22da2877ebd..0e098ceda49 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -574,6 +574,7 @@ GEM
open4 (~> 1.0)
launchy (2.5.0)
addressable (~> 2.7)
+ lefthook (0.7.7)
letter_opener (1.7.0)
launchy (~> 2.2)
listen (3.7.1)
@@ -1029,6 +1030,7 @@ DEPENDENCIES
json_spec (~> 1.1.4)
ladle
launchy (~> 2.5.0)
+ lefthook
letter_opener
listen (~> 3.7.0)
livingstyleguide (~> 2.1.0)
diff --git a/lefthook.yml b/lefthook.yml
new file mode 100644
index 00000000000..8fde47c590c
--- /dev/null
+++ b/lefthook.yml
@@ -0,0 +1,14 @@
+# Lefthook configuration
+#
+# Add commit hooks with `lefthook install`
+#
+# Refer for explanation to following link:
+# https://github.com/evilmartians/lefthook/blob/master/docs/full_guide.md
+
+pre-commit:
+ parallel: true
+ commands:
+ rubocop:
+ files: git diff --name-only --staged
+ glob: "*.rb"
+ run: bundle exec rubocop --force-exclusion {files}