[ruby/syntax_suggest] Rollback comment indentation behavior
Originally I fixed https://github.com/ruby/syntax_suggest/pull/177 by making the process of comment removal indentation aware. The next commit is the more general fix and means we don't need to carry that additional logic/overhead. Also: Update syntax via linter
This commit is contained in:
parent
2acbcec056
commit
63ea6b0cf2
@ -155,10 +155,11 @@ module SyntaxSuggest
|
|||||||
# ).to eq(2)
|
# ).to eq(2)
|
||||||
#
|
#
|
||||||
def clean_sweep(source:)
|
def clean_sweep(source:)
|
||||||
|
# Match comments, but not HEREDOC strings with #{variable} interpolation
|
||||||
|
# https://rubular.com/r/HPwtW9OYxKUHXQ
|
||||||
source.lines.map do |line|
|
source.lines.map do |line|
|
||||||
if line.match?(/^\s*#([^{].*)?$/) # https://rubular.com/r/LLE10D8HKMkJvs
|
if line.match?(/^\s*#([^{].*|)$/)
|
||||||
whitespace = /^(?<whitespace>\s*)#([^{].*)?$/.match(line).named_captures["whitespace"] || ""
|
$/
|
||||||
whitespace + $/
|
|
||||||
else
|
else
|
||||||
line
|
line
|
||||||
end
|
end
|
||||||
|
@ -48,10 +48,10 @@ module SyntaxSuggest
|
|||||||
strip_line = line.dup
|
strip_line = line.dup
|
||||||
strip_line.lstrip!
|
strip_line.lstrip!
|
||||||
|
|
||||||
if (@empty = strip_line.empty?)
|
@indent = if (@empty = strip_line.empty?)
|
||||||
@indent = line.length - 1 # Newline removed from strip_line is not "whitespace"
|
line.length - 1 # Newline removed from strip_line is not "whitespace"
|
||||||
else
|
else
|
||||||
@indent = line.length - strip_line.length
|
line.length - strip_line.length
|
||||||
end
|
end
|
||||||
|
|
||||||
set_kw_end
|
set_kw_end
|
||||||
|
@ -28,9 +28,9 @@ module SyntaxSuggest
|
|||||||
block = expansion.expand_neighbors(block)
|
block = expansion.expand_neighbors(block)
|
||||||
|
|
||||||
expect(block.to_s).to eq(<<~EOM.indent(2))
|
expect(block.to_s).to eq(<<~EOM.indent(2))
|
||||||
def bark # index 1
|
def bark # index 1
|
||||||
|
|
||||||
end # index 3
|
end # index 3
|
||||||
EOM
|
EOM
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -72,7 +72,6 @@ module SyntaxSuggest
|
|||||||
EOM
|
EOM
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
it "joins multi-line chained methods when separated by comments" do
|
it "joins multi-line chained methods when separated by comments" do
|
||||||
source = <<~EOM
|
source = <<~EOM
|
||||||
User.
|
User.
|
||||||
@ -114,7 +113,7 @@ module SyntaxSuggest
|
|||||||
lines = CleanDocument.new(source: source).lines
|
lines = CleanDocument.new(source: source).lines
|
||||||
expect(lines[0].to_s).to eq($/)
|
expect(lines[0].to_s).to eq($/)
|
||||||
expect(lines[1].to_s).to eq('puts "what"' + $/)
|
expect(lines[1].to_s).to eq('puts "what"' + $/)
|
||||||
expect(lines[2].to_s).to eq(' ' + $/)
|
expect(lines[2].to_s).to eq($/)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "trailing slash: does not join trailing do" do
|
it "trailing slash: does not join trailing do" do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user