@@ -221,6 +221,135 @@ defmodule Credo.Check.Consistency.UnusedVariableNamesTest do
221221 end )
222222 end
223223
224+ test "it should report a violation for different naming schemes in a two elem tuple match (expects meaningful)" do
225+ [
226+ """
227+ defmodule Credo.SampleOne do
228+ defmodule Foo do
229+ def bar(x1, x2) do
230+ {_a, _b} = x1
231+ {_c, _} = x2
232+ end
233+ end
234+ end
235+ """ ,
236+ """
237+ defmodule Credo.SampleTwo do
238+ defmodule Foo do
239+ def bar(x1, x2) do
240+ with {:ok, _} <- x1,
241+ {:ok, _b} <- x2, do: :ok
242+ end
243+ end
244+ end
245+ """
246+ ]
247+ |> to_source_files ( )
248+ |> run_check ( @ described_check )
249+ |> assert_issues ( fn issues ->
250+ assert length ( issues ) == 2
251+
252+ assert Enum . find ( issues , & match? ( % { trigger: "_" , line_no: 5 } , & 1 ) )
253+ assert Enum . find ( issues , & match? ( % { trigger: "_" , line_no: 4 } , & 1 ) )
254+ end )
255+ end
256+
257+ test "it should report a violation for different naming schemes with a map match (expects meaningful)" do
258+ [
259+ """
260+ defmodule Credo.SampleOne do
261+ defmodule Foo do
262+ def bar(%{a: _a, b: _b, c: _}) do
263+ :ok
264+ end
265+ end
266+ end
267+ """ ,
268+ """
269+ defmodule Credo.SampleTwo do
270+ defmodule Foo do
271+ def bar(map) do
272+ case map do
273+ %{a: _} -> :ok
274+ _map -> :error
275+ end
276+ end
277+ end
278+ end
279+ """
280+ ]
281+ |> to_source_files ( )
282+ |> run_check ( @ described_check )
283+ |> assert_issues ( fn issues ->
284+ assert length ( issues ) == 2
285+
286+ assert Enum . find ( issues , & match? ( % { trigger: "_" , line_no: 3 } , & 1 ) )
287+ assert Enum . find ( issues , & match? ( % { trigger: "_" , line_no: 5 } , & 1 ) )
288+ end )
289+ end
290+
291+ test "it should report a violation for different naming schemes with a list match (expects meaningful)" do
292+ [
293+ """
294+ defmodule Credo.SampleOne do
295+ defmodule Foo do
296+ def bar(list) do
297+ case list do
298+ [] -> :empty
299+ [head | _] -> head
300+ end
301+ end
302+ end
303+ end
304+ """ ,
305+ """
306+ defmodule Credo.SampleTwo do
307+ defmodule Foo do
308+ def bar([_a, _b | rest]) do
309+ rest
310+ end
311+ end
312+ end
313+ """
314+ ]
315+ |> to_source_files ( )
316+ |> run_check ( @ described_check )
317+ |> assert_issue ( fn issue ->
318+ assert "_" == issue . trigger
319+ assert 6 == issue . line_no
320+ end )
321+ end
322+
323+ test "it should report a violation for different naming schemes with a macro (expects meaningful)" do
324+ [
325+ """
326+ defmodule Credo.SampleOne do
327+ defmodule Foo do
328+ defmacro __using__(_) do
329+ end
330+ end
331+
332+ def bar(_opts) do
333+ end
334+ end
335+ """ ,
336+ """
337+ defmodule Credo.SampleTwo do
338+ defmodule Foo do
339+ defmacrop bar(_opts) do
340+ end
341+ end
342+ end
343+ """
344+ ]
345+ |> to_source_files ( )
346+ |> run_check ( @ described_check )
347+ |> assert_issue ( fn issue ->
348+ assert "_" == issue . trigger
349+ assert 3 == issue . line_no
350+ end )
351+ end
352+
224353 test "it should report a violation for naming schemes other than the forced one" do
225354 [
226355 """
0 commit comments