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
-
INCLUDED_FORMATTERS =
Combination of short and long formatter names.
%w[p progress fu fuubar pa pacman].freeze
Class Attribute Summary
Base
- Inherited
Class Method Summary
Base
- Inherited
Instance Attribute Summary
Instance Method Summary
- #run Internal use only
- #all_extensions private Internal use only
- #current_formatter private Internal use only
- #dependent_gems private Internal use only
- #extensions private Internal use only
- #installed_and_not_loaded_extensions private Internal use only
- #installed_extensions private Internal use only
- #installed_gems private Internal use only
- #loaded_extensions private Internal use only
- #lockfile private Internal use only
- #not_installed_extensions private Internal use only
- #print_install_suggestions private Internal use only
- #print_load_suggestions private Internal use only
- #print_opt_out_instruction private Internal use only
- #puts(*args) private Internal use only
Instance Attribute Details
#skip? ⇒ Boolean
(readonly, private)
# 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 ]#not_installed_extensions (private)
[ GitHub ]# File 'lib/rubocop/cli/command/suggest_extensions.rb', line 95
def not_installed_extensions all_extensions - installed_gems end
#print_install_suggestions (private)
[ GitHub ]# File 'lib/rubocop/cli/command/suggest_extensions.rb', line 41
def print_install_suggestions puts puts 'Tip: Based on detected gems, the following ' \ 'RuboCop extension libraries might be helpful:' not_installed_extensions.sort.each do |extension| puts " * #{extension} (https://rubygems.org/gems/#{extension})" end end
#print_load_suggestions (private)
[ GitHub ]# File 'lib/rubocop/cli/command/suggest_extensions.rb', line 51
def print_load_suggestions puts puts 'The following RuboCop extension libraries are installed but not loaded in config:' installed_and_not_loaded_extensions.sort.each do |extension| puts " * #{extension}" end end
#print_opt_out_instruction (private)
[ GitHub ]# File 'lib/rubocop/cli/command/suggest_extensions.rb', line 60
def print_opt_out_instruction puts puts 'You can opt out of this message by adding the following to your config ' \ '(see https://docs.rubocop.org/rubocop/extensions.html#extension-suggestions ' \ 'for more options):' puts ' AllCops:' puts ' SuggestExtensions: false' 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