Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove visibility indent config #31

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .rufo
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ spaces_inside_hash_brace :never
spaces_around_binary :one
parens_in_def :yes
double_newline_inside_type :no
visibility_indent :align
trailing_commas :always
align_case_when true
align_chained_calls true
65 changes: 0 additions & 65 deletions lib/rufo/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def initialize(code, **options)

# Are we inside a type body?
@inside_type_body = false
@visibility_indent_in_action = {}

# Map lines to commands that start at the begining of a line with the following info:
# - line indent
Expand Down Expand Up @@ -311,7 +310,6 @@ def visit(node)
# [:vcall, exp]
token_column = current_token_column
visit node[1]
adjust_visibility_indent(node[1], token_column)
when :fcall
# [:fcall, [:@ident, "foo", [1, 0]]]
visit node[1]
Expand Down Expand Up @@ -1502,11 +1500,6 @@ def visit_bodystmt(node)
indent_body ensure_body[1]
end

if inside_type_body && current_type && @visibility_indent_in_action[current_type]
@indent -= @indent_size
@visibility_indent_in_action.delete current_type
end

write_indent if @line != line
consume_keyword "end"
end
Expand Down Expand Up @@ -3502,64 +3495,6 @@ def void_exps?(node)
node.size == 1 && node[0].size == 1 && node[0][0] == :void_stmt
end

def adjust_visibility_indent(node, base_column)
return if @visibility_indent == :align

case node[1]
when "private", "protected", "public"
# OK
else
return
end

i = @tokens.size - 1

# First, skip spaces until a newline or comment
while i >= 0
token = @tokens[i]
case token[1]
when :on_sp
i -= 1
next
when :on_nl, :on_ignored_nl, :on_comment
i -= 1
break
else
return
end
end

if @visibility_indent_in_action[@current_type]
last_newline_index = @output.rindex("\n")
if last_newline_index
# Remove extra indent if we are indenting inside private/protected/public
# and we just found another one.
@output = "#{@output[0..last_newline_index]}#{@output[last_newline_index + 1 + @indent_size..-1]}".dup
@indent -= @indent_size
@visibility_indent_in_action.delete @current_type
end
end

# Now we skip all spaces and newlines
while i >= 0
token = @tokens[i]
case token[1]
when :on_sp, :on_nl, :on_ignored_nl
i -= 1
next
else
break
end
end

return if i < 0

if @visibility_indent == :indent || base_column + @indent_size == @tokens[i][0][1]
@indent += @indent_size
@visibility_indent_in_action[@current_type] = true
end
end

def find_closing_brace_token
count = 0
i = @tokens.size - 1
Expand Down
10 changes: 0 additions & 10 deletions lib/rufo/formatter/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ def init_settings(options)
spaces_around_binary options.fetch(:spaces_around_binary, :dynamic)
parens_in_def options.fetch(:parens_in_def, :dynamic)
double_newline_inside_type options.fetch(:double_newline_inside_type, :dynamic)
visibility_indent options.fetch(:visibility_indent, :dynamic)
align_case_when options.fetch(:align_case_when, false)
align_chained_calls options.fetch(:align_chained_calls, false)
trailing_commas options.fetch(:trailing_commas, :dynamic)
Expand Down Expand Up @@ -40,15 +39,6 @@ def trailing_commas(value)
end
end

def visibility_indent(value)
case value
when :indent, :align, :dynamic #, :dedent
@visibility_indent = value
else
raise ArgumentError.new("invalid value for visibility_indent: #{value}. Valid values are: :indent, :align, :dynamic")
end
end

def align_case_when(value)
@align_case_when = value
end
Expand Down
63 changes: 2 additions & 61 deletions spec/lib/rufo/formatter_source_specs/visibility_indent.rb.spec
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#~# ORIGINAL
#~# visibility_indent: :dynamic

private

Expand All @@ -14,22 +13,6 @@ foo
bar

#~# ORIGINAL
#~# visibility_indent: :dynamic

private

foo
bar

#~# EXPECTED

private

foo
bar

#~# ORIGINAL
#~# visibility_indent: :align

private

Expand All @@ -44,22 +27,6 @@ foo
bar

#~# ORIGINAL
#~# visibility_indent: :indent

private

foo
bar

#~# EXPECTED

private

foo
bar

#~# ORIGINAL
#~# visibility_indent: :dynamic

private

Expand All @@ -72,18 +39,6 @@ protected

#~# EXPECTED

private

foo
bar

protected

baz

#~# ORIGINAL
#~# visibility_indent: :indent

private

foo
Expand All @@ -93,19 +48,7 @@ protected

baz

#~# EXPECTED

private

foo
bar

protected

baz

#~# ORIGINAL
#~# visibility_indent: :align

private

Expand All @@ -128,7 +71,6 @@ protected
baz

#~# ORIGINAL
#~# visibility_indent: :dynamic

class Foo
private
Expand All @@ -141,11 +83,10 @@ end
class Foo
private

foo
foo
end

#~# ORIGINAL
#~# visibility_indent: :dynamic

class << self
private
Expand All @@ -158,6 +99,6 @@ end
class << self
private

foo
foo
end