From bc695985b9a600325ea13eb76dc0e873bd1f9d8c Mon Sep 17 00:00:00 2001 From: Eric Agnew Date: Mon, 5 Mar 2018 09:27:55 -0600 Subject: [PATCH 1/4] Add validator class and move checks outside modules so check will run when receiving apps are initialized in development --- lib/bd_lint.rb | 6 +++++- lib/bd_lint/rvm_version.rb | 4 ++-- lib/bd_lint/validator.rb | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 lib/bd_lint/validator.rb diff --git a/lib/bd_lint.rb b/lib/bd_lint.rb index dffb8fd..631d985 100644 --- a/lib/bd_lint.rb +++ b/lib/bd_lint.rb @@ -1,10 +1,14 @@ require "bd_lint/rvm_version" +require "bd_lint/validator" require "pre-commit" require "plugins/pre_commit/checks/jscs" +# Run this on application initialization +BdLint::Validator.check +BdLint::RvmVersion.check + module BdLint def self.run - RvmVersion.check PreCommit.run end end diff --git a/lib/bd_lint/rvm_version.rb b/lib/bd_lint/rvm_version.rb index 0fcbd26..cb29ff3 100644 --- a/lib/bd_lint/rvm_version.rb +++ b/lib/bd_lint/rvm_version.rb @@ -1,7 +1,7 @@ +require "mkmf" + module BdLint class RvmVersion - require "mkmf" - def self.check if MakeMakefile.find_executable("rvm") rvm_current = %x(rvm current).chomp diff --git a/lib/bd_lint/validator.rb b/lib/bd_lint/validator.rb new file mode 100644 index 0000000..c727f61 --- /dev/null +++ b/lib/bd_lint/validator.rb @@ -0,0 +1,15 @@ +module BdLint + class Validator + GIT_HOOK_PATH = ".git/hooks/pre-commit".freeze + + class GitHookError < StandardError; end + + def self.check + raise GitHookError, "Please run `bundle exec rake bd_lint:generate:pre_commit`" if invalid? + end + + def self.invalid? + !defined?(Rake) && !File.exist?(GIT_HOOK_PATH) + end + end +end From b119a7287a813c49b625eb45278c163ecc13205d Mon Sep 17 00:00:00 2001 From: Eric Agnew Date: Mon, 5 Mar 2018 09:29:34 -0600 Subject: [PATCH 2/4] Bump version for new feature --- lib/bd_lint/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bd_lint/version.rb b/lib/bd_lint/version.rb index 87621f4..480f78a 100644 --- a/lib/bd_lint/version.rb +++ b/lib/bd_lint/version.rb @@ -1,3 +1,3 @@ module BdLint - VERSION = "0.2.1.4".freeze + VERSION = "0.2.2".freeze end From 9acacd6a6f788c789c36937b5805df8460ae3bfb Mon Sep 17 00:00:00 2001 From: Eric Agnew Date: Mon, 5 Mar 2018 09:33:17 -0600 Subject: [PATCH 3/4] Prevents test suite from issues with validator --- Gemfile.lock | 4 ++-- test_app/config/application.rb | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 1df8b61..24517c3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - bd_lint (0.2.1.4) + bd_lint (0.2.2) brakeman bundler-audit execjs @@ -206,4 +206,4 @@ DEPENDENCIES thor BUNDLED WITH - 1.16.0 + 1.16.1 diff --git a/test_app/config/application.rb b/test_app/config/application.rb index 245bb2d..da07141 100644 --- a/test_app/config/application.rb +++ b/test_app/config/application.rb @@ -6,6 +6,8 @@ require "action_mailer/railtie" require "action_view/railtie" require "sprockets/railtie" +# Prevents test from not running +require "rake" # require "rails/test_unit/railtie" Bundler.require(*Rails.groups) From 7ae9df7b0b5f5b4333fffe1afeb939b6b8f603d1 Mon Sep 17 00:00:00 2001 From: Eric Agnew Date: Tue, 6 Mar 2018 08:01:00 -0600 Subject: [PATCH 4/4] Add conditional error message with proper command --- lib/bd_lint/validator.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/bd_lint/validator.rb b/lib/bd_lint/validator.rb index c727f61..cd38677 100644 --- a/lib/bd_lint/validator.rb +++ b/lib/bd_lint/validator.rb @@ -5,11 +5,15 @@ class Validator class GitHookError < StandardError; end def self.check - raise GitHookError, "Please run `bundle exec rake bd_lint:generate:pre_commit`" if invalid? + raise GitHookError, "Please run `bundle exec #{message}`" if invalid? end def self.invalid? !defined?(Rake) && !File.exist?(GIT_HOOK_PATH) end + + def self.message + defined?(Rails) ? "rails g pre_commit" : "rake bd_lint:generate:pre_commit" + end end end