Sha256: ad8ecb4c7eb7d56402aad35f5f0b2b72257805640caed4a6aa25d70964152839

Contents?: true

Size: 1.14 KB

Versions: 20

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 < Base
        extend AutoCorrector

        MSG = 'Align right let brace'

        def self.autocorrect_incompatible_with
          [Layout::ExtraSpacing]
        end

        def on_new_investigation
          super
          return if processed_source.blank?

          token_aligner.offending_tokens.each do |let|
            add_offense(let.loc.end) do |corrector|
              corrector.insert_before(
                let.loc.end, token_aligner.indent_for(let)
              )
            end
          end
        end

        private

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

Version data entries

20 entries across 18 versions & 2 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rspec-2.12.1/lib/rubocop/cop/rspec/align_right_let_brace.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rspec-2.9.0/lib/rubocop/cop/rspec/align_right_let_brace.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-rspec-2.12.1/lib/rubocop/cop/rspec/align_right_let_brace.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-rspec-2.9.0/lib/rubocop/cop/rspec/align_right_let_brace.rb
rubocop-rspec-2.12.1 lib/rubocop/cop/rspec/align_right_let_brace.rb
rubocop-rspec-2.12.0 lib/rubocop/cop/rspec/align_right_let_brace.rb
rubocop-rspec-2.11.1 lib/rubocop/cop/rspec/align_right_let_brace.rb
rubocop-rspec-2.11.0 lib/rubocop/cop/rspec/align_right_let_brace.rb
rubocop-rspec-2.10.0 lib/rubocop/cop/rspec/align_right_let_brace.rb
rubocop-rspec-2.9.0 lib/rubocop/cop/rspec/align_right_let_brace.rb
rubocop-rspec-2.8.0 lib/rubocop/cop/rspec/align_right_let_brace.rb
rubocop-rspec-2.7.0 lib/rubocop/cop/rspec/align_right_let_brace.rb
rubocop-rspec-2.6.0 lib/rubocop/cop/rspec/align_right_let_brace.rb
rubocop-rspec-2.5.0 lib/rubocop/cop/rspec/align_right_let_brace.rb
rubocop-rspec-2.4.0 lib/rubocop/cop/rspec/align_right_let_brace.rb
rubocop-rspec-2.3.0 lib/rubocop/cop/rspec/align_right_let_brace.rb
rubocop-rspec-2.2.0 lib/rubocop/cop/rspec/align_right_let_brace.rb
rubocop-rspec-2.1.0 lib/rubocop/cop/rspec/align_right_let_brace.rb
rubocop-rspec-2.0.1 lib/rubocop/cop/rspec/align_right_let_brace.rb
rubocop-rspec-2.0.0 lib/rubocop/cop/rspec/align_right_let_brace.rb