@@ -204,6 +204,7 @@ defmodule Credo.Test.Case do
204204 |> run_check(MyProject.MyCheck, foo_parameter: "bar")
205205 """
206206 def run_check ( source_files , check , params \\ [ ] ) do
207+ Process . put ( :credo_test_source_files , source_files )
207208 issues = CheckRunner . run_check ( source_files , check , params )
208209
209210 check_on_malformed_issues ( source_files , issues )
@@ -247,18 +248,54 @@ defmodule Credo.Test.Case do
247248 found trigger is not the given trigger:
248249 actual: #{ inspect ( actual_trigger , pretty: true ) }
249250 expected: #{ inspect ( trigger , pretty: true ) }
251+
252+ #{ get_issue_inline ( issue ) }
250253 """ )
251254 end
252255 end
253256 end
254257
255- defp get_source_line ( source_files , % Credo.Issue { } = issue ) do
258+ @ doc false
259+ def test_source_files? do
260+ test_source_files ( ) != [ ]
261+ end
262+
263+ @ doc false
264+ def test_source_files do
265+ Process . get ( :credo_test_source_files , [ ] )
266+ end
267+
268+ @ doc false
269+ def get_issue_inline ( issue ) do
270+ source_files = test_source_files ( )
271+ source_line = get_source_line ( source_files , issue )
272+
273+ marker =
274+ if issue . column && issue . trigger != Credo.Issue . no_trigger ( ) do
275+ String . duplicate ( " " , issue . column - 1 ) <>
276+ String . duplicate ( "^" , String . length ( to_string ( issue . trigger ) ) )
277+ else
278+ ""
279+ end
280+
281+ """
282+ #{ source_line }
283+ #{ marker }
284+ """
285+ end
286+
287+ defp get_source_line ( source_files , % Credo.Issue { } = issue ) when is_list ( source_files ) do
256288 source_files
257289 |> find_source_file ( issue )
258290 |> Credo.SourceFile . line_at ( issue . line_no )
259291 end
260292
261- defp find_source_file ( source_files , % Credo.Issue { filename: filename } ) do
293+ defp get_source_line ( % Credo.SourceFile { } = source_file , % Credo.Issue { } = issue ) do
294+ Credo.SourceFile . line_at ( source_file , issue . line_no )
295+ end
296+
297+ defp find_source_file ( source_files , % Credo.Issue { filename: filename } )
298+ when is_list ( source_files ) do
262299 Enum . find ( source_files , & ( & 1 . filename == filename ) ) || raise "Could not find source file"
263300 end
264301
0 commit comments