From 6f1728bf8419e25b2d29c2de384f4f199746b9dc Mon Sep 17 00:00:00 2001 From: Max Brosnahan Date: Thu, 12 Oct 2017 20:53:23 +0200 Subject: [PATCH 1/2] Change visibility config default --- .rufo | 1 - lib/rufo/formatter/settings.rb | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.rufo b/.rufo index 5faeea24..d7ce1af1 100644 --- a/.rufo +++ b/.rufo @@ -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 diff --git a/lib/rufo/formatter/settings.rb b/lib/rufo/formatter/settings.rb index 6103bc3f..8cfde2d4 100644 --- a/lib/rufo/formatter/settings.rb +++ b/lib/rufo/formatter/settings.rb @@ -5,7 +5,7 @@ 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) + visibility_indent options.fetch(:visibility_indent, :align) 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) From fcda2ce49f32f794d8d787e55ec93dc386fcb99d Mon Sep 17 00:00:00 2001 From: Max Brosnahan Date: Thu, 12 Oct 2017 20:56:18 +0200 Subject: [PATCH 2/2] Remove visibility indent config --- lib/rufo/formatter.rb | 65 ------------------- lib/rufo/formatter/settings.rb | 10 --- .../visibility_indent.rb.spec | 63 +----------------- 3 files changed, 2 insertions(+), 136 deletions(-) diff --git a/lib/rufo/formatter.rb b/lib/rufo/formatter.rb index 08a6ac4a..55d4c6f6 100644 --- a/lib/rufo/formatter.rb +++ b/lib/rufo/formatter.rb @@ -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 @@ -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] @@ -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 @@ -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 diff --git a/lib/rufo/formatter/settings.rb b/lib/rufo/formatter/settings.rb index 8cfde2d4..5daa77e6 100644 --- a/lib/rufo/formatter/settings.rb +++ b/lib/rufo/formatter/settings.rb @@ -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, :align) 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) @@ -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 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