From 3a65ecb2fd74a990dd86d27087fd2d683f68b4cd Mon Sep 17 00:00:00 2001 From: Nikola Jichev Date: Sun, 28 Apr 2024 16:43:20 +0300 Subject: [PATCH] Fix formatting and warning --- .../code_action/remove_debugger.ex | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/next_ls/extensions/credo_extension/code_action/remove_debugger.ex b/lib/next_ls/extensions/credo_extension/code_action/remove_debugger.ex index fb9d6623..281f4cfe 100644 --- a/lib/next_ls/extensions/credo_extension/code_action/remove_debugger.ex +++ b/lib/next_ls/extensions/credo_extension/code_action/remove_debugger.ex @@ -14,6 +14,7 @@ defmodule NextLS.CredoExtension.CodeAction.RemoveDebugger do def new(%Diagnostic{} = diagnostic, text, uri) do range = diagnostic.range + with {:ok, ast, comments} <- parse(text), {:ok, debugger_node} <- find_debugger(ast, range) do indent = EditHelpers.get_indent(text, range.start.line) @@ -74,16 +75,18 @@ defmodule NextLS.CredoExtension.CodeAction.RemoveDebugger do end end) - result = Enum.min_by(results, fn node -> - range = Sourceror.get_range(node) + result = + Enum.min_by(results, fn node -> + range = Sourceror.get_range(node) - pos.start[:column] - range.start[:column] + range.end[:column] - pos.end[:column] - end) + pos.start[:column] - range.start[:column] + range.end[:column] - pos.end[:column] + end) - result = Enum.find(results, result, fn - {:|>, _, [_first, ^result]} -> true - _ -> false - end) + result = + Enum.find(results, result, fn + {:|>, _, [_first, ^result]} -> true + _ -> false + end) case result do nil -> {:error, "could find a debugger to remove"} @@ -118,8 +121,7 @@ defmodule NextLS.CredoExtension.CodeAction.RemoveDebugger do defp matches_debug?({:dbg, _, _}), do: true - defp matches_debug?({{:., _, [{:__aliases__, _, [:IO]}, f]}, _, _}) when f in [:puts, :inspect], - do: true + defp matches_debug?({{:., _, [{:__aliases__, _, [:IO]}, f]}, _, _}) when f in [:puts, :inspect], do: true defp matches_debug?({{:., _, [{:__aliases__, _, [:IEx]}, :pry]}, _, _}), do: true defp matches_debug?({{:., _, [{:__aliases__, _, [:Mix]}, :env]}, _, _}), do: true @@ -132,9 +134,6 @@ defmodule NextLS.CredoExtension.CodeAction.RemoveDebugger do defp remove_debugger({:dbg, _, [arg | _]}), do: arg defp remove_debugger(_node), do: {:__block__, [], []} - defp pipe?({:|>, _, _}), do: true - defp pipe?(_), do: false - defp make_title({_, ctx, _} = node), do: "Remove `#{format_node(node)}` #{ctx[:line]}:#{ctx[:column]}" defp format_node({:|>, _, [_arg, function]}), do: format_node(function)