Class: RuboCop::ConfigValidator
- Inherits:
-
Object
- Object
- RuboCop::ConfigValidator
- Extended by:
- Forwardable
- Defined in:
- lib/rubocop/config_validator.rb
Overview
Handles validation of configuration, for example cop names, parameter names, and Ruby versions.
Constant Summary collapse
- COMMON_PARAMS =
%w[Exclude Include Severity inherit_mode AutoCorrect StyleGuide Details].freeze
- INTERNAL_PARAMS =
%w[Description StyleGuide VersionAdded VersionChanged VersionRemoved Reference Safe SafeAutoCorrect].freeze
- NEW_COPS_VALUES =
%w[pending disable enable].freeze
Instance Method Summary collapse
-
#initialize(config) ⇒ ConfigValidator
constructor
A new instance of ConfigValidator.
-
#target_ruby_version ⇒ Object
rubocop:enable Metrics/AbcSize.
-
#validate ⇒ Object
rubocop:disable Metrics/AbcSize.
- #validate_section_presence(name) ⇒ Object
Constructor Details
#initialize(config) ⇒ ConfigValidator
Returns a new instance of ConfigValidator.
20 21 22 23 24 |
# File 'lib/rubocop/config_validator.rb', line 20 def initialize(config) @config = config @config_obsoletion = ConfigObsoletion.new(config) @target_ruby = TargetRuby.new(config) end |
Instance Method Details
#target_ruby_version ⇒ Object
rubocop:enable Metrics/AbcSize
50 51 52 |
# File 'lib/rubocop/config_validator.rb', line 50 def target_ruby_version target_ruby.version end |
#validate ⇒ Object
rubocop:disable Metrics/AbcSize
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rubocop/config_validator.rb', line 27 def validate check_cop_config_value(@config) reject_conflicting_safe_settings # Don't validate RuboCop's own files further. Avoids infinite recursion. return if @config.internal? valid_cop_names, invalid_cop_names = @config.keys.partition do |key| ConfigLoader.default_configuration.key?(key) end @config_obsoletion.reject_obsolete_cops_and_parameters alert_about_unrecognized_cops(invalid_cop_names) check_target_ruby validate_new_cops_parameter validate_parameter_names(valid_cop_names) validate_enforced_styles(valid_cop_names) validate_syntax_cop reject_mutually_exclusive_defaults end |
#validate_section_presence(name) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/rubocop/config_validator.rb', line 54 def validate_section_presence(name) return unless @config.key?(name) && @config[name].nil? raise ValidationError, "empty section #{name} found in #{smart_loaded_path}" end |