module RuboCop::Version

This module holds the RuboCop version information.

Constants

CANONICAL_FEATURE_NAMES
EXTENSION_PATH_NAMES
MSG
STRING

Public Class Methods

document_version() click to toggle source

@api private

# File lib/rubocop/version.rb, line 89
def self.document_version
  STRING.match('\d+\.\d+').to_s
end
extension_versions(env) click to toggle source

@api private

# File lib/rubocop/version.rb, line 39
def self.extension_versions(env)
  features = Util.silence_warnings do
    # Suppress any config issues when loading the config (ie. deprecations,
    # pending cops, etc.).
    env.config_store.unvalidated.for_pwd.loaded_features.sort
  end

  features.map do |loaded_feature|
    next unless (match = loaded_feature.match(/rubocop-(?<feature>.*)/))

    # Get the expected name of the folder containing the extension code.
    # Usually it would be the same as the extension name. but sometimes authors
    # can choose slightly different name for their gems, e.g. rubocop-md instead of
    # rubocop-markdown.
    feature = EXTENSION_PATH_NAMES.fetch(loaded_feature, match[:feature])

    begin
      require "rubocop/#{feature}/version"
    rescue LoadError
      # Not worth mentioning libs that are not installed
    end

    next unless (feature_version = feature_version(feature))

    "  - #{loaded_feature} #{feature_version}"
  end.compact
end
feature_version(feature) click to toggle source

Returns feature version in one of two ways:

  • Find by RuboCop core version style (e.g. rubocop-performance, rubocop-rspec)

  • Find by ‘bundle gem` version style (e.g. rubocop-rake)

@api private

# File lib/rubocop/version.rb, line 73
def self.feature_version(feature)
  capitalized_feature = feature.capitalize
  extension_name = CANONICAL_FEATURE_NAMES.fetch(capitalized_feature, capitalized_feature)

  # Find by RuboCop core version style (e.g. rubocop-performance, rubocop-rspec)
  RuboCop.const_get(extension_name)::Version::STRING
rescue NameError
  begin
    # Find by `bundle gem` version style (e.g. rubocop-rake, rubocop-packaging)
    RuboCop.const_get(extension_name)::VERSION
  rescue NameError
    # noop
  end
end
server_mode() click to toggle source

@api private

# File lib/rubocop/version.rb, line 94
def self.server_mode
  RuboCop.const_defined?(:Server) && Server.running? ? ' +server' : ''
end
version(debug: false, env: nil) click to toggle source

@api private

# File lib/rubocop/version.rb, line 17
    def self.version(debug: false, env: nil)
      if debug
        verbose_version = format(MSG, version: STRING, parser_version: Parser::VERSION,
                                      rubocop_ast_version: RuboCop::AST::Version::STRING,
                                      ruby_engine: RUBY_ENGINE, ruby_version: RUBY_VERSION,
                                      server_mode: server_mode,
                                      ruby_platform: RUBY_PLATFORM)
        return verbose_version unless env

        extension_versions = extension_versions(env)
        return verbose_version if extension_versions.empty?

        <<~VERSIONS
          #{verbose_version}
          #{extension_versions.join("\n")}
        VERSIONS
      else
        STRING
      end
    end