Class: Boring::Overcommit::PreCommit::Rubocop::InstallGenerator

Inherits:
BaseGenerator
  • Object
show all
Defined in:
lib/generators/boring/overcommit/pre_commit/rubocop/install/install_generator.rb

Constant Summary collapse

DEFAULT_RUBY_VERSION =
"2.7.1"

Instance Method Summary collapse

Methods inherited from BaseGenerator

#add_git_hooks_with_overcommit, #add_overcommit_gem

Instance Method Details

#check_and_install_rubocopObject



15
16
17
18
19
20
21
22
23
# File 'lib/generators/boring/overcommit/pre_commit/rubocop/install/install_generator.rb', line 15

def check_and_install_rubocop
  return if rubocop_gem_exists?

  say "\nRuboCop gem is not installed. Running the generator to install it!\n", :red

  ruby_version = options[:ruby_version].presence || DEFAULT_RUBY_VERSION

  run "bundle exec rails generate boring:rubocop:install --ruby_version=#{ruby_version}"
end

#configure_rubocopObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/generators/boring/overcommit/pre_commit/rubocop/install/install_generator.rb', line 25

def configure_rubocop
  say "\nAdding configurations for running RuboCop on pre-commit", :green

  uncomment_lines(".overcommit.yml", /PreCommit:/)

  gsub_file(".overcommit.yml", /PreCommit:/) do
    <<~YAML
      PreCommit:
        RuboCop:
          enabled: true
          on_warn: fail # Treat all warnings as failures
          problem_on_unmodified_line: ignore # run RuboCop only on modified code'
    YAML
  end
end

#enable_overcommit_configurationsObject



41
42
43
44
45
46
47
48
49
# File 'lib/generators/boring/overcommit/pre_commit/rubocop/install/install_generator.rb', line 41

def enable_overcommit_configurations
  say "\nEnabling new configurations", :green

  run "git add .overcommit.yml"

  Bundler.with_unbundled_env do
    run "bundle exec overcommit --sign"
  end
end