Skip to content

Commit

Permalink
Default to creating git pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
faqndo97 committed Dec 31, 2023
1 parent e3da4fc commit 5b62b80
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions railties/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* Add Git pre commiter to by default when rubocop is present

*faqndo97*

* Add brakeman gem by default for static analysis of security vulnerabilities. Allow skipping with --skip-brakeman option.

*vipulnsward*
Expand Down
2 changes: 1 addition & 1 deletion railties/lib/rails/generators/rails/app/app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def app
end

def bin
exclude_pattern = Regexp.union([(/rubocop/ if skip_rubocop?), (/brakeman/ if skip_brakeman?)].compact)
exclude_pattern = Regexp.union([(/rubocop|hooks/ if skip_rubocop?), (/brakeman/ if skip_brakeman?)].compact)
directory "bin", { exclude_pattern: exclude_pattern } do |content|
"#{shebang}\n" + content
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
system("bin/rubocop")
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ require "fileutils"
# path to your application root.
APP_ROOT = File.expand_path("..", __dir__)

HOOKS_PATH = File.expand_path("../bin/hooks", __dir__)

def system!(*args)
system(*args, exception: true)
end
Expand All @@ -12,7 +14,12 @@ FileUtils.chdir APP_ROOT do
# This script is idempotent, so that you can run it at any time and get an expectable outcome.
# Add necessary setup steps to this file.

puts "== Installing dependencies =="
<% unless options.skip_rubocop? -%>
puts "== Installing Pre Commiter =="
system("git config core.hooksPath #{HOOKS_PATH}")
<% end -%>

puts "\n== Installing dependencies =="
system! "gem install bundler --conservative"
system("bundle check") || system!("bundle install")
<% if using_node? -%>
Expand Down
5 changes: 5 additions & 0 deletions railties/test/generators/app_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -628,14 +628,19 @@ def test_inclusion_of_a_debugger

def test_inclusion_of_rubocop
run_generator

assert_gem "rubocop-rails-omakase"
assert_file "bin/rubocop"
assert_directory "bin/hooks"
assert_file ".rubocop.yml"
end

def test_rubocop_is_skipped_if_required
run_generator [destination_root, "--skip-rubocop"]

assert_no_gem "rubocop"
assert_no_file "bin/rubocop"
assert_no_directory "bin/hooks"
assert_no_file ".rubocop.yml"
end

Expand Down

0 comments on commit 5b62b80

Please sign in to comment.