diff --git a/lib/credo/check/consistency/multi_alias_import_require_use.ex b/lib/credo/check/consistency/multi_alias_import_require_use.ex index 4dfa238e2..9327c2ee6 100644 --- a/lib/credo/check/consistency/multi_alias_import_require_use.ex +++ b/lib/credo/check/consistency/multi_alias_import_require_use.ex @@ -38,7 +38,7 @@ defmodule Credo.Check.Consistency.MultiAliasImportRequireUse do issue_locations = @collector.find_locations_not_matching(expected, source_file) Enum.map(issue_locations, fn line_no -> - format_issue(issue_meta, message: message_for(expected), line_no: line_no) + format_issue(issue_meta, message: message_for(expected), line_no: line_no, trigger: "") end) end diff --git a/lib/credo/check/consistency/tabs_or_spaces.ex b/lib/credo/check/consistency/tabs_or_spaces.ex index ece737cc2..bee9007da 100644 --- a/lib/credo/check/consistency/tabs_or_spaces.ex +++ b/lib/credo/check/consistency/tabs_or_spaces.ex @@ -39,10 +39,17 @@ defmodule Credo.Check.Consistency.TabsOrSpaces do lines_with_issues = @collector.find_locations_not_matching(expected, source_file) Enum.map(lines_with_issues, fn line_no -> - format_issue(issue_meta, message: message_for(expected), line_no: line_no) + format_issue(issue_meta, + message: message_for(expected), + line_no: line_no, + trigger: trigger_for(expected) + ) end) end + defp trigger_for(:spaces = _expected), do: "\t" + defp trigger_for(:tabs = _expected), do: " " + defp message_for(:spaces = _expected) do "File is using tabs while most of the files use spaces for indentation." end diff --git a/lib/credo/check/design/duplicated_code.ex b/lib/credo/check/design/duplicated_code.ex index fd75ebfa5..476c9e92f 100644 --- a/lib/credo/check/design/duplicated_code.ex +++ b/lib/credo/check/design/duplicated_code.ex @@ -257,6 +257,7 @@ defmodule Credo.Check.Design.DuplicatedCode do issue_meta, message: "Duplicate code found in #{filenames} (mass: #{node_mass}).", line_no: line_no, + trigger: {:__no_trigger__}, severity: Severity.compute(1 + Enum.count(other_nodes), 1) ) end diff --git a/lib/credo/check/readability/one_arity_function_in_pipe.ex b/lib/credo/check/readability/one_arity_function_in_pipe.ex index ec7167f7f..f9e0c4474 100644 --- a/lib/credo/check/readability/one_arity_function_in_pipe.ex +++ b/lib/credo/check/readability/one_arity_function_in_pipe.ex @@ -25,18 +25,19 @@ defmodule Credo.Check.Readability.OneArityFunctionInPipe do end defp traverse({:|>, _, [_, {name, meta, nil}]} = ast, issues, issue_meta) when is_atom(name) do - {ast, [issue(issue_meta, meta[:line]) | issues]} + {ast, [issue(issue_meta, meta[:line], name) | issues]} end defp traverse(ast, issues, _) do {ast, issues} end - defp issue(meta, line) do + defp issue(meta, line, name) do format_issue( meta, message: "One arity functions should have parentheses in pipes", - line_no: line + line_no: line, + trigger: to_string(name) ) end end diff --git a/lib/credo/check/readability/parentheses_on_zero_arity_defs.ex b/lib/credo/check/readability/parentheses_on_zero_arity_defs.ex index c044f6ce6..662e3fb2f 100644 --- a/lib/credo/check/readability/parentheses_on_zero_arity_defs.ex +++ b/lib/credo/check/readability/parentheses_on_zero_arity_defs.ex @@ -73,10 +73,10 @@ defmodule Credo.Check.Readability.ParenthesesOnZeroArityDefs do cond do parens? and not enforce_parens? -> - issues ++ [issue_for(issue_meta, line_no, :present)] + issues ++ [issue_for(issue_meta, name, line_no, :present)] not parens? and enforce_parens? -> - issues ++ [issue_for(issue_meta, line_no, :missing)] + issues ++ [issue_for(issue_meta, name, line_no, :missing)] true -> issues @@ -92,7 +92,7 @@ defmodule Credo.Check.Readability.ParenthesesOnZeroArityDefs do Credo.Backports.String.slice(line, skip..-1) end - defp issue_for(issue_meta, line_no, kind) do + defp issue_for(issue_meta, name, line_no, kind) do message = case kind do :present -> @@ -102,6 +102,6 @@ defmodule Credo.Check.Readability.ParenthesesOnZeroArityDefs do "Use parentheses () when defining a function which has no arguments." end - format_issue(issue_meta, message: message, line_no: line_no) + format_issue(issue_meta, message: message, line_no: line_no, trigger: to_string(name)) end end diff --git a/lib/credo/check/readability/redundant_blank_lines.ex b/lib/credo/check/readability/redundant_blank_lines.ex index 12132d894..6971ca123 100644 --- a/lib/credo/check/readability/redundant_blank_lines.ex +++ b/lib/credo/check/readability/redundant_blank_lines.ex @@ -43,7 +43,8 @@ defmodule Credo.Check.Readability.RedundantBlankLines do format_issue( issue_meta, message: "There should be no more than #{max_blank_lines} consecutive blank lines.", - line_no: line + line_no: line, + trigger: "" ) end diff --git a/lib/credo/check/readability/separate_alias_require.ex b/lib/credo/check/readability/separate_alias_require.ex index 10d0f50fa..6368b11ed 100644 --- a/lib/credo/check/readability/separate_alias_require.ex +++ b/lib/credo/check/readability/separate_alias_require.ex @@ -76,8 +76,12 @@ defmodule Credo.Check.Readability.SeparateAliasRequire do {ast, issues} end - defp issue_for(issue_meta, line_no, type) do - format_issue(issue_meta, message: message(type), line_no: line_no) + defp issue_for(issue_meta, line_no, macro_name) do + format_issue(issue_meta, + message: message(macro_name), + line_no: line_no, + trigger: to_string(macro_name) + ) end def message(:alias), do: "aliases should be consecutive within a file" diff --git a/lib/credo/check/readability/single_function_to_block_pipe.ex b/lib/credo/check/readability/single_function_to_block_pipe.ex index cfbb7d968..3ca6b758d 100644 --- a/lib/credo/check/readability/single_function_to_block_pipe.ex +++ b/lib/credo/check/readability/single_function_to_block_pipe.ex @@ -51,7 +51,7 @@ defmodule Credo.Check.Readability.SingleFunctionToBlockPipe do defp issue({:|>, meta, [arg, {marker, _case_meta, _case_args}]}, issue_meta) when marker in [:case, :if] do - if issue?(arg), do: issue_for(issue_meta, meta[:line]), else: nil + if issue?(arg), do: issue_for(issue_meta, meta[:line], marker), else: nil end defp issue(_, _), do: nil @@ -70,11 +70,12 @@ defmodule Credo.Check.Readability.SingleFunctionToBlockPipe do defp issue?(_), do: false - defp issue_for(issue_meta, line_no) do + defp issue_for(issue_meta, line_no, marker) do format_issue( issue_meta, message: "Avoid single pipes to a block", - line_no: line_no + line_no: line_no, + trigger: to_string(marker) ) end end diff --git a/lib/credo/check/readability/trailing_blank_line.ex b/lib/credo/check/readability/trailing_blank_line.ex index f5b2772d9..9485cb0b6 100644 --- a/lib/credo/check/readability/trailing_blank_line.ex +++ b/lib/credo/check/readability/trailing_blank_line.ex @@ -37,7 +37,8 @@ defmodule Credo.Check.Readability.TrailingBlankLine do format_issue( issue_meta, message: "There should be a final \\n at the end of each file.", - line_no: line_no + line_no: line_no, + trigger: {:__no_trigger__} ) end end diff --git a/lib/credo/check/readability/with_custom_tagged_tuple.ex b/lib/credo/check/readability/with_custom_tagged_tuple.ex index 3db9d26c1..2e61c0dbc 100644 --- a/lib/credo/check/readability/with_custom_tagged_tuple.ex +++ b/lib/credo/check/readability/with_custom_tagged_tuple.ex @@ -51,6 +51,7 @@ defmodule Credo.Check.Readability.WithCustomTaggedTuple do defp errors(source_file) do {_ast, errors} = Macro.prewalk(Credo.Code.ast(source_file), MapSet.new(), &traverse/2) + Enum.sort_by(errors, &{&1.line, &1.column}) end @@ -76,7 +77,7 @@ defmodule Credo.Check.Readability.WithCustomTaggedTuple do issue_meta, message: "Invalid usage of placeholder `#{inspect(error.placeholder)}` in with", line_no: error.line, - column: error.column + trigger: inspect(error.placeholder) ) end end diff --git a/lib/credo/check/readability/with_single_clause.ex b/lib/credo/check/readability/with_single_clause.ex index 2243a9533..fa6e3ead1 100644 --- a/lib/credo/check/readability/with_single_clause.ex +++ b/lib/credo/check/readability/with_single_clause.ex @@ -90,7 +90,8 @@ defmodule Credo.Check.Readability.WithSingleClause do format_issue(issue_meta, message: "`with` contains only one <- clause and an `else` branch, consider using `case` instead", - line_no: line + line_no: line, + trigger: "with" ) ] diff --git a/lib/credo/check/refactor/apply.ex b/lib/credo/check/refactor/apply.ex index 672bf8bad..8d7db635e 100644 --- a/lib/credo/check/refactor/apply.ex +++ b/lib/credo/check/refactor/apply.ex @@ -82,7 +82,8 @@ defmodule Credo.Check.Refactor.Apply do format_issue( issue_meta, message: "Avoid `apply/2` and `apply/3` when the number of arguments is known", - line_no: meta[:line] + line_no: meta[:line], + trigger: "apply" ) end end diff --git a/lib/credo/check/refactor/module_dependencies.ex b/lib/credo/check/refactor/module_dependencies.ex index 716e91726..b3831abcc 100644 --- a/lib/credo/check/refactor/module_dependencies.ex +++ b/lib/credo/check/refactor/module_dependencies.ex @@ -86,7 +86,7 @@ defmodule Credo.Check.Refactor.ModuleDependencies do else module_dependencies = get_dependencies(ast, dependency_namespaces) - issues_for_module(module_dependencies, max, issue_meta, meta) + issues_for_module(module_dependencies, max, issue_meta, meta, module_name) end {ast, issues ++ new_issues} @@ -105,19 +105,19 @@ defmodule Credo.Check.Refactor.ModuleDependencies do |> filter_namespaces(dependency_namespaces) end - defp issues_for_module(deps, max_deps, issue_meta, meta) when length(deps) > max_deps do + defp issues_for_module(deps, max_deps, issue_meta, meta, module_name) + when length(deps) > max_deps do [ format_issue( issue_meta, message: "Module has too many dependencies: #{length(deps)} (max is #{max_deps})", - trigger: deps, - line_no: meta[:line], - column_no: meta[:column] + trigger: module_name, + line_no: meta[:line] ) ] end - defp issues_for_module(_, _, _, _), do: [] + defp issues_for_module(_, _, _, _, _), do: [] # Resolve dependencies to full module names defp with_fullnames(dependencies, aliases) do diff --git a/lib/credo/check/refactor/pass_async_in_test_cases.ex b/lib/credo/check/refactor/pass_async_in_test_cases.ex index 05bd7e83b..649dcb76a 100644 --- a/lib/credo/check/refactor/pass_async_in_test_cases.ex +++ b/lib/credo/check/refactor/pass_async_in_test_cases.ex @@ -30,7 +30,7 @@ defmodule Credo.Check.Refactor.PassAsyncInTestCases do module_name = module_name_from(module_namespace) if String.ends_with?(module_name, "Case") and !Keyword.has_key?(options, :async) do - {ast, issues ++ [issue_for(ast, meta[:line], issue_meta)]} + {ast, issues ++ [issue_for(module_name, meta[:line], issue_meta)]} else {ast, issues} end diff --git a/lib/credo/check/refactor/redundant_with_clause_result.ex b/lib/credo/check/refactor/redundant_with_clause_result.ex index c1520c24f..57f5caa06 100644 --- a/lib/credo/check/refactor/redundant_with_clause_result.ex +++ b/lib/credo/check/refactor/redundant_with_clause_result.ex @@ -70,10 +70,14 @@ defmodule Credo.Check.Refactor.RedundantWithClauseResult do defp issue_for({clauses, body}, meta, issue_meta) do case {redundant?(List.last(clauses), body), length(clauses)} do {true, 1} -> - format_issue(issue_meta, message: @redundant_with, line_no: meta[:line]) + format_issue(issue_meta, message: @redundant_with, line_no: meta[:line], trigger: "with") {true, _length} -> - format_issue(issue_meta, message: @redundant_clause, line_no: meta[:line]) + format_issue(issue_meta, + message: @redundant_clause, + line_no: meta[:line], + trigger: "with" + ) _else -> nil diff --git a/lib/credo/check/refactor/with_clauses.ex b/lib/credo/check/refactor/with_clauses.ex index 4c67eb9b9..ed93b9065 100644 --- a/lib/credo/check/refactor/with_clauses.ex +++ b/lib/credo/check/refactor/with_clauses.ex @@ -83,12 +83,24 @@ defmodule Credo.Check.Refactor.WithClauses do end defp issue_if_not_starting_with_pattern_clause(_clauses, line, issue_meta) do - [format_issue(issue_meta, message: @message_first_clause_not_pattern, line_no: line)] + [ + format_issue(issue_meta, + message: @message_first_clause_not_pattern, + line_no: line, + trigger: "with" + ) + ] end defp issue_if_not_ending_with_pattern_clause(clauses, line, issue_meta) do if length(clauses) > 1 and not match?({:<-, _, _}, Enum.at(clauses, -1)) do - [format_issue(issue_meta, message: @message_last_clause_not_pattern, line_no: line)] + [ + format_issue(issue_meta, + message: @message_last_clause_not_pattern, + line_no: line, + trigger: "with" + ) + ] else [] end diff --git a/lib/credo/check/warning/lazy_logging.ex b/lib/credo/check/warning/lazy_logging.ex index 9b24209db..a7633ea6c 100644 --- a/lib/credo/check/warning/lazy_logging.ex +++ b/lib/credo/check/warning/lazy_logging.ex @@ -94,26 +94,27 @@ defmodule Credo.Check.Warning.LazyLogging do ignored_functions = Params.get(params, :ignore, __MODULE__) unless Enum.member?(ignored_functions, fun_name) do - issue_for_call(arguments, meta, issue_meta) + issue_for_call(arguments, meta, fun_name, issue_meta) end end - defp issue_for_call([{:<<>>, _, [_ | _]} | _] = _args, meta, issue_meta) do - issue_for(issue_meta, meta[:line]) + defp issue_for_call([{:<<>>, _, [_ | _]} | _] = _args, meta, fun_name, issue_meta) do + issue_for(issue_meta, meta[:line], fun_name) end - defp issue_for_call(_args, _meta, _issue_meta) do + defp issue_for_call(_args, _meta, _trigger, _issue_meta) do nil end defp logger_import?([{:__aliases__, _meta, [:Logger]}]), do: true defp logger_import?(_), do: false - defp issue_for(issue_meta, line_no) do + defp issue_for(issue_meta, line_no, trigger) do format_issue( issue_meta, message: "Prefer lazy Logger calls.", - line_no: line_no + line_no: line_no, + trigger: to_string(trigger) ) end end diff --git a/lib/credo/check/warning/missed_metadata_key_in_logger_config.ex b/lib/credo/check/warning/missed_metadata_key_in_logger_config.ex index 0d48eb684..9f36df390 100644 --- a/lib/credo/check/warning/missed_metadata_key_in_logger_config.ex +++ b/lib/credo/check/warning/missed_metadata_key_in_logger_config.ex @@ -160,10 +160,10 @@ defmodule Credo.Check.Warning.MissedMetadataKeyInLoggerConfig do defp logger_import?([{:__aliases__, _meta, [:Logger]}]), do: true defp logger_import?(_), do: false - defp issue_for(issue_meta, line_no, missed_keys) do + defp issue_for(issue_meta, line_no, [trigger | _] = missed_keys) do message = "Logger metadata key #{Enum.join(missed_keys, ", ")} not found in Logger config" - format_issue(issue_meta, message: message, line_no: line_no) + format_issue(issue_meta, message: message, line_no: line_no, trigger: to_string(trigger)) end defp find_metadata_keys(params) do diff --git a/lib/credo/check/warning/wrong_test_file_extension.ex b/lib/credo/check/warning/wrong_test_file_extension.ex index 9fa2abae6..df0d2d72b 100644 --- a/lib/credo/check/warning/wrong_test_file_extension.ex +++ b/lib/credo/check/warning/wrong_test_file_extension.ex @@ -34,7 +34,9 @@ defmodule Credo.Check.Warning.WrongTestFileExtension do defp issue_for(issue_meta) do format_issue( issue_meta, - message: "Test files should end with .exs" + message: "Test files should end with .exs", + line_no: 1, + trigger: "" ) end diff --git a/test/credo/check/readability/nested_function_calls_test.exs b/test/credo/check/readability/nested_function_calls_test.exs index e536fe715..577e0942f 100644 --- a/test/credo/check/readability/nested_function_calls_test.exs +++ b/test/credo/check/readability/nested_function_calls_test.exs @@ -1,7 +1,7 @@ defmodule Credo.Check.Readability.NestedFunctionCallsTest do use Credo.Test.Case - alias Credo.Check.Readability.NestedFunctionCalls + @described_check Credo.Check.Readability.NestedFunctionCalls # # cases NOT raising issues @@ -16,7 +16,7 @@ defmodule Credo.Check.Readability.NestedFunctionCallsTest do end """ |> to_source_file() - |> run_check(NestedFunctionCalls) + |> run_check(@described_check) |> refute_issues() end @@ -29,7 +29,7 @@ defmodule Credo.Check.Readability.NestedFunctionCallsTest do end """ |> to_source_file() - |> run_check(NestedFunctionCalls) + |> run_check(@described_check) |> refute_issues() end @@ -42,7 +42,7 @@ defmodule Credo.Check.Readability.NestedFunctionCallsTest do end """ |> to_source_file() - |> run_check(NestedFunctionCalls) + |> run_check(@described_check) |> refute_issues() end @@ -55,7 +55,7 @@ defmodule Credo.Check.Readability.NestedFunctionCallsTest do end """ |> to_source_file - |> run_check(NestedFunctionCalls) + |> run_check(@described_check) |> refute_issues() end @@ -68,7 +68,7 @@ defmodule Credo.Check.Readability.NestedFunctionCallsTest do end """ |> to_source_file - |> run_check(NestedFunctionCalls) + |> run_check(@described_check) |> refute_issues() end @@ -81,7 +81,7 @@ defmodule Credo.Check.Readability.NestedFunctionCallsTest do end """ |> to_source_file - |> run_check(NestedFunctionCalls) + |> run_check(@described_check) |> refute_issues() end @@ -94,7 +94,7 @@ defmodule Credo.Check.Readability.NestedFunctionCallsTest do end """ |> to_source_file() - |> run_check(NestedFunctionCalls) + |> run_check(@described_check) |> refute_issues() end @@ -109,7 +109,7 @@ defmodule Credo.Check.Readability.NestedFunctionCallsTest do end """ |> to_source_file() - |> run_check(NestedFunctionCalls) + |> run_check(@described_check) |> refute_issues() end @@ -122,7 +122,7 @@ defmodule Credo.Check.Readability.NestedFunctionCallsTest do end """ |> to_source_file() - |> run_check(NestedFunctionCalls) + |> run_check(@described_check) |> refute_issues() end @@ -146,7 +146,7 @@ defmodule Credo.Check.Readability.NestedFunctionCallsTest do end """ |> to_source_file() - |> run_check(NestedFunctionCalls) + |> run_check(@described_check) |> refute_issues() end @@ -163,7 +163,7 @@ defmodule Credo.Check.Readability.NestedFunctionCallsTest do end """ |> to_source_file() - |> run_check(NestedFunctionCalls) + |> run_check(@described_check) |> assert_issue() end @@ -176,7 +176,7 @@ defmodule Credo.Check.Readability.NestedFunctionCallsTest do end """ |> to_source_file() - |> run_check(NestedFunctionCalls) + |> run_check(@described_check) |> assert_issues() end @@ -189,7 +189,7 @@ defmodule Credo.Check.Readability.NestedFunctionCallsTest do end """ |> to_source_file() - |> run_check(NestedFunctionCalls, min_pipeline_length: 1) + |> run_check(@described_check, min_pipeline_length: 1) |> assert_issue() end @@ -202,7 +202,7 @@ defmodule Credo.Check.Readability.NestedFunctionCallsTest do end """ |> to_source_file() - |> run_check(NestedFunctionCalls, min_pipeline_length: 3) + |> run_check(@described_check, min_pipeline_length: 3) |> refute_issues() end @@ -219,7 +219,7 @@ defmodule Credo.Check.Readability.NestedFunctionCallsTest do end """ |> to_source_file() - |> run_check(NestedFunctionCalls) + |> run_check(@described_check) |> assert_issue() end end diff --git a/test/credo/check/readability/one_arity_function_in_pipe_test.exs b/test/credo/check/readability/one_arity_function_in_pipe_test.exs index c8ae2185e..285aa5717 100644 --- a/test/credo/check/readability/one_arity_function_in_pipe_test.exs +++ b/test/credo/check/readability/one_arity_function_in_pipe_test.exs @@ -62,7 +62,9 @@ defmodule Credo.Check.Readability.OneArityFunctionInPipeTest do """ |> to_source_file |> run_check(@described_check) - |> assert_issue() + |> assert_issue(fn issue -> + assert issue.trigger == "bar" + end) end test "it should report violations for missing parentheses" do diff --git a/test/credo/check/readability/parentheses_on_zero_arity_defs_test.exs b/test/credo/check/readability/parentheses_on_zero_arity_defs_test.exs index e5a21b51f..423bccc5e 100644 --- a/test/credo/check/readability/parentheses_on_zero_arity_defs_test.exs +++ b/test/credo/check/readability/parentheses_on_zero_arity_defs_test.exs @@ -53,7 +53,26 @@ defmodule Credo.Check.Readability.ParenthesesOnZeroArityDefsTest do |> refute_issues() end - test "it should NOT report a violation with no parens if parens: true /2" do + test "it should NOT report or crash on macros creating zero arity functions" do + """ + defmodule Credo.Sample.Module do + defmacro dynamic_methoder(attribute, value) do + quote do + def unquote(attribute)(), do: unquote(value) + end + end + end + """ + |> to_source_file + |> run_check(@described_check) + |> refute_issues() + end + + # + # cases raising issues + # + + test "it should report a violation with no parens if parens: true /2" do """ defmodule Mix.Tasks.Credo do def foo!, do: impl().foo!() @@ -65,10 +84,6 @@ defmodule Credo.Check.Readability.ParenthesesOnZeroArityDefsTest do |> assert_issues() end - # - # cases raising issues - # - test "it should report a violation with parens (by default)" do """ defmodule Mix.Tasks.Credo do @@ -79,7 +94,9 @@ defmodule Credo.Check.Readability.ParenthesesOnZeroArityDefsTest do """ |> to_source_file |> run_check(@described_check) - |> assert_issue() + |> assert_issue(fn issue -> + assert issue.trigger == "run" + end) end test "it should report a violation with no parens if parens: true" do @@ -92,21 +109,8 @@ defmodule Credo.Check.Readability.ParenthesesOnZeroArityDefsTest do """ |> to_source_file |> run_check(@described_check, parens: true) - |> assert_issue() - end - - test "it should not crash on macros creating zero arity functions" do - """ - defmodule Credo.Sample.Module do - defmacro dynamic_methoder(attribute, value) do - quote do - def unquote(attribute)(), do: unquote(value) - end - end - end - """ - |> to_source_file - |> run_check(@described_check) - |> refute_issues() + |> assert_issue(fn issue -> + assert issue.trigger == "run" + end) end end diff --git a/test/credo/check/readability/separate_alias_require_test.exs b/test/credo/check/readability/separate_alias_require_test.exs index caf70e083..06fd56cd1 100644 --- a/test/credo/check/readability/separate_alias_require_test.exs +++ b/test/credo/check/readability/separate_alias_require_test.exs @@ -183,6 +183,9 @@ defmodule Credo.Check.Readability.SeparateAliasImportRequireUseTest do """ |> to_source_file |> run_check(@described_check) - |> assert_issue() + |> assert_issue(fn issue -> + assert issue.line_no == 11 + assert issue.trigger == "alias" + end) end end diff --git a/test/credo/check/readability/with_custom_tagged_tuple_test.exs b/test/credo/check/readability/with_custom_tagged_tuple_test.exs index b30bc8582..68e7f7f97 100644 --- a/test/credo/check/readability/with_custom_tagged_tuple_test.exs +++ b/test/credo/check/readability/with_custom_tagged_tuple_test.exs @@ -43,10 +43,13 @@ defmodule Credo.Check.Readability.WithCustomTaggedTupleTest do |> to_source_file() |> run_check(@described_check) |> assert_issues(fn issues -> - issue_messages = Enum.map(issues, & &1.message) + [issue1, issue2] = issues - assert Enum.member?(issue_messages, "Invalid usage of placeholder `:resource` in with") - assert Enum.member?(issue_messages, "Invalid usage of placeholder `:authz` in with") + assert issue1.message == "Invalid usage of placeholder `:resource` in with" + assert issue1.trigger == ":resource" + + assert issue2.message == "Invalid usage of placeholder `:authz` in with" + assert issue2.trigger == ":authz" end) end end diff --git a/test/credo/check/refactor/apply_test.exs b/test/credo/check/refactor/apply_test.exs index 947828712..6748be73e 100644 --- a/test/credo/check/refactor/apply_test.exs +++ b/test/credo/check/refactor/apply_test.exs @@ -204,6 +204,8 @@ defmodule Credo.Check.Refactor.ApplyTest do """ |> to_source_file |> run_check(@described_check) - |> assert_issue() + |> assert_issue(fn issue -> + assert issue.trigger == "apply" + end) end end diff --git a/test/credo/check/refactor/module_dependencies_test.exs b/test/credo/check/refactor/module_dependencies_test.exs index a6760232c..4e5e3b19e 100644 --- a/test/credo/check/refactor/module_dependencies_test.exs +++ b/test/credo/check/refactor/module_dependencies_test.exs @@ -107,6 +107,8 @@ defmodule Credo.Check.Refactor.ModuleDependenciesTest do """ |> to_source_file |> run_check(@described_check) - |> assert_issue() + |> assert_issue(fn issue -> + assert issue.trigger == "CredoSampleModule" + end) end end diff --git a/test/credo/check/refactor/redundant_with_clause_result_test.exs b/test/credo/check/refactor/redundant_with_clause_result_test.exs index 476404d8c..30b845f9e 100644 --- a/test/credo/check/refactor/redundant_with_clause_result_test.exs +++ b/test/credo/check/refactor/redundant_with_clause_result_test.exs @@ -110,6 +110,7 @@ defmodule Credo.Check.Refactor.RedundantWithClauseResultTest do |> to_source_file |> run_check(@described_check) |> assert_issue(fn issue -> + assert issue.line_no == 2 assert issue.message == "the last clause in `with` is redundant" end) end @@ -125,7 +126,9 @@ defmodule Credo.Check.Refactor.RedundantWithClauseResultTest do |> to_source_file |> run_check(@described_check) |> assert_issue(fn issue -> + assert issue.line_no == 2 assert issue.message == "the `with` statement is redundant" + assert issue.trigger == "with" end) end end diff --git a/test/credo/check/warning/lazy_logging_test.exs b/test/credo/check/warning/lazy_logging_test.exs index 579240385..98a5caa79 100644 --- a/test/credo/check/warning/lazy_logging_test.exs +++ b/test/credo/check/warning/lazy_logging_test.exs @@ -135,6 +135,8 @@ defmodule Credo.Check.Warning.LazyLoggingTest do """ |> to_source_file |> run_check(@described_check) - |> assert_issue() + |> assert_issue(fn issue -> + assert issue.trigger == "debug" + end) end end diff --git a/test/credo/check/warning/missed_metadata_key_in_logger_config_test.exs b/test/credo/check/warning/missed_metadata_key_in_logger_config_test.exs index 89bf76bb9..a8d242d62 100644 --- a/test/credo/check/warning/missed_metadata_key_in_logger_config_test.exs +++ b/test/credo/check/warning/missed_metadata_key_in_logger_config_test.exs @@ -168,6 +168,8 @@ defmodule Credo.Check.Warning.MissedMetadataKeyInLoggerConfigTest do """ |> to_source_file |> run_check(@described_check) - |> assert_issue() + |> assert_issue(fn issue -> + assert issue.trigger == "key" + end) end end