diff --git a/lib/excoveralls/ignore.ex b/lib/excoveralls/ignore.ex index fb4cb19c..1cbfd91a 100644 --- a/lib/excoveralls/ignore.ex +++ b/lib/excoveralls/ignore.ex @@ -61,144 +61,134 @@ defmodule ExCoveralls.Ignore do } end - defp process_regular_line(coverage_line, _index, state = %{ignore_mode: :ignore_line}) do - ignored_coverage = Enum.map([coverage_line | state.coverage_buffer], fn _ -> nil end) - + defp process_regular_line(_coverage_line, _index, state = %{ignore_mode: :ignore_line}) do %{ state | ignore_mode: :no_ignore, - coverage: [ignored_coverage | state.coverage], - coverage_buffer: [] + coverage: [nil | state.coverage] } end - defp process_regular_line(coverage_line, _index, state = %{ignore_mode: :ignore_block}) do + defp process_regular_line(_coverage_line, _index, state = %{ignore_mode: :ignore_block}) do %{ state - | coverage_buffer: [coverage_line | state.coverage_buffer] + | coverage: [nil | state.coverage] } end defp process_start_marker( - coverage_line, + _coverage_line, index, - state = %{ignore_mode: :no_ignore, coverage_buffer: []} + state = %{ignore_mode: :no_ignore} ) do %{ state | ignore_mode: :ignore_block, - coverage_buffer: [coverage_line], + coverage: [nil | state.coverage], last_marker_index: index } end - defp process_start_marker(coverage_line, index, state = %{ignore_mode: :ignore_block}) do + defp process_start_marker(_coverage_line, index, state = %{ignore_mode: :ignore_block}) do warning = {index, "unexpected ignore-start or missing previous ignore-stop"} %{ state - | coverage: [state.coverage_buffer | state.coverage], - coverage_buffer: [coverage_line], + | coverage: [nil | state.coverage], warnings: [warning | state.warnings], last_marker_index: index } end - defp process_start_marker(coverage_line, index, state = %{ignore_mode: :ignore_line}) do + defp process_start_marker(_coverage_line, index, state = %{ignore_mode: :ignore_line}) do warning = {state.last_marker_index, "redundant ignore-next-line right before an ignore-start"} %{ state | ignore_mode: :ignore_block, - coverage: [state.coverage_buffer | state.coverage], - coverage_buffer: [coverage_line], + coverage: [nil | state.coverage], warnings: [warning | state.warnings], last_marker_index: index } end - defp process_stop_marker(coverage_line, index, state = %{ignore_mode: :ignore_block}) do - ignored_coverage = Enum.map([coverage_line | state.coverage_buffer], fn _ -> nil end) - + defp process_stop_marker(_coverage_line, index, state = %{ignore_mode: :ignore_block}) do %{ state | ignore_mode: :no_ignore, - coverage: [ignored_coverage | state.coverage], - coverage_buffer: [], + coverage: [nil | state.coverage], last_marker_index: index } end - defp process_stop_marker(coverage_line, index, state) do + defp process_stop_marker(_coverage_line, index, state) do warning = {index, "unexpected ignore-stop or missing previous ignore-start"} %{ state | ignore_mode: :no_ignore, - coverage: [coverage_line, state.coverage_buffer | state.coverage], - coverage_buffer: [], + coverage: [nil | state.coverage], warnings: [warning | state.warnings], last_marker_index: index } end defp process_next_line_marker( - coverage_line, + _coverage_line, index, - state = %{ignore_mode: :no_ignore, coverage_buffer: []} + state = %{ignore_mode: :no_ignore} ) do %{ state | ignore_mode: :ignore_line, - coverage_buffer: [coverage_line], + coverage: [nil | state.coverage], last_marker_index: index } end - defp process_next_line_marker(coverage_line, index, state = %{ignore_mode: :ignore_block}) do + defp process_next_line_marker( + _coverage_line, + index, + state = %{ignore_mode: :ignore_block} + ) do warning = {index, "redundant ignore-next-line inside ignore block"} %{ state - | coverage_buffer: [coverage_line | state.coverage_buffer], + | coverage: [nil | state.coverage], warnings: [warning | state.warnings] } end - defp process_next_line_marker(coverage_line, index, state = %{ignore_mode: :ignore_line}) do + defp process_next_line_marker( + _coverage_line, + index, + state = %{ignore_mode: :ignore_line} + ) do warning = {index, "duplicated ignore-next-line"} %{ state - | coverage: [state.coverage_buffer | state.coverage], - coverage_buffer: [coverage_line], + | coverage: [nil | state.coverage], warnings: [warning | state.warnings], last_marker_index: index } end - defp process_end_of_file(state = %{ignore_mode: :no_ignore, coverage_buffer: []}) do + defp process_end_of_file(state = %{ignore_mode: :no_ignore}) do state end defp process_end_of_file(state = %{ignore_mode: :ignore_line}) do warning = {state.last_marker_index, "redundant ignore-next-line at the end of file"} - %{ - state - | coverage: [state.coverage_buffer | state.coverage], - warnings: [warning | state.warnings] - } + %{state | warnings: [warning | state.warnings]} end defp process_end_of_file(state = %{ignore_mode: :ignore_block}) do warning = {state.last_marker_index, "ignore-start without a corresponding ignore-stop"} - %{ - state - | coverage: [state.coverage_buffer | state.coverage], - warnings: [warning | state.warnings] - } + %{state | warnings: [warning | state.warnings]} end end diff --git a/test/ignore_test.exs b/test/ignore_test.exs index 3364c733..311ff4e9 100644 --- a/test/ignore_test.exs +++ b/test/ignore_test.exs @@ -99,7 +99,7 @@ defmodule ExCoveralls.IgnoreTest do test "start marker without a stop marker is discarded with a warning" do info = Ignore.filter(@source_info) |> Enum.at(0) assert(info[:source] == @content) - assert(info[:coverage] == [0, 0, 0, nil, nil, nil, nil, 0, 0, nil, 0, 0, 0, 0]) + assert(info[:coverage] == [0, 0, 0, nil, nil, nil, nil, 0, 0, nil, nil, nil, nil, nil]) assert(info[:warnings] == [{9, "ignore-start without a corresponding ignore-stop"}]) end @@ -125,7 +125,7 @@ defmodule ExCoveralls.IgnoreTest do test "start marker followed by another start marker is discarded with a warning" do info = Ignore.filter(@source_info) |> Enum.at(0) assert(info[:source] == @content) - assert(info[:coverage] == [0, 0, 0, nil, 0, 0, nil, nil, nil, nil, 0, 0]) + assert(info[:coverage] == [0, 0, 0, nil, nil, nil, nil, nil, nil, nil, 0, 0]) assert(info[:warnings] == [{6, "unexpected ignore-start or missing previous ignore-stop"}]) end end