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 kDEFINED kFALSE kNIL kSELF kTRUE tAMPER tBANG tCARET tCHARACTER tCOLON3 tCONSTANT tCVAR tDOT2 tDOT3 tFLOAT tGVAR tIDENTIFIER tINTEGER tIVAR tLAMBDA tLBRACK tLCURLY tLPAREN_ARG tPIPE tQSYMBOLS_BEG tQWORDS_BEG tREGEXP_BEG tSTAR tSTRING tSTRING_BEG tSYMBEG tSYMBOL tSYMBOLS_BEG tTILDE tUMINUS tUNARY_NUM tUPLUS tWORDS_BEG tXSTRING_BEG ].freeze
- ARGUMENT_TAKING_FLOW_TOKEN_TYPES =
%i[ tIDENTIFIER kBREAK kNEXT kRETURN kSUPER kYIELD ].freeze
- ARITHMETIC_OPERATOR_TOKENS =
%i[tDIVIDE tDSTAR tMINUS tPERCENT tPLUS tSTAR2].freeze
Constants included from RangeHelp
RangeHelp::BYTE_ORDER_MARK, RangeHelp::NOT_GIVEN
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_gem_version, #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
permalink #on_new_investigation ⇒ Object
[View source]
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/rubocop/cop/style/redundant_line_continuation.rb', line 86 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 |