Skip to content
Permalink
Browse files

Add WithCustomTaggedTuples check

  • Loading branch information
rrrene committed Feb 13, 2020
1 parent f5bca5f commit 3d1a394a65e965ad0bff4af0d46a634b4adc5a62
@@ -163,7 +163,7 @@
{Credo.Check.Readability.MultiAlias, false},
{Credo.Check.Readability.Specs, false},
{Credo.Check.Readability.SinglePipe, false},
{Credo.Check.Readability.WithTaggedTuple, false},
{Credo.Check.Readability.WithCustomTaggedTuple, false},
{Credo.Check.Refactor.ABCSize, false},
{Credo.Check.Refactor.AppendSingleItem, false},
{Credo.Check.Refactor.DoubleBooleanNegation, false},
@@ -1,4 +1,4 @@
defmodule Credo.Check.Readability.WithTaggedTuple do
defmodule Credo.Check.Readability.WithCustomTaggedTuple do
@moduledoc false

@checkdoc """
@@ -0,0 +1,44 @@
defmodule Credo.Check.Readability.WithCustomTaggedTupleTest do
use Credo.TestHelper

@described_check Credo.Check.Readability.WithCustomTaggedTuple

test "it should NOT report violation" do
"""
defmodule Test do
def run(user, resource) do
with {:ok, resource} <- Resource.fetch(user),
:ok <- Resource.authorize(resource, user),
do: SomeMod.do_something(resource)
end
end
"""
|> to_source_file()
|> run_check(@described_check)
|> refute_issues()
end

test "it should report a violation" do
"""
defmodule Test do
def run(user, resource) do
with {:resource, {:ok, resource}} <- {:resource, Resource.fetch(user)},
{:authz, :ok} <- {:authz, Resource.authorize(resource, user)} do
SomeMod.do_something(resource)
else
{:resource, _} -> {:error, :not_found}
{:authz, _} -> {:error, :unauthorized}
end
end
end
"""
|> to_source_file()
|> run_check(@described_check)
|> assert_issues(fn issues ->
issue_messages = Enum.map(issues, & &1.message)

assert Enum.member?(issue_messages, "Invalid usage of placeholder `:resource` in with")
assert Enum.member?(issue_messages, "Invalid usage of placeholder `:authz` in with")
end)
end
end

This file was deleted.

0 comments on commit 3d1a394

Please sign in to comment.
You can’t perform that action at this time.