Skip to content
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
3 changes: 2 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
AllCops:
NewCops: enable
TargetRubyVersion: 3.0
TargetRubyVersion: 3.1
SuggestExtensions: false
Exclude:
- .vendor/**/*
Expand Down Expand Up @@ -70,6 +70,7 @@ Style/BlockDelimiters:
Style/GlobalVars:
Exclude:
- ext/tree_sitter/extconf.rb

Style/IfUnlessModifier:
Enabled: false

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [unreleased]

- Drop support for Ruby < 3.1.
- Deprarture from the `ruby/pretty_print` API with Wadler:
- accept `indent` which will apply to `nest` and `group` implicitly if no
`indent:` kwarg is passed.
Expand Down
2 changes: 1 addition & 1 deletion examples/oppen/oppen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
Oppen.eof,
]

puts Oppen.print(tokens: tokens)
puts Oppen.print(tokens:)
# Hello, World!
# How are you doing?
2 changes: 1 addition & 1 deletion examples/oppen_and_wadler_customization/new_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# The new line String can be specified using the `new_line` parameter.
new_line = '<br>'

printer = Oppen::Wadler.new(indent: 2, new_line: new_line)
printer = Oppen::Wadler.new(indent: 2, new_line:)

printer.group {
printer.text 'Hello, World!'
Expand Down
2 changes: 1 addition & 1 deletion examples/oppen_and_wadler_customization/whitespace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# to prevent trailing whitespaces can be specified using the `whitespace` parameter.
whitespace = '**'

printer = Oppen::Wadler.new(indent: 2, whitespace: whitespace)
printer = Oppen::Wadler.new(indent: 2, whitespace:)

printer.group {
printer.text '******Hello, World!******'
Expand Down
2 changes: 1 addition & 1 deletion examples/oppen_and_wadler_customization/width.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
width = 5

printer_width_default = Oppen::Wadler.new(indent: 2)
printer_width_narrow = Oppen::Wadler.new(indent: 2, width: width)
printer_width_narrow = Oppen::Wadler.new(indent: 2, width:)
test_block = ->(printer) {
printer.group {
printer.text 'Hello, World!'
Expand Down
4 changes: 4 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ gem:
lint:
bundle exec rubocop --config .rubocop.yml

[group('lint')]
lint-fix:
bundle exec rubocop --config .rubocop.yml -A

[group('publish')]
publish:
gem -C {{PKG_OUT}} push {{GEM_FILE}}
Expand Down
16 changes: 8 additions & 8 deletions lib/oppen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ def self.oppen
# @return [Config]
def self.wadler(eager_print: true, trim_trailing_whitespaces: true, upsize_stack: true)
new(
eager_print: eager_print,
eager_print:,
indent_anchor: :current_offset,
trim_trailing_whitespaces: trim_trailing_whitespaces,
upsize_stack: upsize_stack,
trim_trailing_whitespaces:,
upsize_stack:,
)
end
end
Expand All @@ -172,7 +172,7 @@ def self.wadler(eager_print: true, trim_trailing_whitespaces: true, upsize_stack
# @return [Token::String]
# a new String token.
def self.string(value, width: value.length)
Token::String.new(value, width: width)
Token::String.new(value, width:)
end

# @return [Token::Whitespace] a new Whitespace token.
Expand All @@ -196,7 +196,7 @@ def self.whitespace(value)
#
# @see Wadler#break example on `line_continuation`.
def self.break(str = ' ', line_continuation: '', offset: 0, width: str.length)
Token::Break.new(str, width: width, line_continuation: line_continuation, offset: offset)
Token::Break.new(str, width:, line_continuation:, offset:)
end

# @param line_continuation [String]
Expand All @@ -209,7 +209,7 @@ def self.break(str = ' ', line_continuation: '', offset: 0, width: str.length)
#
# @see Wadler#break example on `line_continuation`.
def self.line_break(line_continuation: '', offset: 0)
Token::LineBreak.new(line_continuation: line_continuation, offset: offset)
Token::LineBreak.new(line_continuation:, offset:)
end

# In a consistent group, the presence of a new line inside the group will
Expand All @@ -232,7 +232,7 @@ def self.line_break(line_continuation: '', offset: 0)
#
# @see Wadler#group
def self.begin_consistent(offset: 2)
Token::Begin.new(break_type: :consistent, offset: offset)
Token::Begin.new(break_type: :consistent, offset:)
end

# In an inconsistent group, the presence of a new line inside the group will
Expand All @@ -251,7 +251,7 @@ def self.begin_consistent(offset: 2)
#
# @see Wadler#group
def self.begin_inconsistent(offset: 2)
Token::Begin.new(break_type: :inconsistent, offset: offset)
Token::Begin.new(break_type: :inconsistent, offset:)
end

# @return [Token::End] a new End token.
Expand Down
2 changes: 1 addition & 1 deletion lib/oppen/mixins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def upsize_circular_array(arr, offset)

# @return [String]
def tokens_to_wadler(tokens, base_indent: 0, printer_name: 'out', width: tokens.length * 3)
printer = Oppen::Wadler.new(base_indent: base_indent, indent: 2, width: width)
printer = Oppen::Wadler.new(base_indent:, indent: 2, width:)

handle_break_token = ->(token) {
if token.offset.positive?
Expand Down
2 changes: 1 addition & 1 deletion lib/oppen/print_stack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def print(token, token_width, trim_on_break: 0)
in Token::End
handle_end
in Token::Break
handle_break token, token_width, trim_on_break: trim_on_break
handle_break token, token_width, trim_on_break:
in Token::String
handle_string token, token_width
end
Expand Down
2 changes: 1 addition & 1 deletion lib/oppen/printer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def advance_left(token, token_width)
end
trim_on_break ||= 0

print_stack.print(token, token_width, trim_on_break: trim_on_break)
print_stack.print(token, token_width, trim_on_break:)

case token
when Token::Break
Expand Down
2 changes: 1 addition & 1 deletion lib/oppen/token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def length = 999_999
end

def initialize(line_continuation: '', offset: 0)
super(LineBreakString.new, line_continuation: line_continuation, offset: offset)
super(LineBreakString.new, line_continuation:, offset:)
end
end

Expand Down
80 changes: 40 additions & 40 deletions lib/wadler/print.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ def add_missing_begin_and_end
def output
add_missing_begin_and_end
Oppen.print(
tokens: tokens,
new_line: new_line,
config: config,
tokens:,
new_line:,
config:,
space: space_gen,
out: out,
width: width,
out:,
width:,
)
end

Expand Down Expand Up @@ -327,7 +327,7 @@ def text(value, width: value.length)
end
tokens << Oppen.whitespace(match)
else
tokens << Oppen.string(value, width: width)
tokens << Oppen.string(value, width:)
end
self
end
Expand All @@ -345,7 +345,7 @@ def text(value, width: value.length)
#
# @see Wadler#break example on `line_continuation`.
def breakable(str = ' ', line_continuation: '', width: str.length)
tokens << Oppen.break(str, width: width, line_continuation: line_continuation, offset: current_indent)
tokens << Oppen.break(str, width:, line_continuation:, offset: current_indent)
self
end

Expand All @@ -370,7 +370,7 @@ def breakable(str = ' ', line_continuation: '', width: str.length)
#
# @return [self]
def break(line_continuation: '')
tokens << Oppen.line_break(line_continuation: line_continuation, offset: current_indent)
tokens << Oppen.line_break(line_continuation:, offset: current_indent)
self
end

Expand Down Expand Up @@ -483,11 +483,11 @@ def separate(args, sep, breakable: ' ', break_pos: :after,
first = false
elsif break_pos == :after
text sep
breakable(breakable, line_continuation: line_continuation) if breakable && !force_break
self.break(line_continuation: line_continuation) if force_break
breakable(breakable, line_continuation:) if breakable && !force_break
self.break(line_continuation:) if force_break
else
breakable(breakable, line_continuation: line_continuation) if breakable && !force_break
self.break(line_continuation: line_continuation) if force_break
breakable(breakable, line_continuation:) if breakable && !force_break
self.break(line_continuation:) if force_break
text sep
end
yield(*as)
Expand All @@ -505,7 +505,7 @@ def separate(args, sep, breakable: ' ', break_pos: :after,
body.()
}
}.end
breakable('', line_continuation: line_continuation) if !line_continuation.empty? && !break_type
breakable('', line_continuation:) if !line_continuation.empty? && !break_type

self
end
Expand Down Expand Up @@ -553,7 +553,7 @@ def surround(lft, rgt, **opts)
text lft if lft

indent = opts.fetch(:indent, @indent)
nest_open(indent: indent)
nest_open(indent:)

lft_breakable = opts.fetch(:lft_breakable, '')
lft_can_break = opts.fetch(:lft_can_break, true)
Expand Down Expand Up @@ -598,17 +598,17 @@ def surround(lft, rgt, **opts)
# This is a wrapper around {separate} where `breakable: true`.
#
# @see [separate]
def lines(*args, **kwargs, &block)
separate(*args, **kwargs.merge(force_break: true), &block)
def lines(*args, **kwargs, &)
separate(*args, **kwargs.merge(force_break: true), &)
end

# Concatenates args.
#
# This is a wrapper around {separate} where `breakable: false`.
#
# @see [separate]
def concat *args, **kwargs, &block
separate(*args, **kwargs.merge(breakable: false), &block)
def concat(*args, **kwargs, &)
separate(*args, **kwargs.merge(breakable: false), &)
end

# @!endgroup
Expand All @@ -634,15 +634,15 @@ def angles(padding: '', **kwargs, &block)
# {surround} with `< >`. New lines cannot appear after and before the delimiters.
#
# @return [self]
def angles_break_both(**kwargs, &block)
angles(**kwargs.merge(lft_force_break: true, rgt_force_break: true), &block)
def angles_break_both(**kwargs, &)
angles(**kwargs.merge(lft_force_break: true, rgt_force_break: true), &)
end

# {surround} with `< >`. New lines will appear after and before the delimiters.
#
# @return [self]
def angles_break_none(**kwargs, &block)
angles(**kwargs.merge(lft_can_break: false, rgt_can_break: false), &block)
def angles_break_none(**kwargs, &)
angles(**kwargs.merge(lft_can_break: false, rgt_can_break: false), &)
end

# {surround} with `{ }`. New lines can appear after and before the delimiters.
Expand All @@ -662,15 +662,15 @@ def braces(padding: '', **kwargs, &block)
# {surround} with `{ }`. New lines cannot appear after and before the delimiters.
#
# @return [self]
def braces_break_both(**kwargs, &block)
braces(**kwargs.merge(lft_force_break: true, rgt_force_break: true), &block)
def braces_break_both(**kwargs, &)
braces(**kwargs.merge(lft_force_break: true, rgt_force_break: true), &)
end

# {surround} with `{ }`. New lines will appear after and before the delimiters.
#
# @return [self]
def braces_break_none(**kwargs, &block)
braces(**kwargs.merge(lft_can_break: false, rgt_can_break: false), &block)
def braces_break_none(**kwargs, &)
braces(**kwargs.merge(lft_can_break: false, rgt_can_break: false), &)
end

# {surround} with `[ ]`. New lines can appear after and before the delimiters.
Expand All @@ -690,15 +690,15 @@ def brackets(padding: '', **kwargs, &block)
# {surround} with `[ ]`. New lines cannot appear after and before the delimiters.
#
# @return [self]
def brackets_break_both(**kwargs, &block)
brackets(**kwargs.merge(lft_force_break: true, rgt_force_break: true), &block)
def brackets_break_both(**kwargs, &)
brackets(**kwargs.merge(lft_force_break: true, rgt_force_break: true), &)
end

# {surround} with `[ ]`. New lines will appear after and before the delimiters.
#
# @return [self]
def brackets_break_none(**kwargs, &block)
brackets(**kwargs.merge(lft_can_break: false, rgt_can_break: false), &block)
def brackets_break_none(**kwargs, &)
brackets(**kwargs.merge(lft_can_break: false, rgt_can_break: false), &)
end

# {surround} with `( )`. New lines can appear after and before the delimiters.
Expand All @@ -718,39 +718,39 @@ def parens(padding: '', **kwargs, &block)
# {surround} with `( )`. New lines cannot appear after and before the delimiters.
#
# @return [self]
def parens_break_both(**kwargs, &block)
parens(**kwargs.merge(lft_force_break: true, rgt_force_break: true), &block)
def parens_break_both(**kwargs, &)
parens(**kwargs.merge(lft_force_break: true, rgt_force_break: true), &)
end

# {surround} with `( )`. New lines will appear after and before the delimiters.
#
# @return [self]
def parens_break_none(**kwargs, &block)
parens(**kwargs.merge(lft_can_break: false, rgt_can_break: false), &block)
def parens_break_none(**kwargs, &)
parens(**kwargs.merge(lft_can_break: false, rgt_can_break: false), &)
end

# {surround} with `` ` ` ``. New lines cannot appear after and before the delimiters
# unless you specify it with `rgt_can_break` and `lft_can_break`.
#
# @return [self]
def backticks(**kwargs, &block)
surround('`', '`', lft_can_break: false, rgt_can_break: false, **kwargs, &block)
def backticks(**kwargs, &)
surround('`', '`', lft_can_break: false, rgt_can_break: false, **kwargs, &)
end

# {surround} with `" "`. New lines cannot appear after and before the delimiters
# unless you specify it with `rgt_can_break` and `lft_can_break`.
#
# @return [self]
def quote_double(**kwargs, &block)
surround('"', '"', lft_can_break: false, rgt_can_break: false, **kwargs, &block)
def quote_double(**kwargs, &)
surround('"', '"', lft_can_break: false, rgt_can_break: false, **kwargs, &)
end

# {surround} with `' '`. New lines cannot appear after and before the delimiters
# unless you specify it with `rgt_can_break` and `lft_can_break`.
#
# @return [self]
def quote_single(**kwargs, &block)
surround("'", "'", lft_can_break: false, rgt_can_break: false, **kwargs, &block)
def quote_single(**kwargs, &)
surround("'", "'", lft_can_break: false, rgt_can_break: false, **kwargs, &)
end

# Open a consistent group.
Expand Down
2 changes: 1 addition & 1 deletion oppen.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ Gem::Specification.new do |spec|

spec.files = Dir['lib/**/*', 'LICENSE', 'README.md']
spec.require_paths = ['lib']
spec.required_ruby_version = Gem::Requirement.new('>= 3.0')
spec.required_ruby_version = Gem::Requirement.new('>= 3.1')
end
Loading
Loading