diff --git a/.rufo b/.rufo index 5faeea24..35d1e354 100644 --- a/.rufo +++ b/.rufo @@ -1,4 +1,3 @@ -indent_size 2 spaces_inside_hash_brace :never spaces_around_binary :one parens_in_def :yes diff --git a/lib/rufo/formatter.rb b/lib/rufo/formatter.rb index 08a6ac4a..646844e5 100644 --- a/lib/rufo/formatter.rb +++ b/lib/rufo/formatter.rb @@ -3,6 +3,8 @@ require "ripper" class Rufo::Formatter + INDENT_SIZE = 2 + def self.format(code, **options) formatter = new(code, **options) formatter.format @@ -1222,7 +1224,7 @@ def visit_command_args(args, base_column) # # foo 1, # 2 - elsif !args_is_def_class_or_module && @first_token_in_line && base_column + @indent_size == @first_token_in_line[0][1] + elsif !args_is_def_class_or_module && @first_token_in_line && base_column + INDENT_SIZE == @first_token_in_line[0][1] # Otherwise, align it just by two spaces (so we need to dedent, we fake a dedent here) # # foo 1, @@ -1503,7 +1505,7 @@ def visit_bodystmt(node) end if inside_type_body && current_type && @visibility_indent_in_action[current_type] - @indent -= @indent_size + @indent -= INDENT_SIZE @visibility_indent_in_action.delete current_type end @@ -2685,7 +2687,7 @@ def visit_literal_elements(elements, inside_hash: false, inside_array: false, to # foo([ # 2, # ]) - @literal_indents << [base_line, @line, token_column + @indent_size - needed_indent] + @literal_indents << [base_line, @line, token_column + INDENT_SIZE - needed_indent] elsif call_info && call_info[0] == current_token_column # If the closing literal position matches the column where # the call started, we want to preserve it like that @@ -3260,9 +3262,9 @@ def indent(value = nil) yield @indent = old_indent else - @indent += @indent_size + @indent += INDENT_SIZE yield - @indent -= @indent_size + @indent -= INDENT_SIZE end end @@ -3438,7 +3440,7 @@ def indent_after_space(node, sticky: false, want_space: true, first_space: nil, end def next_indent - @indent + @indent_size + @indent + INDENT_SIZE end def check(kind) @@ -3534,8 +3536,8 @@ def adjust_visibility_indent(node, base_column) 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 + @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 @@ -3554,8 +3556,8 @@ def adjust_visibility_indent(node, base_column) return if i < 0 - if @visibility_indent == :indent || base_column + @indent_size == @tokens[i][0][1] - @indent += @indent_size + if @visibility_indent == :indent || base_column + INDENT_SIZE == @tokens[i][0][1] + @indent += INDENT_SIZE @visibility_indent_in_action[@current_type] = true end end diff --git a/lib/rufo/formatter/settings.rb b/lib/rufo/formatter/settings.rb index 6103bc3f..9a463db6 100644 --- a/lib/rufo/formatter/settings.rb +++ b/lib/rufo/formatter/settings.rb @@ -1,6 +1,5 @@ class Rufo::Formatter def init_settings(options) - indent_size options.fetch(:indent_size, 2) spaces_inside_hash_brace options.fetch(:spaces_inside_hash_brace, :dynamic) spaces_around_binary options.fetch(:spaces_around_binary, :dynamic) parens_in_def options.fetch(:parens_in_def, :dynamic) @@ -11,10 +10,6 @@ def init_settings(options) trailing_commas options.fetch(:trailing_commas, :dynamic) end - def indent_size(value) - @indent_size = value - end - def spaces_inside_hash_brace(value) @spaces_inside_hash_brace = dynamic_always_never_match("spaces_inside_hash_brace", value) end diff --git a/spec/lib/rufo/formatter_source_specs/indent_size.rb.spec b/spec/lib/rufo/formatter_source_specs/indent_size.rb.spec deleted file mode 100644 index b9b83783..00000000 --- a/spec/lib/rufo/formatter_source_specs/indent_size.rb.spec +++ /dev/null @@ -1,13 +0,0 @@ -#~# ORIGINAL -#~# indent_size: 4 - -begin - 1 - end - -#~# EXPECTED - -begin - 1 -end -