From 836e54f9d8e930bd192e408f9c43b3d924858673 Mon Sep 17 00:00:00 2001 From: Wilson Silva Date: Fri, 6 Jan 2023 10:58:39 +0700 Subject: [PATCH] Add Overcommit to prevent committing substandard code --- .overcommit.yml | 33 +++++++++++++++++++++++++++++++++ bin/setup | 8 +++++++- nostr.gemspec | 1 + 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 .overcommit.yml diff --git a/.overcommit.yml b/.overcommit.yml new file mode 100644 index 0000000..cbffc77 --- /dev/null +++ b/.overcommit.yml @@ -0,0 +1,33 @@ +# Use this file to configure the Overcommit hooks you wish to use. This will +# extend the default configuration defined in: +# https://github.com/sds/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/sds/overcommit/tree/master/lib/overcommit/hook +# +# For a complete list of options that you can use to customize hooks, see: +# https://github.com/sds/overcommit#configuration +# +# Uncomment the following lines to make the configuration take effect. + +PreCommit: + RuboCop: + enabled: true + on_warn: fail # Treat all warnings as failures + + TrailingWhitespace: + enabled: true + exclude: + - '**/db/structure.sql' # Ignore trailing whitespace in generated files + +#PostCheckout: +# ALL: # Special hook name that customizes all hooks of this type +# quiet: true # Change all post-checkout hooks to only display output on failure +# +# IndexTags: +# enabled: true # Generate a tags file with `ctags` each time HEAD changes diff --git a/bin/setup b/bin/setup index dce67d8..a90d1a3 100755 --- a/bin/setup +++ b/bin/setup @@ -5,4 +5,10 @@ set -vx bundle install -# Do any other automated setup that you need to do here +if ! which overcommit >/dev/null; then + echo 'The gem overcommit is not installed. It is necessary to lint the git history through git hooks.' + echo 'Please install overcommit and run this script again.' + exit 1 +fi + +overcommit --install diff --git a/nostr.gemspec b/nostr.gemspec index 71cf0f6..0009e59 100644 --- a/nostr.gemspec +++ b/nostr.gemspec @@ -31,6 +31,7 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } spec.require_paths = ['lib'] + spec.add_development_dependency 'overcommit', '~> 0.59' spec.add_development_dependency 'rake', '~> 13.0' spec.add_development_dependency 'rspec', '~> 3.12' spec.add_development_dependency 'rubocop', '~> 1.42'