Class: RuboCop::Gusto::Init

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/rubocop/gusto/init.rb

Constant Summary collapse

PLUGINS =
%w(rubocop-gusto rubocop-rspec rubocop-performance rubocop-rake rubocop-rails).freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



16
17
18
# File 'lib/rubocop/gusto/init.rb', line 16

def self.source_root
  File.expand_path("templates", __dir__)
end

Instance Method Details

#add_dependenciesObject



20
21
22
23
24
25
26
27
# File 'lib/rubocop/gusto/init.rb', line 20

def add_dependencies
  if rails?
    # we don't want rubocop-rails to be a dependency of the gem so that we can use this in non-rails gems
    run "bundle show rubocop-rails >/dev/null || bundle add rubocop-rails --group development", capture: true
  end

  run "bundle binstub rubocop", capture: true
end

#copy_config_filesObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rubocop/gusto/init.rb', line 29

def copy_config_files
  config = ConfigYml.load_file(options[:rubocop_yml])

  if config.empty?
    template "rubocop.yml", options[:rubocop_yml]
    config = ConfigYml.load_file(options[:rubocop_yml])
  end

  if rails?
    config.add_inherit_gem("rubocop-gusto", "config/default.yml", "config/rails.yml")
    config.add_plugin(PLUGINS)
  else
    config.add_inherit_gem("rubocop-gusto", "config/default.yml")
    config.add_plugin(PLUGINS - %w(rubocop-rails))
  end

  config.sort!
  config.write(options[:rubocop_yml])
  say_status "update", options[:rubocop_yml]

  create_file(".rubocop_todo.yml", skip: true)
end