Sha256: 9e3cad0cd6977c41672ca38e1f5fc17d65b93eb5920b4d84b061021011066672

Contents?: true

Size: 893 Bytes

Versions: 13

Compression:

Stored size: 893 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    # Common functionality for handling percent literals.
    module PercentLiteral
      def percent_literal?(node)
        return unless (begin_source = begin_source(node))
        begin_source.start_with?('%')
      end

      def process(node, *types)
        return unless percent_literal?(node) && types.include?(type(node))
        on_percent_literal(node)
      end

      def begin_source(node)
        node.loc.begin.source if node.loc.respond_to?(:begin) && node.loc.begin
      end

      def type(node)
        node.loc.begin.source[0..-2]
      end

      # A range containing only the contents of the percent literal (e.g. in
      # %i{1 2 3} this will be the range covering '1 2 3' only)
      def contents_range(node)
        range_between(node.loc.begin.end_pos, node.loc.end.begin_pos)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/percent_literal.rb
dirwatch-0.0.8 vendor/bundle/ruby/2.5.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/percent_literal.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/percent_literal.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/percent_literal.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/percent_literal.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/percent_literal.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/percent_literal.rb
rubocop-0.47.1 lib/rubocop/cop/mixin/percent_literal.rb
rubocop-0.47.0 lib/rubocop/cop/mixin/percent_literal.rb
rubocop-0.46.0 lib/rubocop/cop/mixin/percent_literal.rb
rubocop-0.45.0 lib/rubocop/cop/mixin/percent_literal.rb
rubocop-0.44.1 lib/rubocop/cop/mixin/percent_literal.rb
rubocop-0.44.0 lib/rubocop/cop/mixin/percent_literal.rb