Sha256: 967ce99810879567817a87e65e66805e0ef8018bfefcf9d75c7149bdb251b6a1

Contents?: true

Size: 865 Bytes

Versions: 75

Compression:

Stored size: 865 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    # Common functionality for working with heredoc strings.
    module Heredoc
      OPENING_DELIMITER = /(<<[~-]?)['"`]?([^'"`]+)['"`]?/.freeze

      def on_str(node)
        return unless node.heredoc?

        on_heredoc(node)
      end
      alias on_dstr on_str
      alias on_xstr on_str

      def on_heredoc(_node)
        raise NotImplementedError
      end

      private

      def indent_level(str)
        indentations = str.lines.map { |line| line[/^\s*/] }.reject { |line| line.end_with?("\n") }
        indentations.empty? ? 0 : indentations.min_by(&:size).size
      end

      def delimiter_string(node)
        node.source.match(OPENING_DELIMITER).captures[1]
      end

      def heredoc_type(node)
        node.source.match(OPENING_DELIMITER).captures[0]
      end
    end
  end
end

Version data entries

75 entries across 67 versions & 9 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/mixin/heredoc.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/mixin/heredoc.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/mixin/heredoc.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.36.0/lib/rubocop/cop/mixin/heredoc.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.35.1/lib/rubocop/cop/mixin/heredoc.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.31.2/lib/rubocop/cop/mixin/heredoc.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/mixin/heredoc.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.52.1/lib/rubocop/cop/mixin/heredoc.rb
fablicop-1.10.3 vendor/bundle/ruby/3.2.0/gems/rubocop-1.52.1/lib/rubocop/cop/mixin/heredoc.rb
rubocop-1.53.1 lib/rubocop/cop/mixin/heredoc.rb
rubocop-1.53.0 lib/rubocop/cop/mixin/heredoc.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.35.1/lib/rubocop/cop/mixin/heredoc.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.52.1/lib/rubocop/cop/mixin/heredoc.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.31.2/lib/rubocop/cop/mixin/heredoc.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.36.0/lib/rubocop/cop/mixin/heredoc.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/mixin/heredoc.rb
fablicop-1.10.2 vendor/bundle/ruby/3.2.0/gems/rubocop-1.52.1/lib/rubocop/cop/mixin/heredoc.rb
rubocop-1.52.1 lib/rubocop/cop/mixin/heredoc.rb
rubocop-1.52.0 lib/rubocop/cop/mixin/heredoc.rb
rubocop-1.51.0 lib/rubocop/cop/mixin/heredoc.rb