class RuboCop::RSpec::AlignLetBrace
Shared behavior for aligning braces for single line lets
Attributes
root[R]
token[R]
Public Class Methods
new(root, token)
click to toggle source
# File lib/rubocop/rspec/align_let_brace.rb, line 9 def initialize(root, token) @root = root @token = token end
Public Instance Methods
indent_for(node)
click to toggle source
# File lib/rubocop/rspec/align_let_brace.rb, line 20 def indent_for(node) ' ' * (target_column_for(node) - let_token(node).column) end
offending_tokens()
click to toggle source
# File lib/rubocop/rspec/align_let_brace.rb, line 14 def offending_tokens single_line_lets.reject do |let| target_column_for(let) == let_token(let).column end end
Private Instance Methods
adjacent_let_chunks()
click to toggle source
# File lib/rubocop/rspec/align_let_brace.rb, line 42 def adjacent_let_chunks last_line = nil single_line_lets.chunk do |node| line = node.loc.line last_line = (line if last_line.nil? || last_line + 1 == line) last_line.nil? end.map(&:last) end
let_group_for(let)
click to toggle source
# File lib/rubocop/rspec/align_let_brace.rb, line 34 def let_group_for(let) adjacent_let_chunks.detect do |chunk| chunk.any? do |member| member == let && member.loc.line == let.loc.line end end end
let_token(node)
click to toggle source
# File lib/rubocop/rspec/align_let_brace.rb, line 26 def let_token(node) node.loc.public_send(token) end
single_line_lets()
click to toggle source
# File lib/rubocop/rspec/align_let_brace.rb, line 52 def single_line_lets @single_line_lets ||= root.each_node(:block).select do |node| let?(node) && node.single_line? end end
target_column_for(let)
click to toggle source
# File lib/rubocop/rspec/align_let_brace.rb, line 30 def target_column_for(let) let_group_for(let).map { |member| let_token(member).column }.max end