Class: RuboCop::Cop::Style::RedundantLineContinuation
- Extended by:
- AutoCorrector
- Includes:
- MatchRange
- Defined in:
- lib/rubocop/cop/style/redundant_line_continuation.rb
Overview
Check for redundant line continuation.
This cop marks a line continuation as redundant if removing the backslash does not result in a syntax error. However, a backslash at the end of a comment or for string concatenation is not redundant and is not considered an offense.
Constant Summary collapse
- MSG =
'Redundant line continuation.'
- LINE_CONTINUATION =
'\\'
- LINE_CONTINUATION_PATTERN =
/(\\\n)/.freeze
- ALLOWED_STRING_TOKENS =
%i[tSTRING tSTRING_CONTENT].freeze
- ARGUMENT_TYPES =
%i[ kDEF kFALSE kNIL kSELF kTRUE tCONSTANT tCVAR tFLOAT tGVAR tIDENTIFIER tINTEGER tIVAR tLBRACK tLCURLY tLPAREN_ARG tSTRING tSTRING_BEG tSYMBOL tXSTRING_BEG ].freeze
- ARGUMENT_TAKING_FLOW_TOKEN_TYPES =
%i[tIDENTIFIER kRETURN kBREAK kNEXT kYIELD].freeze
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
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, #ready, #relevant_file?, requires_gem, #string_literals_frozen_by_default?, support_autocorrect?, support_multiple_source?, #target_rails_version, #target_ruby_version
Methods included from ExcludeLimit
Methods included from AutocorrectLogic
#autocorrect?, #autocorrect_enabled?, #autocorrect_requested?, #autocorrect_with_disable_uncorrectable?, #correctable?, #disable_uncorrectable?, #safe_autocorrect?
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
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/rubocop/cop/style/redundant_line_continuation.rb', line 81 def on_new_investigation return unless processed_source.ast each_match_range(processed_source.ast.source_range, LINE_CONTINUATION_PATTERN) do |range| next if require_line_continuation?(range) next unless redundant_line_continuation?(range) add_offense(range) do |corrector| corrector.remove_leading(range, 1) end end inspect_end_of_ruby_code_line_continuation end |