zf

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

collector.ex (863B)


      1 defmodule Credo.Check.Consistency.TabsOrSpaces.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     |> Enum.reduce(%{}, fn line, stats ->
     10       match = indentation(line)
     11 
     12       if match do
     13         Map.update(stats, match, 1, &(&1 + 1))
     14       else
     15         stats
     16       end
     17     end)
     18   end
     19 
     20   def find_locations_not_matching(expected, source_file) do
     21     source_file
     22     |> SourceFile.lines()
     23     |> List.foldr([], fn {line_no, _} = line, line_nos ->
     24       if indentation(line) && indentation(line) != expected do
     25         [line_no | line_nos]
     26       else
     27         line_nos
     28       end
     29     end)
     30   end
     31 
     32   defp indentation({_line_no, "  " <> _line}), do: :spaces
     33   defp indentation({_line_no, "\t" <> _line}), do: :tabs
     34   defp indentation({_, _}), do: nil
     35 end