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).freeze
GRAPHQL_GEM_PATTERN =
/\A\s*gem\s+['"]graphql['"]/
GRAPHQL_LOCKFILE_PATTERN =
/\A\s+graphql\s+\(/
SIDEKIQ_GEM_PATTERN =
/\A\s*gem\s+['"]sidekiq['"]/
SIDEKIQ_LOCKFILE_PATTERN =
/\A\s+sidekiq\s+\(/
SORBET_GEM_PATTERN =

Matches the whole sorbet family: sorbet, sorbet-runtime, sorbet-static-and-runtime

/\A\s*gem\s+['"]sorbet(-[\w-]+)?['"]/
SORBET_LOCKFILE_PATTERN =
/\A\s+sorbet(-[\w-]+)?\s+\(/

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



23
24
25
# File 'lib/rubocop/gusto/init.rb', line 23

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

Instance Method Details

#add_dependenciesObject



27
28
29
30
31
32
33
# File 'lib/rubocop/gusto/init.rb', line 27

def add_dependencies
  detected_optional_plugins.each do |plugin|
    run "bundle show #{plugin} >/dev/null || bundle add #{plugin} --group development", capture: true
  end

  run "bundle binstub rubocop", capture: true
end

#copy_config_filesObject



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

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

  config.add_inherit_gem("rubocop-gusto", *inherit_gem_configs)
  config.add_plugin(PLUGINS + detected_optional_plugins)

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

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