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 indent size config #30

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
@@ -1,4 +1,3 @@
indent_size 2
spaces_inside_hash_brace :never
spaces_around_binary :one
parens_in_def :yes
Expand Down
22 changes: 12 additions & 10 deletions lib/rufo/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
require "ripper"

class Rufo::Formatter
INDENT_SIZE = 2

def self.format(code, **options)
formatter = new(code, **options)
formatter.format
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 0 additions & 5 deletions lib/rufo/formatter/settings.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
Expand Down
13 changes: 0 additions & 13 deletions spec/lib/rufo/formatter_source_specs/indent_size.rb.spec

This file was deleted.