zf

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

line_endings.ex (1534B)


      1 defmodule Credo.Check.Consistency.LineEndings do
      2   use Credo.Check,
      3     run_on_all: true,
      4     base_priority: :high,
      5     tags: [:formatter],
      6     param_defaults: [
      7       force: nil
      8     ],
      9     explanations: [
     10       check: """
     11       Windows and Linux/macOS systems use different line-endings in files.
     12 
     13       It seems like a good idea not to mix these in the same codebase.
     14 
     15       While this is not necessarily a concern for the correctness of your code,
     16       you should use a consistent style throughout your codebase.
     17       """,
     18       params: [
     19         force: "Force a choice, values can be `:unix` or `:windows`."
     20       ]
     21     ]
     22 
     23   @collector Credo.Check.Consistency.LineEndings.Collector
     24 
     25   @doc false
     26   @impl true
     27   def run_on_all_source_files(exec, source_files, params) do
     28     @collector.find_and_append_issues(source_files, exec, params, &issues_for/3)
     29   end
     30 
     31   defp issues_for(expected, source_file, params) do
     32     first_line_with_issue = @collector.first_line_with_issue(expected, source_file)
     33 
     34     message =
     35       case expected do
     36         :unix ->
     37           "File is using windows line endings while most of the files use unix line endings."
     38 
     39         :windows ->
     40           "File is using unix line endings while most of the files use windows line endings."
     41       end
     42 
     43     trigger =
     44       case expected do
     45         :unix -> "\r\n"
     46         :windows -> "\n"
     47       end
     48 
     49     source_file
     50     |> IssueMeta.for(params)
     51     |> format_issue(message: message, line_no: first_line_with_issue, trigger: trigger)
     52     |> List.wrap()
     53   end
     54 end