123456789_123456789_123456789_123456789_123456789_

Class: RuboCop::CLI::Command::SuggestExtensions Private

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Base
Instance Chain:
self, Base
Inherits: RuboCop::CLI::Command::Base
Defined in: lib/rubocop/cli/command/suggest_extensions.rb

Overview

Suggest RuboCop extensions to install based on Gemfile dependencies. Only primary dependencies are evaluated, so if a dependency depends on a gem with an extension, it is not suggested. However, if an extension is a transitive dependency, it will not be suggested.

Constant Summary

Class Attribute Summary

Base - Inherited

Class Method Summary

Instance Attribute Summary

Base - Inherited

Instance Method Summary

Instance Attribute Details

#skip?Boolean (readonly, private)

[ GitHub ]

  
# File 'lib/rubocop/cli/command/suggest_extensions.rb', line 30

def skip?
  # Disable outputting the notification:
  # 1. On CI
  # 2. When given RuboCop options that it doesn't make sense for
  # 3. For all formatters except specified in `INCLUDED_FORMATTERS'`
  ENV.fetch('CI', nil) ||
    @options[:only] || @options[:debug] || @options[:list_target_files] ||
    @options[:out] || @options[:stdin] ||
    !INCLUDED_FORMATTERS.include?(current_formatter)
end

Instance Method Details

#all_extensions (private)

[ GitHub ]

  
# File 'lib/rubocop/cli/command/suggest_extensions.rb', line 73

def all_extensions
  return [] unless lockfile.dependencies.any?

  extensions = @config_store.for_pwd.for_all_cops['SuggestExtensions']
  case extensions
  when true
    extensions = ConfigLoader.default_configuration.for_all_cops['SuggestExtensions']
  when false, nil
    extensions = {}
  end

  extensions.select { |_, v| (Array(v) & dependent_gems).any? }.keys
end

#current_formatter (private)

[ GitHub ]

  
# File 'lib/rubocop/cli/command/suggest_extensions.rb', line 69

def current_formatter
  @options[:format] || @config_store.for_pwd.for_all_cops['DefaultFormatter'] || 'p'
end

#dependent_gems (private)

[ GitHub ]

  
# File 'lib/rubocop/cli/command/suggest_extensions.rb', line 111

def dependent_gems
  lockfile.dependencies.map(&:name)
end

#extensions (private)

[ GitHub ]

  
# File 'lib/rubocop/cli/command/suggest_extensions.rb', line 87

def extensions
  not_installed_extensions + installed_and_not_loaded_extensions
end

#installed_and_not_loaded_extensions (private)

[ GitHub ]

  
# File 'lib/rubocop/cli/command/suggest_extensions.rb', line 103

def installed_and_not_loaded_extensions
  installed_extensions - loaded_extensions
end

#installed_extensions (private)

[ GitHub ]

  
# File 'lib/rubocop/cli/command/suggest_extensions.rb', line 91

def installed_extensions
  all_extensions & installed_gems
end

#installed_gems (private)

[ GitHub ]

  
# File 'lib/rubocop/cli/command/suggest_extensions.rb', line 115

def installed_gems
  lockfile.gems.map(&:name)
end

#loaded_extensions (private)

[ GitHub ]

  
# File 'lib/rubocop/cli/command/suggest_extensions.rb', line 99

def loaded_extensions
  @config_store.for_pwd.loaded_features.to_a
end

#lockfile (private)

[ GitHub ]

  
# File 'lib/rubocop/cli/command/suggest_extensions.rb', line 107

def lockfile
  @lockfile ||= Lockfile.new
end

#not_installed_extensions (private)

[ GitHub ]

  
# File 'lib/rubocop/cli/command/suggest_extensions.rb', line 95

def not_installed_extensions
  all_extensions - installed_gems
end

#puts(*args) (private)

[ GitHub ]

  
# File 'lib/rubocop/cli/command/suggest_extensions.rb', line 119

def puts(*args)
  output = (@options[:stderr] ? $stderr : $stdout)
  output.puts(*args)
end

#run

[ GitHub ]

  
# File 'lib/rubocop/cli/command/suggest_extensions.rb', line 17

def run
  return if skip? || extensions.none?

  print_install_suggestions if not_installed_extensions.any?
  print_load_suggestions if installed_and_not_loaded_extensions.any?

  print_opt_out_instruction

  puts if @options[:display_time]
end