Class: RuboCop::Cop::Style::DirectiveScope
Overview
Checks for directive scopes that can be expressed with the tighter
next-statement forms: a disable/enable pair, an
enable/disable pair, or a push/pop with signed arguments
wrapping exactly one statement. A statement-scoped directive cannot
drift as the surrounding code changes and needs no closing boundary.
Constant Summary collapse
- MSG_PAIR =
'Use `%<mode>s-next` instead of a `%<mode>s`/`enable` pair ' \ 'around a single statement.'
- MSG_ENABLE_PAIR =
'Use `enable-next` instead of an `enable`/`disable` pair ' \ 'around a single statement.'
- MSG_PUSH_POP =
'Use `%<replacement>s` instead of `push`/`pop` around a single statement.'
Constants included from RangeHelp
RangeHelp::BYTE_ORDER_MARK, RangeHelp::NOT_GIVEN
Constants inherited from Base
Base::DEPARTMENT_SEVERITIES, Base::RESTRICT_ON_SEND
Instance Attribute Summary
Attributes inherited from Base
#config, #processed_source, #project_index
Instance Method Summary collapse
Methods included from AutoCorrector
Methods inherited from Base
#active_support_extensions_enabled?, #add_global_offense, #add_offense, #always_autocorrect?, autocorrect_incompatible_with, badge, #begin_investigation, #callbacks_needed, callbacks_needed, #config_to_allow_offenses, #config_to_allow_offenses=, #contextual_autocorrect?, #cop_config, cop_name, #cop_name, department, documentation_url, exclude_from_registry, #excluded_file?, #external_dependency_checksum, inherited, #initialize, #inspect, joining_forces, lint?, match?, #message, #offenses, #on_investigation_end, #on_other_file, #parse, #parser_engine, #preview?, #ready, #relevant_file?, requires_gem, #string_literals_frozen_by_default?, support_autocorrect?, support_multiple_source?, #target_gem_version, #target_rails_version, #target_ruby_version
Methods included from ExcludeLimit
cop_dir_for, #exclude_limit, read_limits
Methods included from AutocorrectLogic
#autocorrect?, #autocorrect_enabled?, #autocorrect_requested?, #autocorrect_with_disable_uncorrectable?, #correctable?, #disable_uncorrectable?, #safe_autocorrect?, #skipped_unsafe_correction_with_disable_uncorrectable?
Methods included from IgnoredNode
#ignore_node, #ignored_node?, #part_of_ignored_node?
Methods included from Util
Constructor Details
This class inherits a constructor from RuboCop::Cop::Base
Instance Method Details
#on_new_investigation ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/rubocop/cop/style/directive_scope.rb', line 74 def on_new_investigation processed_source.comments.each do |comment| directive = DirectiveComment.new(comment) next unless comment_config.comment_only_line?(directive.line_number) if plain_disable?(directive) check_pair(directive) elsif signed_push?(directive) check_push_pop(directive) elsif plain_enable?(directive) check_enable_pair(directive) end end end |