Skip to content

Commit

Permalink
Add comment handling to Heredocs
Browse files Browse the repository at this point in the history
  • Loading branch information
René Föhring committed Mar 30, 2019
1 parent dd0d568 commit f2a30e1
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/credo/code/heredocs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ defmodule Credo.Code.Heredocs do
parse_code(t, acc <> "\\\"", replacement, empty_line_replacement)
end

defp parse_code(<<"#"::utf8, t::binary>>, acc, replacement, empty_line_replacement) do
parse_comment(t, acc <> "#", replacement, empty_line_replacement)
end

defp parse_code(<<"?\""::utf8, t::binary>>, acc, replacement, empty_line_replacement) do
parse_code(t, acc <> "?\"", replacement, empty_line_replacement)
end
Expand All @@ -50,6 +54,20 @@ defmodule Credo.Code.Heredocs do
parse_code(t, acc <> h, replacement, empty_line_replacement)
end

defp parse_comment("", acc, _replacement, _empty_line_replacement) do
acc
end

defp parse_comment(<<"\n"::utf8, t::binary>>, acc, replacement, empty_line_replacement) do
parse_code(t, acc <> "\n", replacement, empty_line_replacement)
end

defp parse_comment(str, acc, replacement, empty_line_replacement) when is_binary(str) do
{h, t} = String.next_codepoint(str)

parse_comment(t, acc <> h, replacement, empty_line_replacement)
end

defp parse_heredoc("", acc, _replacement, _empty_line_replacement) do
acc
end
Expand Down

0 comments on commit f2a30e1

Please sign in to comment.