diff --git a/.rufo b/.rufo index 35d1e354..40741e57 100644 --- a/.rufo +++ b/.rufo @@ -2,7 +2,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 diff --git a/lib/rufo/formatter.rb b/lib/rufo/formatter.rb index 646844e5..dd9b4a0c 100644 --- a/lib/rufo/formatter.rb +++ b/lib/rufo/formatter.rb @@ -57,7 +57,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 @@ -313,7 +312,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] @@ -1504,11 +1502,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 @@ -3504,64 +3497,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 diff --git a/lib/rufo/formatter/settings.rb b/lib/rufo/formatter/settings.rb index 9a463db6..5525dc53 100644 --- a/lib/rufo/formatter/settings.rb +++ b/lib/rufo/formatter/settings.rb @@ -4,7 +4,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) @@ -35,15 +34,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 diff --git a/spec/lib/rufo/formatter_source_specs/visibility_indent.rb.spec b/spec/lib/rufo/formatter_source_specs/visibility_indent.rb.spec index b33ff800..5f26be0d 100644 --- a/spec/lib/rufo/formatter_source_specs/visibility_indent.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/visibility_indent.rb.spec @@ -1,5 +1,4 @@ #~# ORIGINAL -#~# visibility_indent: :dynamic private @@ -14,22 +13,6 @@ foo bar #~# ORIGINAL -#~# visibility_indent: :dynamic - -private - - foo -bar - -#~# EXPECTED - -private - - foo - bar - -#~# ORIGINAL -#~# visibility_indent: :align private @@ -44,22 +27,6 @@ foo bar #~# ORIGINAL -#~# visibility_indent: :indent - -private - -foo -bar - -#~# EXPECTED - -private - - foo - bar - -#~# ORIGINAL -#~# visibility_indent: :dynamic private @@ -72,18 +39,6 @@ protected #~# EXPECTED -private - - foo - bar - -protected - - baz - -#~# ORIGINAL -#~# visibility_indent: :indent - private foo @@ -93,19 +48,7 @@ protected baz -#~# EXPECTED - -private - - foo - bar - -protected - - baz - #~# ORIGINAL -#~# visibility_indent: :align private @@ -128,7 +71,6 @@ protected baz #~# ORIGINAL -#~# visibility_indent: :dynamic class Foo private @@ -141,11 +83,10 @@ end class Foo private - foo + foo end #~# ORIGINAL -#~# visibility_indent: :dynamic class << self private @@ -158,6 +99,6 @@ end class << self private - foo + foo end