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

Fix missing line break due to puts logic #232

Merged
merged 1 commit into from
Nov 15, 2024
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## HEAD (unreleased)

- Fix: Separate multiple parser errors by newline. (https://github.com/ruby/syntax_suggest/pull/232)

## 2.0.1

- Fix CLI failure when shipped with default gems. (https://github.com/ruby/syntax_suggest/pull/226 and https://github.com/ruby/syntax_suggest/pull/227)
Expand Down
1 change: 1 addition & 0 deletions lib/syntax_suggest/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ def self.valid?(source)
require_relative "code_line"
require_relative "code_block"
require_relative "block_expand"
require_relative "mini_stringio"
require_relative "priority_queue"
require_relative "unvisited_lines"
require_relative "around_block_scan"
Expand Down
18 changes: 0 additions & 18 deletions lib/syntax_suggest/core_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,6 @@
# Ruby 3.2+ has a cleaner way to hook into Ruby that doesn't use `require`
if SyntaxError.method_defined?(:detailed_message)
module SyntaxSuggest
# Mini String IO [Private]
#
# Acts like a StringIO with reduced API, but without having to require that
# class.
class MiniStringIO
def initialize(isatty: $stderr.isatty)
@string = +""
@isatty = isatty
end

attr_reader :isatty
def puts(value = $/, **)
@string << value
end

attr_reader :string
end

# SyntaxSuggest.module_for_detailed_message [Private]
#
# Used to monkeypatch SyntaxError via Module.prepend
Expand Down
24 changes: 24 additions & 0 deletions lib/syntax_suggest/mini_stringio.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module SyntaxSuggest
# Mini String IO [Private]
#
# Acts like a StringIO with reduced API, but without having to require that
# class.
class MiniStringIO
EMPTY_ARG = Object.new

def initialize(isatty: $stderr.isatty)
@string = +""
@isatty = isatty
end

attr_reader :isatty
def puts(value = EMPTY_ARG, **)
if !value.equal?(EMPTY_ARG)
@string << value
end
@string << $/
end

attr_reader :string
end
end
25 changes: 25 additions & 0 deletions spec/unit/mini_stringio_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

require_relative "../spec_helper"

module SyntaxSuggest
RSpec.describe "MiniStringIO" do
it "#puts with no inputs" do
io = MiniStringIO.new
io.puts
expect(io.string).to eq($/)
end

it "#puts with an input" do
io = MiniStringIO.new
io.puts "Hello"
expect(io.string).to eq(["Hello", $/].join)
end

it "#puts with an input with a newline" do
io = MiniStringIO.new
io.puts "Hello\n"
expect(io.string).to eq(["Hello\n", $/].join)
end
end
end
Loading