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

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cli/command/suggest_extensions.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Run all the selected cops and report the result.

Constant Summary collapse

INCLUDED_FORMATTERS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Combination of short and long formatter names.

%w[p progress fu fuubar pa pacman].freeze

Instance Attribute Summary

Attributes inherited from Base

#env

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

by_command_name, inherited, #initialize

Constructor Details

This class inherits a constructor from RuboCop::CLI::Command::Base

Class Method Details

.dependent_gemsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Gems that the current bundle depends on Suggestions are only made for gems that are 1st party dependencies



17
18
19
20
21
# File 'lib/rubocop/cli/command/suggest_extensions.rb', line 17

def dependent_gems
  bundler do |gems|
    gems.dependencies.map(&:name)
  end
end

.installed_gemsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

All installed gems in the current bundle If a suggestion is installed but not depended on, it still should not be suggested.



26
27
28
29
30
31
32
33
34
# File 'lib/rubocop/cli/command/suggest_extensions.rb', line 26

def installed_gems
  bundler do
    # Load specs from the lockfile without trying to resolve them
    return [] unless Bundler.default_lockfile

    lockfile = Bundler.read_file(Bundler.default_lockfile)
    Bundler::LockfileParser.new(lockfile).specs.map(&:name)
  end
end

Instance Method Details

#runObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rubocop/cli/command/suggest_extensions.rb', line 47

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

  puts
  puts 'Tip: Based on detected gems, the following '\
    'RuboCop extension libraries might be helpful:'

  extensions.sort.each do |extension|
    puts "  * #{extension} (http://github.com/rubocop-hq/#{extension})"
  end

  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'

  puts if @options[:display_time]
end