Skip to content

Commit

Permalink
Merge pull request #314 from ruby-formatter/ruby-3.3
Browse files Browse the repository at this point in the history
Support Ruby 3.3
  • Loading branch information
kzkn authored Dec 27, 2023
2 parents 972825d + f03cdb4 commit 221c711
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby_version: ['3.2', '3.1', '3.0', '2.7']
ruby_version: ['3.3', '3.2', '3.1', '3.0', '2.7']

steps:
- uses: actions/checkout@v3
Expand Down
13 changes: 2 additions & 11 deletions bin/verify-sample-code
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
repos = {
"rspec/rspec-core" => {
"--exclude-pattern" => [
"spec/rspec/core/world_spec.rb",
"spec/rspec/core/formatters/exception_presenter_spec.rb",
"spec/rspec/core/formatters/snippet_extractor_spec.rb",
"spec/rspec/core/metadata_spec.rb",
"spec/rspec/core/formatters/html_formatter_spec.rb",
"spec/rspec/core/formatters_spec.rb",
"spec/rspec/core/formatters/documentation_formatter_spec.rb",
"spec/rspec/core/formatters/progress_formatter_spec.rb"
].join(","),
"lostisland/faraday" => {
"--format" => "progress",
},
}

Expand Down
10 changes: 10 additions & 0 deletions lib/rufo/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2315,6 +2315,12 @@ def visit_q_or_i_array(node)
write_indent next_indent
end
next_token

# fix for 3.3 ripper change. two :on_words_sep are generated for "#\n "
while current_token_kind == :on_words_sep
next_token
end

has_space = true if current_token_value.start_with?(" ")
end

Expand All @@ -2337,6 +2343,10 @@ def visit_q_or_i_array(node)
next_token
write_line
write_indent(column)
# two :on_words_sep are generated for "#\n " on ruby 3.3
while current_token_kind == :on_words_sep
next_token
end
else
next_token
write_space
Expand Down
27 changes: 21 additions & 6 deletions spec/lib/rufo/formatter_source_specs/break.rb.spec
Original file line number Diff line number Diff line change
@@ -1,29 +1,44 @@
#~# ORIGINAL break
loop do

break
end

#~# EXPECTED
break
loop do
break
end

#~# ORIGINAL
loop do

break 1
end

#~# EXPECTED
break 1
loop do
break 1
end

#~# ORIGINAL

loop do
break 1 , 2
end

#~# EXPECTED
break 1, 2
loop do
break 1, 2
end

#~# ORIGINAL
loop do

break 1 ,
2
end

#~# EXPECTED
break 1,
2
loop do
break 1,
2
end
27 changes: 22 additions & 5 deletions spec/lib/rufo/formatter_source_specs/next.rb.spec
Original file line number Diff line number Diff line change
@@ -1,29 +1,46 @@
#~# ORIGINAL next
loop do

next
end

#~# EXPECTED
next
loop do
next
end

#~# ORIGINAL
loop do

next 1
end

#~# EXPECTED
next 1
loop do
next 1
end

#~# ORIGINAL
loop do

next 1 , 2
end

#~# EXPECTED
next 1, 2
loop do
next 1, 2
end

#~# ORIGINAL
loop do

next 1 ,
2
end

#~# EXPECTED
next 1,
2
loop do
next 1,
2
end

6 changes: 5 additions & 1 deletion spec/lib/rufo/formatter_source_specs/redo.rb.spec
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#~# ORIGINAL redo
loop do

redo
end

#~# EXPECTED
redo
loop do
redo
end
8 changes: 7 additions & 1 deletion spec/lib/rufo/formatter_source_specs/retry.rb.spec
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#~# ORIGINAL retry
begin
rescue

retry
end

#~# EXPECTED
retry
begin
rescue
retry
end
32 changes: 26 additions & 6 deletions spec/lib/rufo/formatter_source_specs/yield.rb.spec
Original file line number Diff line number Diff line change
@@ -1,36 +1,56 @@
#~# ORIGINAL yield
def foo

yield
end

#~# EXPECTED
yield
def foo
yield
end

#~# ORIGINAL
def foo

yield 1
end

#~# EXPECTED
yield 1
def foo
yield 1
end

#~# ORIGINAL
def foo

yield 1 , 2
end

#~# EXPECTED
yield 1, 2
def foo
yield 1, 2
end

#~# ORIGINAL
def foo

yield 1 ,
2
end

#~# EXPECTED
yield 1,
2
def foo
yield 1,
2
end

#~# ORIGINAL
def foo

yield( 1 , 2 )
end

#~# EXPECTED
yield(1, 2)
def foo
yield(1, 2)
end

0 comments on commit 221c711

Please sign in to comment.