Sha256: 0bbe0618d8ee05ad16a830b6cd1997da99a368fd1d535c39be488873a14e53b8

Contents?: true

Size: 1.08 KB

Versions: 49

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    # Classes that include this module just implement functions to determine
    # what is an offense and how to do auto-correction. They get help with
    # adding offenses for the faulty string nodes, and with filtering out
    # nodes.
    module StringHelp
      def on_str(node)
        # Constants like __FILE__ are handled as strings,
        # but don't respond to begin.
        return unless node.loc.respond_to?(:begin) && node.loc.begin
        return if part_of_ignored_node?(node)

        if offense?(node)
          add_offense(node) do |corrector|
            opposite_style_detected
            autocorrect(corrector, node) if respond_to?(:autocorrect, true)
          end
        else
          correct_style_detected
        end
      end

      def on_regexp(node)
        ignore_node(node)
      end

      private

      def inside_interpolation?(node)
        # A :begin node inside a :dstr node is an interpolation.
        node.ancestors.drop_while { |a| !a.begin_type? }.any?(&:dstr_type?)
      end
    end
  end
end

Version data entries

49 entries across 49 versions & 6 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/mixin/string_help.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/mixin/string_help.rb
rubocop-1.29.1 lib/rubocop/cop/mixin/string_help.rb
rubocop-1.29.0 lib/rubocop/cop/mixin/string_help.rb
rubocop-1.28.2 lib/rubocop/cop/mixin/string_help.rb
rubocop-1.28.1 lib/rubocop/cop/mixin/string_help.rb
rubocop-1.28.0 lib/rubocop/cop/mixin/string_help.rb
rubocop-1.27.0 lib/rubocop/cop/mixin/string_help.rb
rubocop-1.26.1 lib/rubocop/cop/mixin/string_help.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/rubocop-1.26.0/lib/rubocop/cop/mixin/string_help.rb
rubocop-1.26.0 lib/rubocop/cop/mixin/string_help.rb
rubocop-1.25.1 lib/rubocop/cop/mixin/string_help.rb
rubocop-1.25.0 lib/rubocop/cop/mixin/string_help.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/rubocop-1.24.0/lib/rubocop/cop/mixin/string_help.rb
rubocop-1.24.1 lib/rubocop/cop/mixin/string_help.rb
rubocop-1.24.0 lib/rubocop/cop/mixin/string_help.rb
rubocop-1.23.0 lib/rubocop/cop/mixin/string_help.rb
rubocop-1.22.3 lib/rubocop/cop/mixin/string_help.rb
rubocop-1.22.2 lib/rubocop/cop/mixin/string_help.rb
rubocop-1.22.1 lib/rubocop/cop/mixin/string_help.rb