Class: RuboCop::OptionsValidator Private
- Inherits:
-
Object
- Object
- RuboCop::OptionsValidator
- Defined in:
- lib/rubocop/options.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.
Validates option arguments and the options’ compatibility with each other.
Class Method Summary collapse
-
.validate_cop_list(names) ⇒ Object
private
Cop name validation must be done later than option parsing, so it’s not called from within Options.
Instance Method Summary collapse
- #boolean_or_empty_cache? ⇒ Boolean private
- #disable_parallel_when_invalid_combo ⇒ Object private
- #display_only_fail_level_offenses_with_autocorrect? ⇒ Boolean private
- #except_syntax? ⇒ Boolean private
- #incompatible_options ⇒ Object private
-
#initialize(options) ⇒ OptionsValidator
constructor
private
A new instance of OptionsValidator.
- #only_includes_redundant_disable? ⇒ Boolean private
- #validate_auto_correct ⇒ Object private
-
#validate_auto_gen_config ⇒ Object
private
rubocop:enable Metrics/AbcSize.
- #validate_cache_enabled_for_cache_root ⇒ Object private
-
#validate_compatibility ⇒ Object
private
rubocop:disable Metrics/AbcSize.
- #validate_cop_options ⇒ Object private
- #validate_display_only_failed ⇒ Object private
- #validate_exclude_limit_option ⇒ Object private
- #validate_parallel ⇒ Object private
Constructor Details
#initialize(options) ⇒ OptionsValidator
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.
Returns a new instance of OptionsValidator.
275 276 277 |
# File 'lib/rubocop/options.rb', line 275 def initialize() = end |
Class Method Details
.validate_cop_list(names) ⇒ Object
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.
Cop name validation must be done later than option parsing, so it’s not called from within Options.
244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/rubocop/options.rb', line 244 def validate_cop_list(names) return unless names cop_names = Cop::Registry.global.names departments = Cop::Registry.global.departments.map(&:to_s) names.each do |name| next if cop_names.include?(name) next if departments.include?(name) next if SYNTAX_DEPARTMENTS.include?(name) raise IncorrectCopNameError, (name, cop_names) end end |
Instance Method Details
#boolean_or_empty_cache? ⇒ Boolean
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.
379 380 381 |
# File 'lib/rubocop/options.rb', line 379 def boolean_or_empty_cache? !.key?(:cache) || %w[true false].include?([:cache]) end |
#disable_parallel_when_invalid_combo ⇒ Object
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.
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
# File 'lib/rubocop/options.rb', line 349 def disable_parallel_when_invalid_combo combos = { auto_gen_config: '--auto-gen-config', fail_fast: '-F/--fail-fast.', auto_correct: '--auto-correct.' } invalid_combos = combos.select { |key, _flag| .key?(key) } return if invalid_combos.empty? .delete(:parallel) puts '-P/--parallel is being ignored because ' \ "it is not compatible with #{invalid_combos.values.join(', ')}" end |
#display_only_fail_level_offenses_with_autocorrect? ⇒ Boolean
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.
371 372 373 |
# File 'lib/rubocop/options.rb', line 371 def display_only_fail_level_offenses_with_autocorrect? [:display_only_fail_level_offenses] && [:autocorrect] end |
#except_syntax? ⇒ Boolean
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.
375 376 377 |
# File 'lib/rubocop/options.rb', line 375 def except_syntax? .key?(:except) && ([:except] & %w[Lint/Syntax Syntax]).any? end |
#incompatible_options ⇒ Object
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.
383 384 385 |
# File 'lib/rubocop/options.rb', line 383 def ||= .keys & Options::EXITING_OPTIONS end |
#only_includes_redundant_disable? ⇒ Boolean
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.
366 367 368 369 |
# File 'lib/rubocop/options.rb', line 366 def only_includes_redundant_disable? .key?(:only) && ([:only] & %w[Lint/RedundantCopDisableDirective RedundantCopDisableDirective]).any? end |
#validate_auto_correct ⇒ Object
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.
329 330 331 332 333 334 335 |
# File 'lib/rubocop/options.rb', line 329 def validate_auto_correct return if .key?(:auto_correct) return unless .key?(:disable_uncorrectable) raise OptionArgumentError, format('--disable-uncorrectable can only be used together with --auto-correct.') end |
#validate_auto_gen_config ⇒ Object
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.
rubocop:enable Metrics/AbcSize
308 309 310 311 312 313 314 315 316 317 318 319 |
# File 'lib/rubocop/options.rb', line 308 def validate_auto_gen_config return if .key?(:auto_gen_config) = '--%<flag>s can only be used together with --auto-gen-config.' i[exclude_limit offense_counts auto_gen_only_exclude].each do |option| if .key?(option) raise OptionArgumentError, format(, flag: option.to_s.tr('_', '-')) end end end |
#validate_cache_enabled_for_cache_root ⇒ Object
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.
395 396 397 398 399 |
# File 'lib/rubocop/options.rb', line 395 def validate_cache_enabled_for_cache_root return unless [:cache] == 'false' raise OptionArgumentError, '--cache-root can not be used with --cache false' end |
#validate_compatibility ⇒ Object
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.
rubocop:disable Metrics/AbcSize
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
# File 'lib/rubocop/options.rb', line 284 def validate_compatibility # rubocop:disable Metrics/MethodLength if only_includes_redundant_disable? raise OptionArgumentError, 'Lint/RedundantCopDisableDirective cannot be used with --only.' end raise OptionArgumentError, 'Syntax checking cannot be turned off.' if except_syntax? unless boolean_or_empty_cache? raise OptionArgumentError, '-C/--cache argument must be true or false' end if display_only_fail_level_offenses_with_autocorrect? raise OptionArgumentError, '--autocorrect cannot be used with ' \ '--display-only-fail-level-offenses' end validate_auto_gen_config validate_auto_correct validate_display_only_failed validate_parallel return if .size <= 1 raise OptionArgumentError, "Incompatible cli options: #{incompatible_options.inspect}" end |
#validate_cop_options ⇒ Object
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.
279 280 281 |
# File 'lib/rubocop/options.rb', line 279 def i[only except].each { |opt| OptionsValidator.validate_cop_list([opt]) } end |
#validate_display_only_failed ⇒ Object
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.
321 322 323 324 325 326 327 |
# File 'lib/rubocop/options.rb', line 321 def validate_display_only_failed return unless .key?(:display_only_failed) return if [:format] == 'junit' raise OptionArgumentError, format('--display-only-failed can only be used together with --format junit.') end |
#validate_exclude_limit_option ⇒ Object
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.
387 388 389 390 391 392 393 |
# File 'lib/rubocop/options.rb', line 387 def validate_exclude_limit_option return if /^\d+$/.match?([:exclude_limit]) # Emulate OptionParser's behavior to make failures consistent regardless # of option order. raise OptionParser::MissingArgument end |
#validate_parallel ⇒ Object
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.
337 338 339 340 341 342 343 344 345 346 347 |
# File 'lib/rubocop/options.rb', line 337 def validate_parallel return unless .key?(:parallel) if [:cache] == 'false' raise OptionArgumentError, '-P/--parallel uses caching to speed up ' \ 'execution, so combining with --cache ' \ 'false is not allowed.' end disable_parallel_when_invalid_combo end |