Module: RuboCop::Version
Relationships & Source Files | |
Defined in: | lib/rubocop/version.rb |
Overview
This module holds the RuboCop version information.
Constant Summary
-
CANONICAL_FEATURE_NAMES =
# File 'lib/rubocop/version.rb', line 13{ 'Rspec' => 'RSpec', 'Graphql' => 'GraphQL', 'Md' => 'Markdown', 'Factory_bot' => 'FactoryBot', 'Thread_safety' => 'ThreadSafety', 'Rspec_rails' => 'RSpecRails' }.freeze
-
EXTENSION_PATH_NAMES =
# File 'lib/rubocop/version.rb', line 17{ 'rubocop-md' => 'markdown', 'rubocop-factory_bot' => 'factory_bot' }.freeze
-
MSG =
# File 'lib/rubocop/version.rb', line 8'%<version>s (using %<parser_version>s, ' \ 'rubocop-ast %<rubocop_ast_version>s, ' \ 'analyzing as Ruby %<target_ruby_version>s, ' \ 'running on %<ruby_engine>s %<ruby_version>s)%<server_mode>s [%<ruby_platform>s]'
-
STRING =
# File 'lib/rubocop/version.rb', line 6'1.68.0'
Class Method Summary
- .config_for_pwd(env) Internal use only Internal use only
- .document_version Internal use only Internal use only
- .extension_versions(env) Internal use only Internal use only
-
.feature_version(feature)
Internal use only
Internal use only
Returns feature version in one of two ways:
- .parser_version Internal use only Internal use only
- .server_mode Internal use only Internal use only
- .target_ruby_version(env) Internal use only Internal use only
- .verbose(env: nil) Internal use only Internal use only
-
.version(debug: false, env: nil)
Internal use only
Internal use only
Note
Marked as private but used by gems like standard.
Class Method Details
.config_for_pwd(env)
This method is for internal use only.
[ GitHub ]
# File 'lib/rubocop/version.rb', line 99
def self.config_for_pwd(env) Util.silence_warnings do # Suppress any config issues when loading the config (ie. deprecations, # pending cops, etc.). env.config_store.unvalidated.for_pwd end end
.document_version
This method is for internal use only.
[ GitHub ]
# File 'lib/rubocop/version.rb', line 129
def self.document_version STRING.match('\d+\.\d+').to_s end
.extension_versions(env)
This method is for internal use only.
[ GitHub ]
# File 'lib/rubocop/version.rb', line 66
def self.extension_versions(env) features = config_for_pwd(env).loaded_features.sort features.filter_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 end
.feature_version(feature)
This method is for internal use only.
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)
# File 'lib/rubocop/version.rb', line 113
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
.parser_version
This method is for internal use only.
[ GitHub ]
# File 'lib/rubocop/version.rb', line 51
def self.parser_version config_path = ConfigFinder.find_config_path(Dir.pwd) yaml = Util.silence_warnings do ConfigLoader.load_yaml_configuration(config_path) end if yaml.dig('AllCops', 'ParserEngine') == 'parser_prism' require 'prism' "Prism #{Prism::VERSION}" else "Parser #{Parser::VERSION}" end end
.server_mode
This method is for internal use only.
[ GitHub ]
.target_ruby_version(env)
This method is for internal use only.
[ GitHub ]
# File 'lib/rubocop/version.rb', line 90
def self.target_ruby_version(env) if env config_for_pwd(env).target_ruby_version else TargetRuby.new(Config.new).version end end
.verbose(env: nil)
This method is for internal use only.
[ GitHub ]
# File 'lib/rubocop/version.rb', line 46
def self.verbose(env: nil) version(debug: true, env: env) end
.version(debug: false, env: nil)
This method is for internal use only.
Note
|
Marked as private but used by gems like standard. |
# File 'lib/rubocop/version.rb', line 23
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, target_ruby_version: target_ruby_version(env), 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