Sha256: b1e38a012f6e6c7c9267894cf5329e21fd715973de8d3910ed21bd19055c0ab5

Contents?: true

Size: 1.22 KB

Versions: 10

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Naming
      # This cop checks that your heredocs are using meaningful delimiters.
      # By default it disallows `END` and `EO*`, and can be configured through
      # forbidden listing additional delimiters.
      #
      # @example
      #
      #   # good
      #   <<-SQL
      #     SELECT * FROM foo
      #   SQL
      #
      #   # bad
      #   <<-END
      #     SELECT * FROM foo
      #   END
      #
      #   # bad
      #   <<-EOS
      #     SELECT * FROM foo
      #   EOS
      class HeredocDelimiterNaming < Cop
        include Heredoc

        MSG = 'Use meaningful heredoc delimiters.'

        def on_heredoc(node)
          return if meaningful_delimiters?(node)

          add_offense(node, location: :heredoc_end)
        end

        private

        def meaningful_delimiters?(node)
          delimiters = delimiter_string(node)

          return false unless delimiters =~ /\w/

          forbidden_delimiters.none? do |forbidden_delimiter|
            delimiters =~ Regexp.new(forbidden_delimiter)
          end
        end

        def forbidden_delimiters
          cop_config['ForbiddenDelimiters'] || []
        end
      end
    end
  end
end

Version data entries

10 entries across 9 versions & 3 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb
rubocop-0.81.0 lib/rubocop/cop/naming/heredoc_delimiter_naming.rb
rubocop-0.80.1 lib/rubocop/cop/naming/heredoc_delimiter_naming.rb
rubocop-0.80.0 lib/rubocop/cop/naming/heredoc_delimiter_naming.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/rubocop-0.79.0/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb
rubocop-0.79.0 lib/rubocop/cop/naming/heredoc_delimiter_naming.rb
rubocop-0.78.0 lib/rubocop/cop/naming/heredoc_delimiter_naming.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.77.0/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb
rubocop-0.77.0 lib/rubocop/cop/naming/heredoc_delimiter_naming.rb