Sha256: 08057704f0d7b7e163362f572f4d3d75e0fee778b0792e76202944445cc51169

Contents?: true

Size: 1.04 KB

Versions: 5

Compression:

Stored size: 1.04 KB

Contents

# encoding: utf-8

module RuboCop
  module Cop
    # Functions for checking the alignment of the `end` keyword.
    module EndKeywordAlignment
      include ConfigurableEnforcedStyle

      MSG = '`end` at %d, %d is not aligned with `%s` at %d, %d'

      private

      def check_offset_of_node(node)
        check_offset(node, node.loc.keyword.source, 0)
      end

      def check_offset(node, alignment_base, offset)
        return if ignored_node?(node)

        end_loc = node.loc.end
        return unless end_loc # Discard modifier forms of if/while/until.

        kw_loc = node.loc.keyword

        if kw_loc.line != end_loc.line &&
            kw_loc.column != end_loc.column + offset
          add_offense(nil, end_loc,
                      format(MSG, end_loc.line, end_loc.column,
                             alignment_base, kw_loc.line, kw_loc.column)) do
            opposite_style_detected
          end
        else
          correct_style_detected
        end
      end

      def parameter_name
        'AlignWith'
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/mixin/end_keyword_alignment.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/mixin/end_keyword_alignment.rb
rubocop-0.26.1 lib/rubocop/cop/mixin/end_keyword_alignment.rb
rubocop-0.26.0 lib/rubocop/cop/mixin/end_keyword_alignment.rb
rubocop-0.25.0 lib/rubocop/cop/mixin/end_keyword_alignment.rb