Sha256: 0bf27374da18bc69881282b79c5b687d133b0b51759f8eaf7d3846eb56d8f81d

Contents?: true

Size: 1007 Bytes

Versions: 14

Compression:

Stored size: 1007 Bytes

Contents

# encoding: utf-8
# 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, :expression) { opposite_style_detected }
        else
          correct_style_detected
        end
      end

      def on_regexp(node)
        ignore_node(node)
      end

      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

14 entries across 14 versions & 2 rubygems

Version Path
fluent-plugin-detect-memb-exceptions-0.0.2 vendor/bundle/ruby/2.0.0/gems/rubocop-0.42.0/lib/rubocop/cop/mixin/string_help.rb
fluent-plugin-detect-memb-exceptions-0.0.1 vendor/bundle/ruby/2.0.0/gems/rubocop-0.42.0/lib/rubocop/cop/mixin/string_help.rb
rubocop-0.43.0 lib/rubocop/cop/mixin/string_help.rb
rubocop-0.42.0 lib/rubocop/cop/mixin/string_help.rb
rubocop-0.41.2 lib/rubocop/cop/mixin/string_help.rb
rubocop-0.41.1 lib/rubocop/cop/mixin/string_help.rb
rubocop-0.41.0 lib/rubocop/cop/mixin/string_help.rb
rubocop-0.40.0 lib/rubocop/cop/mixin/string_help.rb
rubocop-0.39.0 lib/rubocop/cop/mixin/string_help.rb
rubocop-0.38.0 lib/rubocop/cop/mixin/string_help.rb
rubocop-0.37.2 lib/rubocop/cop/mixin/string_help.rb
rubocop-0.37.1 lib/rubocop/cop/mixin/string_help.rb
rubocop-0.37.0 lib/rubocop/cop/mixin/string_help.rb
rubocop-0.36.0 lib/rubocop/cop/mixin/string_help.rb