zf

zenflows testing
git clone https://s.sonu.ch/~srfsh/zf.git
Log | Files | Refs | Submodules | README | LICENSE

collector.ex (822B)


      1 defmodule Credo.Check.Consistency.LineEndings.Collector do
      2   @moduledoc false
      3 
      4   use Credo.Check.Consistency.Collector
      5 
      6   def collect_matches(source_file, _params) do
      7     source_file
      8     |> SourceFile.lines()
      9     # remove the last line since it behaves differently on windows and linux
     10     # and apparently does not help determining line endings (see #965)
     11     |> List.delete_at(-1)
     12     |> Enum.reduce(%{}, fn line, stats ->
     13       Map.update(stats, line_ending(line), 1, &(&1 + 1))
     14     end)
     15   end
     16 
     17   def first_line_with_issue(expected, source_file) do
     18     {line_no, _} =
     19       source_file
     20       |> SourceFile.lines()
     21       |> Enum.find(&(line_ending(&1) != expected))
     22 
     23     line_no
     24   end
     25 
     26   defp line_ending({_line_no, line}) do
     27     if String.ends_with?(line, "\r") do
     28       :windows
     29     else
     30       :unix
     31     end
     32   end
     33 end