123456789_123456789_123456789_123456789_123456789_

Module: RuboCop::Cop::AutocorrectLogic

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Base, Bundler::DuplicatedGem, Bundler::DuplicatedGroup, Bundler::GemComment, Bundler::GemFilename, Bundler::GemVersion, Bundler::InsecureProtocolSource, Bundler::OrderedGems, Cop, Gemspec::AddRuntimeDependency, Gemspec::DependencyVersion, Gemspec::DeprecatedAttributeAssignment, Gemspec::DevelopmentDependencies, Gemspec::DuplicatedAssignment, Gemspec::OrderedDependencies, Gemspec::RequireMFA, Gemspec::RequiredRubyVersion, Gemspec::RubyVersionGlobalsUsage, InternalAffairs::CopDescription, InternalAffairs::CopEnabled, InternalAffairs::CreateEmptyFile, InternalAffairs::EmptyLineBetweenExpectOffenseAndCorrection, InternalAffairs::ExampleDescription, InternalAffairs::ExampleHeredocDelimiter, InternalAffairs::InheritDeprecatedCopClass, InternalAffairs::LambdaOrProc, InternalAffairs::LocationExpression, InternalAffairs::LocationLineEqualityComparison, InternalAffairs::MethodNameEndWith, InternalAffairs::MethodNameEqual, InternalAffairs::NodeDestructuring, InternalAffairs::NodeFirstOrLastArgument, InternalAffairs::NodeMatcherDirective, InternalAffairs::NodeTypePredicate, InternalAffairs::NumblockHandler, InternalAffairs::OffenseLocationKeyword, InternalAffairs::OperatorKeyword, InternalAffairs::ProcessedSourceBufferName, InternalAffairs::RedundantContextConfigParameter, InternalAffairs::RedundantDescribedClassAsSubject, InternalAffairs::RedundantExpectOffenseArguments, InternalAffairs::RedundantLetRuboCopConfigNew, InternalAffairs::RedundantLocationArgument, InternalAffairs::RedundantMessageArgument, InternalAffairs::RedundantMethodDispatchNode, InternalAffairs::RedundantSourceRange, InternalAffairs::SingleLineComparison, InternalAffairs::StyleDetectedApiUse, InternalAffairs::UndefinedConfig, InternalAffairs::UselessMessageAssertion, InternalAffairs::UselessRestrictOnSend, Layout::AccessModifierIndentation, Layout::ArgumentAlignment, Layout::ArrayAlignment, Layout::AssignmentIndentation, Layout::BeginEndAlignment, Layout::BlockAlignment, Layout::BlockEndNewline, Layout::CaseIndentation, Layout::ClassStructure, Layout::ClosingHeredocIndentation, Layout::ClosingParenthesisIndentation, Layout::CommentIndentation, Layout::ConditionPosition, Layout::DefEndAlignment, Layout::DotPosition, Layout::ElseAlignment, Layout::EmptyComment, Layout::EmptyLineAfterGuardClause, Layout::EmptyLineAfterMagicComment, Layout::EmptyLineAfterMultilineCondition, Layout::EmptyLineBetweenDefs, Layout::EmptyLines, Layout::EmptyLinesAroundAccessModifier, Layout::EmptyLinesAroundArguments, Layout::EmptyLinesAroundAttributeAccessor, Layout::EmptyLinesAroundBeginBody, Layout::EmptyLinesAroundBlockBody, Layout::EmptyLinesAroundClassBody, Layout::EmptyLinesAroundExceptionHandlingKeywords, Layout::EmptyLinesAroundMethodBody, Layout::EmptyLinesAroundModuleBody, Layout::EndAlignment, Layout::EndOfLine, Layout::ExtraSpacing, Layout::FirstArgumentIndentation, Layout::FirstArrayElementIndentation, Layout::FirstArrayElementLineBreak, Layout::FirstHashElementIndentation, Layout::FirstHashElementLineBreak, Layout::FirstMethodArgumentLineBreak, Layout::FirstMethodParameterLineBreak, Layout::FirstParameterIndentation, Layout::HashAlignment, Layout::HeredocArgumentClosingParenthesis, Layout::HeredocIndentation, Layout::IndentationConsistency, Layout::IndentationStyle, Layout::IndentationWidth, Layout::InitialIndentation, Layout::LeadingCommentSpace, Layout::LeadingEmptyLines, Layout::LineContinuationLeadingSpace, Layout::LineContinuationSpacing, Layout::LineEndStringConcatenationIndentation, Layout::LineLength, Layout::MultilineArrayBraceLayout, Layout::MultilineArrayLineBreaks, Layout::MultilineAssignmentLayout, Layout::MultilineBlockLayout, Layout::MultilineHashBraceLayout, Layout::MultilineHashKeyLineBreaks, Layout::MultilineMethodArgumentLineBreaks, Layout::MultilineMethodCallBraceLayout, Layout::MultilineMethodCallIndentation, Layout::MultilineMethodDefinitionBraceLayout, Layout::MultilineMethodParameterLineBreaks, Layout::MultilineOperationIndentation, Layout::ParameterAlignment, Layout::RedundantLineBreak, Layout::RescueEnsureAlignment, Layout::SingleLineBlockChain, Layout::SpaceAfterColon, Layout::SpaceAfterComma, Layout::SpaceAfterMethodName, Layout::SpaceAfterNot, Layout::SpaceAfterSemicolon, Layout::SpaceAroundBlockParameters, Layout::SpaceAroundEqualsInParameterDefault, Layout::SpaceAroundKeyword, Layout::SpaceAroundMethodCallOperator, Layout::SpaceAroundOperators, Layout::SpaceBeforeBlockBraces, Layout::SpaceBeforeBrackets, Layout::SpaceBeforeComma, Layout::SpaceBeforeComment, Layout::SpaceBeforeFirstArg, Layout::SpaceBeforeSemicolon, Layout::SpaceInLambdaLiteral, Layout::SpaceInsideArrayLiteralBrackets, Layout::SpaceInsideArrayPercentLiteral, Layout::SpaceInsideBlockBraces, Layout::SpaceInsideHashLiteralBraces, Layout::SpaceInsideParens, Layout::SpaceInsidePercentLiteralDelimiters, Layout::SpaceInsideRangeLiteral, Layout::SpaceInsideReferenceBrackets, Layout::SpaceInsideStringInterpolation, Layout::TrailingEmptyLines, Layout::TrailingWhitespace, Lint::AmbiguousAssignment, Lint::AmbiguousBlockAssociation, Lint::AmbiguousOperator, Lint::AmbiguousOperatorPrecedence, Lint::AmbiguousRange, Lint::AmbiguousRegexpLiteral, Lint::AssignmentInCondition, Lint::BigDecimalNew, Lint::BinaryOperatorWithIdenticalOperands, Lint::BooleanSymbol, Lint::CircularArgumentReference, Lint::ConstantDefinitionInBlock, Lint::ConstantOverwrittenInRescue, Lint::ConstantResolution, Lint::Debugger, Lint::DeprecatedClassMethods, Lint::DeprecatedConstants, Lint::DeprecatedOpenSSLConstant, Lint::DisjunctiveAssignmentInConstructor, Lint::DuplicateBranch, Lint::DuplicateCaseCondition, Lint::DuplicateElsifCondition, Lint::DuplicateHashKey, Lint::DuplicateMagicComment, Lint::DuplicateMatchPattern, Lint::DuplicateMethods, Lint::DuplicateRegexpCharacterClassElement, Lint::DuplicateRequire, Lint::DuplicateRescueException, Lint::DuplicateSetElement, Lint::EachWithObjectArgument, Lint::ElseLayout, Lint::EmptyBlock, Lint::EmptyClass, Lint::EmptyConditionalBody, Lint::EmptyEnsure, Lint::EmptyExpression, Lint::EmptyFile, Lint::EmptyInPattern, Lint::EmptyInterpolation, Lint::EmptyWhen, Lint::EnsureReturn, Lint::ErbNewArguments, Lint::FlipFlop, Lint::FloatComparison, Lint::FloatOutOfRange, Lint::FormatParameterMismatch, Lint::HashCompareByIdentity, Lint::HashNewWithKeywordArgumentsAsDefault, Lint::HeredocMethodCallPosition, Lint::IdentityComparison, Lint::ImplicitStringConcatenation, Lint::IncompatibleIoSelectWithFiberScheduler, Lint::IneffectiveAccessModifier, Lint::InheritException, Lint::InterpolationCheck, Lint::ItWithoutArgumentsInBlock, Lint::LambdaWithoutLiteralBlock, Lint::LiteralAsCondition, Lint::LiteralAssignmentInCondition, Lint::LiteralInInterpolation, Lint::Loop, Lint::MissingCopEnableDirective, Lint::MissingSuper, Lint::MixedCaseRange, Lint::MixedRegexpCaptureTypes, Lint::MultipleComparison, Lint::NestedMethodDefinition, Lint::NestedPercentLiteral, Lint::NextWithoutAccumulator, Lint::NoReturnInBeginEndBlocks, Lint::NonAtomicFileOperation, Lint::NonDeterministicRequireOrder, Lint::NonLocalExitFromIterator, Lint::NumberConversion, Lint::NumberedParameterAssignment, Lint::NumericOperationWithConstantResult, Lint::OrAssignmentToConstant, Lint::OrderedMagicComments, Lint::OutOfRangeRegexpRef, Lint::ParenthesesAsGroupedExpression, Lint::PercentStringArray, Lint::PercentSymbolArray, Lint::RaiseException, Lint::RandOne, Lint::RedundantCopDisableDirective, Lint::RedundantCopEnableDirective, Lint::RedundantDirGlobSort, Lint::RedundantRegexpQuantifiers, Lint::RedundantRequireStatement, Lint::RedundantSafeNavigation, Lint::RedundantSplatExpansion, Lint::RedundantStringCoercion, Lint::RedundantWithIndex, Lint::RedundantWithObject, Lint::RefinementImportMethods, Lint::RegexpAsCondition, Lint::RequireParentheses, Lint::RequireRangeParentheses, Lint::RequireRelativeSelfPath, Lint::RescueException, Lint::RescueType, Lint::ReturnInVoidContext, Lint::SafeNavigationChain, Lint::SafeNavigationConsistency, Lint::SafeNavigationWithEmpty, Lint::ScriptPermission, Lint::SelfAssignment, Lint::SendWithMixinArgument, Lint::ShadowedArgument, Lint::ShadowedException, Lint::ShadowingOuterLocalVariable, Lint::SharedMutableDefault, Lint::StructNewOverride, Lint::SuppressedException, Lint::SymbolConversion, Lint::Syntax, Lint::ToEnumArguments, Lint::ToJSON, Lint::TopLevelReturnWithArgument, Lint::TrailingCommaInAttributeDeclaration, Lint::TripleQuotes, Lint::UnderscorePrefixedVariableName, Lint::UnescapedBracketInRegexp, Lint::UnexpectedBlockArity, Lint::UnifiedInteger, Lint::UnmodifiedReduceAccumulator, Lint::UnreachableCode, Lint::UnreachableLoop, Lint::UnusedBlockArgument, Lint::UnusedMethodArgument, Lint::UriEscapeUnescape, Lint::UriRegexp, Lint::UselessAccessModifier, Lint::UselessAssignment, Lint::UselessDefined, Lint::UselessElseWithoutRescue, Lint::UselessMethodDefinition, Lint::UselessNumericOperation, Lint::UselessRescue, Lint::UselessRuby2Keywords, Lint::UselessSetterCall, Lint::UselessTimes, Lint::Void, Metrics::AbcSize, Metrics::BlockLength, Metrics::BlockNesting, Metrics::ClassLength, Metrics::CollectionLiteralLength, Metrics::CyclomaticComplexity, Metrics::MethodLength, Metrics::ModuleLength, Metrics::ParameterLists, Metrics::PerceivedComplexity, Migration::DepartmentName, Naming::AccessorMethodName, Naming::AsciiIdentifiers, Naming::BinaryOperatorParameterName, Naming::BlockForwarding, Naming::BlockParameterName, Naming::ClassAndModuleCamelCase, Naming::ConstantName, Naming::FileName, Naming::HeredocDelimiterCase, Naming::HeredocDelimiterNaming, Naming::InclusiveLanguage, Naming::MemoizedInstanceVariableName, Naming::MethodName, Naming::MethodParameterName, Naming::PredicateName, Naming::RescuedExceptionsVariableName, Naming::VariableName, Naming::VariableNumber, Security::CompoundHash, Security::Eval, Security::IoMethods, Security::JSONLoad, Security::MarshalLoad, Security::Open, Security::YAMLLoad, Style::AccessModifierDeclarations, Style::AccessorGrouping, Style::Alias, Style::AmbiguousEndlessMethodDefinition, Style::AndOr, Style::ArgumentsForwarding, Style::ArrayCoercion, Style::ArrayFirstLast, Style::ArrayIntersect, Style::ArrayJoin, Style::AsciiComments, Style::Attr, Style::AutoResourceCleanup, Style::BarePercentLiterals, Style::BeginBlock, Style::BisectedAttrAccessor, Style::BitwisePredicate, Style::BlockComments, Style::BlockDelimiters, Style::CaseEquality, Style::CaseLikeIf, Style::CharacterLiteral, Style::ClassAndModuleChildren, Style::ClassCheck, Style::ClassEqualityComparison, Style::ClassMethods, Style::ClassMethodsDefinitions, Style::ClassVars, Style::CollectionCompact, Style::CollectionMethods, Style::ColonMethodCall, Style::ColonMethodDefinition, Style::CombinableDefined, Style::CombinableLoops, Style::CommandLiteral, Style::CommentAnnotation, Style::CommentedKeyword, Style::ComparableClamp, Style::ConcatArrayLiterals, Style::ConditionalAssignment, Style::ConstantVisibility, Style::Copyright, Style::DataInheritance, Style::DateTime, Style::DefWithParentheses, Style::DigChain, Style::Dir, Style::DirEmpty, Style::DisableCopsWithinSourceCodeDirective, Style::DocumentDynamicEvalDefinition, Style::Documentation, Style::DocumentationMethod, Style::DoubleCopDisableDirective, Style::DoubleNegation, Style::EachForSimpleLoop, Style::EachWithObject, Style::EmptyBlockParameter, Style::EmptyCaseCondition, Style::EmptyElse, Style::EmptyHeredoc, Style::EmptyLambdaParameter, Style::EmptyLiteral, Style::EmptyMethod, Style::Encoding, Style::EndBlock, Style::EndlessMethod, Style::EnvHome, Style::EvalWithLocation, Style::EvenOdd, Style::ExactRegexpMatch, Style::ExpandPathArguments, Style::ExplicitBlockArgument, Style::ExponentialNotation, Style::FetchEnvVar, Style::FileEmpty, Style::FileNull, Style::FileRead, Style::FileTouch, Style::FileWrite, Style::FloatDivision, Style::For, Style::FormatString, Style::FormatStringToken, Style::FrozenStringLiteralComment, Style::GlobalStdStream, Style::GlobalVars, Style::GuardClause, Style::HashAsLastArrayItem, Style::HashConversion, Style::HashEachMethods, Style::HashExcept, Style::HashLikeCase, Style::HashSyntax, Style::HashTransformKeys, Style::HashTransformValues, Style::IdenticalConditionalBranches, Style::IfInsideElse, Style::IfUnlessModifier, Style::IfUnlessModifierOfIfUnless, Style::IfWithBooleanLiteralBranches, Style::IfWithSemicolon, Style::ImplicitRuntimeError, Style::InPatternThen, Style::InfiniteLoop, Style::InlineComment, Style::InverseMethods, Style::InvertibleUnlessCondition, Style::IpAddresses, Style::ItAssignment, Style::KeywordArgumentsMerging, Style::KeywordParametersOrder, Style::Lambda, Style::LambdaCall, Style::LineEndConcatenation, Style::MagicCommentFormat, Style::MapCompactWithConditionalBlock, Style::MapIntoArray, Style::MapToHash, Style::MapToSet, Style::MethodCallWithArgsParentheses, Style::MethodCallWithoutArgsParentheses, Style::MethodCalledOnDoEndBlock, Style::MethodDefParentheses, Style::MinMax, Style::MinMaxComparison, Style::MissingElse, Style::MissingRespondToMissing, Style::MixinGrouping, Style::MixinUsage, Style::ModuleFunction, Style::MultilineBlockChain, Style::MultilineIfModifier, Style::MultilineIfThen, Style::MultilineInPatternThen, Style::MultilineMemoization, Style::MultilineMethodSignature, Style::MultilineTernaryOperator, Style::MultilineWhenThen, Style::MultipleComparison, Style::MutableConstant, Style::NegatedIf, Style::NegatedIfElseCondition, Style::NegatedUnless, Style::NegatedWhile, Style::NestedFileDirname, Style::NestedModifier, Style::NestedParenthesizedCalls, Style::NestedTernaryOperator, Style::Next, Style::NilComparison, Style::NilLambda, Style::NonNilCheck, Style::Not, Style::NumberedParameters, Style::NumberedParametersLimit, Style::NumericLiteralPrefix, Style::NumericLiterals, Style::NumericPredicate, Style::ObjectThen, Style::OneLineConditional, Style::OpenStructUse, Style::OperatorMethodCall, Style::OptionHash, Style::OptionalArguments, Style::OptionalBooleanParameter, Style::OrAssignment, Style::ParallelAssignment, Style::ParenthesesAroundCondition, Style::PercentLiteralDelimiters, Style::PercentQLiterals, Style::PerlBackrefs, Style::PreferredHashMethods, Style::Proc, Style::QuotedSymbols, Style::RaiseArgs, Style::RandomWithOffset, Style::RedundantArgument, Style::RedundantArrayConstructor, Style::RedundantAssignment, Style::RedundantBegin, Style::RedundantCapitalW, Style::RedundantCondition, Style::RedundantConditional, Style::RedundantConstantBase, Style::RedundantCurrentDirectoryInPath, Style::RedundantDoubleSplatHashBraces, Style::RedundantEach, Style::RedundantException, Style::RedundantFetchBlock, Style::RedundantFileExtensionInRequire, Style::RedundantFilterChain, Style::RedundantFreeze, Style::RedundantHeredocDelimiterQuotes, Style::RedundantInitialize, Style::RedundantInterpolation, Style::RedundantInterpolationUnfreeze, Style::RedundantLineContinuation, Style::RedundantParentheses, Style::RedundantPercentQ, Style::RedundantRegexpArgument, Style::RedundantRegexpCharacterClass, Style::RedundantRegexpConstructor, Style::RedundantRegexpEscape, Style::RedundantReturn, Style::RedundantSelf, Style::RedundantSelfAssignment, Style::RedundantSelfAssignmentBranch, Style::RedundantSort, Style::RedundantSortBy, Style::RedundantStringEscape, Style::RegexpLiteral, Style::RequireOrder, Style::RescueModifier, Style::RescueStandardError, Style::ReturnNil, Style::ReturnNilInPredicateMethodDefinition, Style::SafeNavigation, Style::SafeNavigationChainLength, Style::Sample, Style::SelectByRegexp, Style::SelfAssignment, Style::Semicolon, Style::Send, Style::SendWithLiteralMethodName, Style::SignalException, Style::SingleArgumentDig, Style::SingleLineBlockParams, Style::SingleLineDoEndBlock, Style::SingleLineMethods, Style::SlicingWithRange, Style::SoleNestedConditional, Style::SpecialGlobalVars, Style::StabbyLambdaParentheses, Style::StaticClass, Style::StderrPuts, Style::StringChars, Style::StringConcatenation, Style::StringHashKeys, Style::StringLiterals, Style::StringLiteralsInInterpolation, Style::StringMethods, Style::Strip, Style::StructInheritance, Style::SuperArguments, Style::SuperWithArgsParentheses, Style::SwapValues, Style::SymbolArray, Style::SymbolLiteral, Style::SymbolProc, Style::TernaryParentheses, Style::TopLevelMethodDefinition, Style::TrailingBodyOnClass, Style::TrailingBodyOnMethodDefinition, Style::TrailingBodyOnModule, Style::TrailingCommaInArguments, Style::TrailingCommaInArrayLiteral, Style::TrailingCommaInBlockArgs, Style::TrailingCommaInHashLiteral, Style::TrailingMethodEndStatement, Style::TrailingUnderscoreVariable, Style::TrivialAccessors, Style::UnlessElse, Style::UnlessLogicalOperators, Style::UnpackFirst, Style::VariableInterpolation, Style::WhenThen, Style::WhileUntilDo, Style::WhileUntilModifier, Style::WordArray, Style::YAMLFileRead, Style::YodaCondition, Style::YodaExpression, Style::ZeroLengthPredicate
Defined in: lib/rubocop/cop/autocorrect_logic.rb

Overview

This module encapsulates the logic for autocorrect behavior for a cop.

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#autocorrect?Boolean (readonly)

[ GitHub ]

  
# File 'lib/rubocop/cop/autocorrect_logic.rb', line 7

def autocorrect?
  autocorrect_requested? && correctable? && autocorrect_enabled?
end

#autocorrect_enabled?Boolean (readonly)

[ GitHub ]

  
# File 'lib/rubocop/cop/autocorrect_logic.rb', line 31

def autocorrect_enabled?
  # allow turning off autocorrect on a cop by cop basis
  return true unless cop_config

  # `false` is the same as `disabled` for backward compatibility.
  return false if ['disabled', false].include?(cop_config['AutoCorrect'])

  # When LSP is enabled, it is considered as editing source code,
  # and autocorrection with `AutoCorrect: contextual` will not be performed.
  return false if contextual_autocorrect? && LSP.enabled?

  # :safe_autocorrect is a derived option based on several command-line
  # arguments - see RuboCop::Options#add_autocorrection_options
  return safe_autocorrect? if @options.fetch(:safe_autocorrect, false)

  true
end

#autocorrect_requested?Boolean (readonly)

[ GitHub ]

  
# File 'lib/rubocop/cop/autocorrect_logic.rb', line 15

def autocorrect_requested?
  @options.fetch(:autocorrect, false)
end

#autocorrect_with_disable_uncorrectable?Boolean (readonly)

[ GitHub ]

  
# File 'lib/rubocop/cop/autocorrect_logic.rb', line 11

def autocorrect_with_disable_uncorrectable?
  autocorrect_requested? && disable_uncorrectable? && autocorrect_enabled?
end

#correctable?Boolean (readonly)

[ GitHub ]

  
# File 'lib/rubocop/cop/autocorrect_logic.rb', line 19

def correctable?
  self.class.support_autocorrect? || disable_uncorrectable?
end

#disable_uncorrectable?Boolean (readonly)

[ GitHub ]

  
# File 'lib/rubocop/cop/autocorrect_logic.rb', line 23

def disable_uncorrectable?
  @options[:disable_uncorrectable] == true
end

#safe_autocorrect?Boolean (readonly)

[ GitHub ]

  
# File 'lib/rubocop/cop/autocorrect_logic.rb', line 27

def safe_autocorrect?
  cop_config.fetch('Safe', true) && cop_config.fetch('SafeAutoCorrect', true)
end

Instance Method Details

#disable_offense(offense_range) (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/autocorrect_logic.rb', line 51

def disable_offense(offense_range)
  unbreakable_range = multiline_ranges(offense_range)&.find do |range|
    range_overlaps_offense?(offense_range, range)
  end

  if unbreakable_range
    disable_offense_before_and_after((unbreakable_range))
  else
    disable_offense_with_eol_or_surround_comment(offense_range)
  end
end

#disable_offense_at_end_of_line(range, eol_comment) (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/autocorrect_logic.rb', line 135

def disable_offense_at_end_of_line(range, eol_comment)
  Corrector.new(range).insert_after(range, eol_comment)
end

#disable_offense_before_and_after(range_by_lines) (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/autocorrect_logic.rb', line 139

def disable_offense_before_and_after()
  range_with_newline = .resize(.size + 1)
  leading_whitespace = .source_line[/^\s*/]

  Corrector.new().wrap(
    range_with_newline,
    "#{leading_whitespace}# rubocop:todo #{cop_name}\n",
    "#{leading_whitespace}# rubocop:enable #{cop_name}\n"
  )
end

#disable_offense_with_eol_or_surround_comment(range) (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/autocorrect_logic.rb', line 77

def disable_offense_with_eol_or_surround_comment(range)
  eol_comment = " # rubocop:todo #{cop_name}"
  needed_line_length = (range.source_line + eol_comment).length

  if needed_line_length <= max_line_length
    disable_offense_at_end_of_line(range_of_first_line(range), eol_comment)
  else
    disable_offense_before_and_after((range))
  end
end

#heredoc_range(node) (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/autocorrect_logic.rb', line 96

def heredoc_range(node)
  node.source_range.join(node.loc.heredoc_end)
end

#max_line_length (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/autocorrect_logic.rb', line 131

def max_line_length
  config.for_cop('Layout/LineLength')['Max'] || 120
end

#multiline_ranges(offense_range) (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/autocorrect_logic.rb', line 63

def multiline_ranges(offense_range)
  return if offense_range.empty?

  processed_source.ast.each_node.filter_map do |node|
    if surrounding_heredoc?(node)
      heredoc_range(node)
    elsif string_continuation?(node)
      (node.source_range)
    elsif surrounding_percent_array?(node) || multiline_string?(node)
      node.source_range
    end
  end
end

#multiline_string?(node) ⇒ Boolean (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/autocorrect_logic.rb', line 108

def multiline_string?(node)
  node.dstr_type? && node.multiline?
end

#range_by_lines(range) (private)

Expand the given range to include all of any lines it covers. Does not include newline at end of the last line.

[ GitHub ]

  
# File 'lib/rubocop/cop/autocorrect_logic.rb', line 121

def (range)
  begin_of_first_line = range.begin_pos - range.column

  last_line = range.source_buffer.source_line(range.last_line)
  last_line_offset = last_line.length - range.last_column
  end_of_last_line = range.end_pos + last_line_offset

  Parser::Source::Range.new(range.source_buffer, begin_of_first_line, end_of_last_line)
end

#range_of_first_line(range) (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/autocorrect_logic.rb', line 112

def range_of_first_line(range)
  begin_of_first_line = range.begin_pos - range.column
  end_of_first_line = begin_of_first_line + range.source_line.length

  Parser::Source::Range.new(range.source_buffer, begin_of_first_line, end_of_first_line)
end

#range_overlaps_offense?(offense_range, range) ⇒ Boolean (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/autocorrect_logic.rb', line 88

def range_overlaps_offense?(offense_range, range)
  offense_range.begin_pos > range.begin_pos && range.overlaps?(offense_range)
end

#string_continuation?(node) ⇒ Boolean (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/autocorrect_logic.rb', line 104

def string_continuation?(node)
  (node.str_type? || node.dstr_type? || node.xstr_type?) && node.source.match?(/\\\s*$/)
end

#surrounding_heredoc?(node) ⇒ Boolean (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/autocorrect_logic.rb', line 92

def surrounding_heredoc?(node)
  node.type?(:str, :dstr, :xstr) && node.heredoc?
end

#surrounding_percent_array?(node) ⇒ Boolean (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/autocorrect_logic.rb', line 100

def surrounding_percent_array?(node)
  node.array_type? && node.percent_literal?
end