zf

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

semicolons.ex (1442B)


      1 defmodule Credo.Check.Readability.Semicolons do
      2   use Credo.Check,
      3     base_priority: :high,
      4     tags: [:formatter],
      5     explanations: [
      6       check: """
      7       Don't use ; to separate statements and expressions.
      8       Statements and expressions should be separated by lines.
      9 
     10           # preferred
     11 
     12           a = 1
     13           b = 2
     14 
     15           # NOT preferred
     16 
     17           a = 1; b = 2
     18 
     19       Like all `Readability` issues, this one is not a technical concern.
     20       But you can improve the odds of others reading and liking your code by making
     21       it easier to follow.
     22       """
     23     ]
     24 
     25   @doc false
     26   @impl true
     27   # TODO: consider for experimental check front-loader (tokens)
     28   def run(%SourceFile{} = source_file, params) do
     29     issue_meta = IssueMeta.for(source_file, params)
     30 
     31     source_file
     32     |> Credo.Code.to_tokens()
     33     |> collect_issues([], issue_meta)
     34   end
     35 
     36   defp collect_issues([], acc, _issue_meta), do: acc
     37 
     38   defp collect_issues([{:";", {line_no, column1, _}} | rest], acc, issue_meta) do
     39     acc = [issue_for(issue_meta, line_no, column1) | acc]
     40     collect_issues(rest, acc, issue_meta)
     41   end
     42 
     43   defp collect_issues([_ | rest], acc, issue_meta), do: collect_issues(rest, acc, issue_meta)
     44 
     45   defp issue_for(issue_meta, line_no, column) do
     46     format_issue(
     47       issue_meta,
     48       message: "Don't use ; to separate statements and expressions",
     49       line_no: line_no,
     50       column: column,
     51       trigger: ";"
     52     )
     53   end
     54 end