Document 'open_browser' credo check
Could we document how to add a basic custom credo warning for open_browser?
Or even add a ready-to-use check to this library?
The following is my crude attempt, I'm sure it can be vastly improved:
defmodule MyProject.Credo.NoOpenBrowser do
@moduledoc false
use Credo.Check,
base_priority: :normal,
category: :warning
def run(source_file, params \\ []) do
issue_meta = IssueMeta.for(source_file, params)
Credo.Code.prewalk(source_file, &traverse(&1, &2, issue_meta))
end
defp traverse({:open_browser, meta, _} = ast, issues, issue_meta) do
{ast, issues ++ [issue_for(meta[:line], issue_meta)]}
end
defp traverse(ast, issues, _issue_meta) do
{ast, issues}
end
defp issue_for(line_no, issue_meta) do
format_issue(
issue_meta,
message: "There should be no `open_browser` calls.",
line_no: line_no
)
end
end
I think that's a really cool idea! I wouldn't mind that being documented in the docs (maybe by the open_browser docs) or included in the library. I wonder... is there prior art here that we can lean on? Do other libraries create their own custom credo checks? (I can't recall using one from a library. Typically use the standard stuff + things we roll on our own).
The only other non-Credo check I've used is excellent_migrations.
Can't think of any other prior art off the top of my head.
@ftes is this Credo check something you're still interested in? If so, I think we could put one into the codebase itself (happy to review a PR 😄 ) and document how to use it. If you're not interested anymore, I'll go ahead and close this.