Skip to content

A platform for community discussion. Free, open, simple.

DEV: Replace Overcommit with Lefthook (#7826)

Abroskin Alexander0872a1182d57
diff --git a/.overcommit.yml b/.overcommit.yml
deleted file mode 100644
index 8a48ff500ee..00000000000
--- a/.overcommit.yml
+++ /dev/null
@@ -1,45 +0,0 @@
-# Use this file to configure the Overcommit hooks you wish to use. This will
-# extend the default configuration defined in:
-# https://github.com/brigade/overcommit/blob/master/config/default.yml
-#
-# At the topmost level of this YAML file is a key representing type of hook
-# being run (e.g. pre-commit, commit-msg, etc.). Within each type you can
-# customize each hook, such as whether to only run it on certain files (via
-# `include`), whether to only display output if it fails (via `quiet`), etc.
-#
-# For a complete list of hooks, see:
-# https://github.com/brigade/overcommit/tree/master/lib/overcommit/hook
-#
-# For a complete list of options that you can use to customize hooks, see:
-# https://github.com/brigade/overcommit#configuration
-
-PreCommit:
- RuboCop:
- enabled: true
- command: ['bundle', 'exec', 'rubocop']
- EsLint:
- enabled: true
- required_executable: './node_modules/.bin/eslint'
- install_command: 'yarn install'
- command: ['yarn', 'eslint', '--ext', '.es6', '-f', 'compact']
- include: '**/*.es6'
- YamlSyntax:
- enabled: true
-
-PostCheckout:
- BundleInstall:
- enabled: true
- YarnInstall:
- enabled: true
-
-PostMerge:
- BundleInstall:
- enabled: true
- YarnInstall:
- enabled: true
-
-PostRewrite:
- BundleInstall:
- enabled: true
- YarnInstall:
- enabled: true
diff --git a/.travis.yml b/.travis.yml
index f8bc50b5016..16534a38cf7 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -74,13 +74,7 @@ script:
- |
bash -c "
if [ '$RUN_LINT' == '1' ]; then
- bundle exec rubocop --parallel && \
- yarn prettier --list-different "app/assets/stylesheets/**/*.scss" "app/assets/javascripts/**/*.es6" "test/javascripts/**/*.es6"
- yarn eslint --ext .es6 app/assets/javascripts && \
- yarn eslint --ext .es6 test/javascripts && \
- yarn eslint --ext .es6 plugins/**/assets/javascripts && \
- yarn eslint --ext .es6 plugins/**/test/javascripts && \
- yarn eslint app/assets/javascripts test/javascripts
+ npx lefthook run lints
else
if [ '$QUNIT_RUN' == '1' ]; then
bundle exec rake qunit:test['1200000'] && \
diff --git a/Gemfile b/Gemfile
index 87a682b5758..172970aa1cc 100644
--- a/Gemfile
+++ b/Gemfile
@@ -152,6 +152,7 @@ group :development do
gem 'bullet', require: !!ENV['BULLET']
gem 'better_errors'
gem 'binding_of_caller'
+ gem 'yaml-lint'
# waiting on 2.7.5 per: https://github.com/ctran/annotate_models/pull/595
if rails_master?
diff --git a/Gemfile.lock b/Gemfile.lock
index 18ba21d178c..46f9119c006 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -412,6 +412,7 @@ GEM
webpush (0.3.8)
hkdf (~> 0.2)
jwt (~> 2.0)
+ yaml-lint (0.0.10)
PLATFORMS
ruby
@@ -533,6 +534,7 @@ DEPENDENCIES
unicorn
webmock
webpush
+ yaml-lint
BUNDLED WITH
1.17.3
diff --git a/lefthook.yml b/lefthook.yml
new file mode 100644
index 00000000000..d085046ad6c
--- /dev/null
+++ b/lefthook.yml
@@ -0,0 +1,49 @@
+pre-commit:
+ parallel: true
+ commands:
+ rubocop:
+ glob: '*.rb'
+ run: bundle exec rubocop {staged_files}
+ eslint:
+ glob: '*.{js,es6}'
+ run: yarn eslint --ext .es6 -f compact {staged_files}
+ yaml-syntax:
+ glob: '*.{yaml,yml}'
+ run: bundle exec yaml-lint {staged_files}
+
+commands: &commands
+ bundle-install:
+ files: git diff --name-only HEAD master
+ glob: '{Gemfile,Gemfile.lock,*.gemspec}'
+ run: bundle install
+ yarn-install:
+ files: git diff --name-only HEAD master
+ glob: '{package.json,yarn.lock}'
+ run: yarn install
+
+post-checkout:
+ commands: *commands
+
+post-merge:
+ commands: *commands
+
+post-rewrite:
+ commands: *commands
+
+lints:
+ parallel: true
+ commands:
+ rubocop:
+ run: bundle exec rubocop --parallel
+ prettier:
+ run: yarn prettier --list-different app/assets/stylesheets/**/*.scss app/assets/javascripts/**/*.es6 test/javascripts/**/*.es6
+ eslint-assets:
+ run: yarn eslint --ext .es6 app/assets/javascripts
+ eslint-test:
+ run: yarn eslint --ext .es6 test/javascripts
+ eslint-plugins-assets:
+ run: yarn eslint --ext .es6 plugins/**/assets/javascripts
+ eslint-plugins-test:
+ run: yarn eslint --ext .es6 plugins/**/test/javascripts
+ eslint-assets-tests:
+ run: yarn eslint app/assets/javascripts test/javascripts
diff --git a/package.json b/package.json
index d49c13b29c5..cf64652a7ea 100644
--- a/package.json
+++ b/package.json
@@ -33,6 +33,7 @@
"spectrum-colorpicker": "1.8.0"
},
"devDependencies": {
+ "@arkweid/lefthook": "^0.5.6",
"babel-eslint": "^8.2",
"chrome-launcher": "^0.10",
"chrome-remote-interface": "^0.25",
diff --git a/yarn.lock b/yarn.lock
index 8180e843dcc..f5a6887babe 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2,6 +2,11 @@
# yarn lockfile v1
+"@arkweid/lefthook@^0.5.6":
+ version "0.5.6"
+ resolved "https://registry.yarnpkg.com/@arkweid/lefthook/-/lefthook-0.5.6.tgz#6c44bc257c2ea2c2498c25df1757fd224a69a088"
+ integrity sha512-hnzXNq/tq7LZGOFE1CigEdSOd1lkhJpUX83pyseIQg7hzrwytnm3+qVLqnMAY/Zk/L7kvWVLXiYxJofDc+2TNg==
+
version "7.0.0-beta.44"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.0.0-beta.44.tgz#2a02643368de80916162be70865c97774f3adbd9"