Fix predicate function naming conventions

Rename predicate functions to follow Elixir style guide:
- Remove 'is_' prefix from predicate function names
- 'is_' prefix is reserved for guard-safe functions

Changes:
- ip_geolocation.ex: is_private_ip? → private_ip?
- ip_geolocation.ex: is_172_private_range? → in_172_private_range?
- leader_election.ex: is_pid_alive? → pid_alive?

Fixes 3 Credo code readability issues.
All Credo code readability issues now resolved.
This commit is contained in:
Graham McIntire 2026-02-09 12:42:07 -06:00
parent c8bd85565c
commit 5f369a3bed
No known key found for this signature in database
2 changed files with 7 additions and 7 deletions

View file

@ -205,7 +205,7 @@ defmodule Aprsme.Cluster.LeaderElection do
end
defp check_pid_liveness(pid, pid_node) do
if is_pid_alive?(pid, pid_node) do
if pid_alive?(pid, pid_node) do
:ok
else
reason = if pid_node == node(), do: "dead local process", else: "dead remote process"
@ -216,11 +216,11 @@ defmodule Aprsme.Cluster.LeaderElection do
cleanup_registration("problematic process #{inspect(pid)}")
end
defp is_pid_alive?(pid, pid_node) when pid_node == node() do
defp pid_alive?(pid, pid_node) when pid_node == node() do
Process.alive?(pid)
end
defp is_pid_alive?(pid, pid_node) do
defp pid_alive?(pid, pid_node) do
if :rpc.call(pid_node, Process, :alive?, [pid]) do
true
else

View file

@ -128,24 +128,24 @@ defmodule AprsmeWeb.Plugs.IPGeolocation do
end
defp valid_ip_for_geolocation?(ip) when is_binary(ip) do
not is_private_ip?(ip)
not private_ip?(ip)
end
defp valid_ip_for_geolocation?(_), do: false
defp is_private_ip?(ip) do
defp private_ip?(ip) do
cond do
String.starts_with?(ip, "127.") -> true
String.starts_with?(ip, "::1") -> true
String.starts_with?(ip, "10.") -> true
String.starts_with?(ip, "192.168.") -> true
String.starts_with?(ip, "172.") -> is_172_private_range?(ip)
String.starts_with?(ip, "172.") -> in_172_private_range?(ip)
true -> false
end
end
# Check if IP is in 172.16.0.0/12 range (172.16.0.0 - 172.31.255.255)
defp is_172_private_range?(ip) do
defp in_172_private_range?(ip) do
case String.split(ip, ".") do
["172", second_octet | _] ->
case Integer.parse(second_octet) do