Skip to content

Commit

Permalink
Rollback comment indentation behavior
Browse files Browse the repository at this point in the history
Originally I fixed #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
  • Loading branch information
schneems committed Mar 9, 2023
1 parent f94fd1f commit ad3db77
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
7 changes: 4 additions & 3 deletions lib/syntax_suggest/clean_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,11 @@ def to_s
# ).to eq(2)
#
def clean_sweep(source:)
# Match comments, but not HEREDOC strings with #{variable} interpolation
# https://rubular.com/r/TReiZlXnlY5ypk
source.lines.map do |line|
if line.match?(/^\s*#([^{].*)?$/) # https://rubular.com/r/LLE10D8HKMkJvs
whitespace = /^(?<whitespace>\s*)#([^{].*)?$/.match(line).named_captures["whitespace"] || ""
whitespace + $/
if line.match?(/^\s*#[^{]?.*$/)
$/
else
line
end
Expand Down
6 changes: 3 additions & 3 deletions lib/syntax_suggest/code_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ def initialize(line:, index:, lex:)
strip_line = line.dup
strip_line.lstrip!

if (@empty = strip_line.empty?)
@indent = line.length - 1 # Newline removed from strip_line is not "whitespace"
@indent = if (@empty = strip_line.empty?)
line.length - 1 # Newline removed from strip_line is not "whitespace"
else
@indent = line.length - strip_line.length
line.length - strip_line.length
end

set_kw_end
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/block_expand_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def sit # index 5
block = expansion.expand_neighbors(block)

expect(block.to_s).to eq(<<~EOM.indent(2))
def bark # index 1
def bark # index 1
end # index 3
end # index 3
EOM
end

Expand Down
3 changes: 1 addition & 2 deletions spec/unit/clean_document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ module SyntaxSuggest
EOM
end


it "joins multi-line chained methods when separated by comments" do
source = <<~EOM
User.
Expand Down Expand Up @@ -114,7 +113,7 @@ module SyntaxSuggest
lines = CleanDocument.new(source: source).lines
expect(lines[0].to_s).to eq($/)
expect(lines[1].to_s).to eq('puts "what"' + $/)
expect(lines[2].to_s).to eq(' ' + $/)
expect(lines[2].to_s).to eq($/)
end

it "trailing slash: does not join trailing do" do
Expand Down

0 comments on commit ad3db77

Please sign in to comment.