DEV: Replace Overcommit with Lefthook (#7826)

Overcommit uses prebuilt hooks and require global installation.
To avoid this issues replace it with Lefthook.
Lefthook will be installed with npm packages. New contributors
will have fully consistent git hooks.
This commit is contained in:
Abroskin Alexander 2019-07-02 12:29:52 +03:00 committed by Régis Hanol
parent 1b45096aa5
commit 0872a1182d
7 changed files with 59 additions and 52 deletions

View File

@ -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

View File

@ -74,13 +74,7 @@ script:
- | - |
bash -c " bash -c "
if [ '$RUN_LINT' == '1' ]; then if [ '$RUN_LINT' == '1' ]; then
bundle exec rubocop --parallel && \ npx lefthook run lints
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
else else
if [ '$QUNIT_RUN' == '1' ]; then if [ '$QUNIT_RUN' == '1' ]; then
bundle exec rake qunit:test['1200000'] && \ bundle exec rake qunit:test['1200000'] && \

View File

@ -152,6 +152,7 @@ group :development do
gem 'bullet', require: !!ENV['BULLET'] gem 'bullet', require: !!ENV['BULLET']
gem 'better_errors' gem 'better_errors'
gem 'binding_of_caller' gem 'binding_of_caller'
gem 'yaml-lint'
# waiting on 2.7.5 per: https://github.com/ctran/annotate_models/pull/595 # waiting on 2.7.5 per: https://github.com/ctran/annotate_models/pull/595
if rails_master? if rails_master?

View File

@ -412,6 +412,7 @@ GEM
webpush (0.3.8) webpush (0.3.8)
hkdf (~> 0.2) hkdf (~> 0.2)
jwt (~> 2.0) jwt (~> 2.0)
yaml-lint (0.0.10)
PLATFORMS PLATFORMS
ruby ruby
@ -533,6 +534,7 @@ DEPENDENCIES
unicorn unicorn
webmock webmock
webpush webpush
yaml-lint
BUNDLED WITH BUNDLED WITH
1.17.3 1.17.3

49
lefthook.yml Normal file
View File

@ -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

View File

@ -33,6 +33,7 @@
"spectrum-colorpicker": "1.8.0" "spectrum-colorpicker": "1.8.0"
}, },
"devDependencies": { "devDependencies": {
"@arkweid/lefthook": "^0.5.6",
"babel-eslint": "^8.2", "babel-eslint": "^8.2",
"chrome-launcher": "^0.10", "chrome-launcher": "^0.10",
"chrome-remote-interface": "^0.25", "chrome-remote-interface": "^0.25",

View File

@ -2,6 +2,11 @@
# yarn lockfile v1 # 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==
"@babel/code-frame@7.0.0-beta.44": "@babel/code-frame@7.0.0-beta.44":
version "7.0.0-beta.44" version "7.0.0-beta.44"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.0.0-beta.44.tgz#2a02643368de80916162be70865c97774f3adbd9" resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.0.0-beta.44.tgz#2a02643368de80916162be70865c97774f3adbd9"