Sha256: 0956405c272e428926cdae1de30169ffc538fddc9aa298f8bd1bfcfde0631bbf

Contents?: true

Size: 1.12 KB

Versions: 53

Compression:

Stored size: 1.12 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

53 entries across 51 versions & 7 rubygems

Version Path
rubocop-rspec-2.27.0 lib/rubocop/cop/rspec/align_right_let_brace.rb
mlh-rubocop-config-1.0.3 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.26.1/lib/rubocop/cop/rspec/align_right_let_brace.rb
rubocop-rspec-2.26.1 lib/rubocop/cop/rspec/align_right_let_brace.rb
rubocop-rspec-2.26.0 lib/rubocop/cop/rspec/align_right_let_brace.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/align_right_let_brace.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rspec-2.13.1/lib/rubocop/cop/rspec/align_right_let_brace.rb
rubocop-rspec-2.25.0 lib/rubocop/cop/rspec/align_right_let_brace.rb
rubocop-rspec-2.24.1 lib/rubocop/cop/rspec/align_right_let_brace.rb
rubocop-rspec-2.24.0 lib/rubocop/cop/rspec/align_right_let_brace.rb
rubocop-rspec-2.23.2 lib/rubocop/cop/rspec/align_right_let_brace.rb
rubocop-rspec-2.23.1 lib/rubocop/cop/rspec/align_right_let_brace.rb
rubocop-rspec-2.23.0 lib/rubocop/cop/rspec/align_right_let_brace.rb
mlh-rubocop-config-1.0.2 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/align_right_let_brace.rb
fablicop-1.10.3 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/align_right_let_brace.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/align_right_let_brace.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-rspec-2.13.1/lib/rubocop/cop/rspec/align_right_let_brace.rb
fablicop-1.10.2 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/align_right_let_brace.rb
rubocop-rspec-2.22.0 lib/rubocop/cop/rspec/align_right_let_brace.rb
rubocop-rspec-2.21.0 lib/rubocop/cop/rspec/align_right_let_brace.rb
rubocop-rspec-2.20.0 lib/rubocop/cop/rspec/align_right_let_brace.rb