Sha256: 8648c3d00f738718307cb733e64bf9d289d4549ae3fb323479d1ed18b2360064

Contents?: true

Size: 1.14 KB

Versions: 4

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module RSpec
      # Checks that right braces for adjacent single line lets are aligned.
      #
      # @example
      #
      #     # bad
      #     let(:foobar) { blahblah }
      #     let(:baz)    { bar }
      #     let(:a)      { b }
      #
      #     # good
      #     let(:foobar) { blahblah }
      #     let(:baz)    { bar      }
      #     let(:a)      { b        }
      #
      class AlignRightLetBrace < Cop
        MSG = 'Align right let brace'.freeze

        def self.autocorrect_incompatible_with
          [Layout::ExtraSpacing]
        end

        def investigate(_)
          token_aligner.offending_tokens.each do |let|
            add_offense(let, :end)
          end
        end

        def autocorrect(let)
          lambda do |corrector|
            corrector.insert_before(
              let.loc.end,
              token_aligner.indent_for(let)
            )
          end
        end

        private

        def token_aligner
          @token_aligner ||=
            RuboCop::RSpec::AlignLetBrace.new(processed_source.ast, :end)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-rspec-1.18.0 lib/rubocop/cop/rspec/align_right_let_brace.rb
rubocop-rspec-1.17.1 lib/rubocop/cop/rspec/align_right_let_brace.rb
rubocop-rspec-1.17.0 lib/rubocop/cop/rspec/align_right_let_brace.rb
rubocop-rspec-1.16.0 lib/rubocop/cop/rspec/align_right_let_brace.rb