forked from curious725/rubocop-rspec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalign_left_let_brace.rb
53 lines (46 loc) · 1.2 KB
/
align_left_let_brace.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# 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'.freeze
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