Sha256: 709b44285999acb17eab77e9ba95bba60498006ac0a13846023e8b96af2875ee

Contents?: true

Size: 1.19 KB

Versions: 12

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module RSpec
      # Checks that left 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 AlignLeftLetBrace < Cop
        MSG = 'Align left let brace'

        def self.autocorrect_incompatible_with
          [Layout::ExtraSpacing]
        end

        def investigate(_processed_source)
          return if processed_source.blank?

          token_aligner.offending_tokens.each do |let|
            add_offense(let, location: :begin)
          end
        end

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

        private

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

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rubocop-rspec-1.41.0 lib/rubocop/cop/rspec/align_left_let_brace.rb
rubocop-rspec-1.40.0 lib/rubocop/cop/rspec/align_left_let_brace.rb
rubocop-rspec-1.39.0 lib/rubocop/cop/rspec/align_left_let_brace.rb
rubocop-rspec-1.38.1 lib/rubocop/cop/rspec/align_left_let_brace.rb
rubocop-rspec-1.38.0 lib/rubocop/cop/rspec/align_left_let_brace.rb
rubocop-rspec-1.37.1 lib/rubocop/cop/rspec/align_left_let_brace.rb
rubocop-rspec-1.37.0 lib/rubocop/cop/rspec/align_left_let_brace.rb
rubocop-rspec-1.36.0 lib/rubocop/cop/rspec/align_left_let_brace.rb
rubocop-rspec-1.35.0 lib/rubocop/cop/rspec/align_left_let_brace.rb
rubocop-rspec-1.34.1 lib/rubocop/cop/rspec/align_left_let_brace.rb
rubocop-rspec-1.34.0 lib/rubocop/cop/rspec/align_left_let_brace.rb
rubocop-rspec-1.33.0 lib/rubocop/cop/rspec/align_left_let_brace.rb