Skip to content

Commit

Permalink
Require parentheses on zero arity functions
Browse files Browse the repository at this point in the history
@jjcarstens is a firm believer
  • Loading branch information
joshk committed Jan 11, 2025
1 parent b5f2a97 commit 90d5fab
Show file tree
Hide file tree
Showing 18 changed files with 37 additions and 40 deletions.
3 changes: 1 addition & 2 deletions .credo.exs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@
{Credo.Check.Readability.ModuleNames, []},
{Credo.Check.Readability.MultiAlias, []},
{Credo.Check.Readability.ParenthesesInCondition, []},
# Disabled as I'm not sure I agree with this one and it requires discussion
# {Credo.Check.Readability.ParenthesesOnZeroArityDefs, []},
{Credo.Check.Readability.ParenthesesOnZeroArityDefs, [parens: true]},
{Credo.Check.Readability.PipeIntoAnonymousFunctions, []},
{Credo.Check.Readability.PredicateFunctionNames, []},
{Credo.Check.Readability.PreferImplicitTry, []},
Expand Down
4 changes: 2 additions & 2 deletions lib/nerves_hub/accounts/remove_account.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ defmodule NervesHub.Accounts.RemoveAccount do
|> Repo.transaction()
end

defp query_org_users do
defp query_org_users() do
from(
org_user in OrgUser,
join: user in assoc(org_user, :user),
Expand Down Expand Up @@ -87,7 +87,7 @@ defmodule NervesHub.Accounts.RemoveAccount do
end)
end

defp truncated_utc_now do
defp truncated_utc_now() do
DateTime.truncate(DateTime.utc_now(), :second)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/nerves_hub/accounts/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ defmodule NervesHub.Accounts.User do
The time length that a password reset token is valid.
Passed to Timex.shift, so it just has to be a keyword list with :minutes, :hours, etc.
"""
def password_reset_window do
def password_reset_window() do
[hours: 8]
end

Expand Down
2 changes: 1 addition & 1 deletion lib/nerves_hub/devices/ca_certificate/csr.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule NervesHub.Devices.CACertificate.CSR do
after a user creates the CSR.
"""
@spec generate_code() :: csr_code()
def generate_code do
def generate_code() do
:crypto.strong_rand_bytes(32) |> Base.encode16()
end

Expand Down
2 changes: 1 addition & 1 deletion lib/nerves_hub/devices/metrics.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule NervesHub.Devices.Metrics do
"mem_used_percent"
]

def default_metrics, do: @default_metrics
def default_metrics(), do: @default_metrics

@doc """
Get all metrics for device
Expand Down
4 changes: 1 addition & 3 deletions lib/nerves_hub/extensions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ defmodule NervesHub.Extensions do
Get list of supported extensions as atoms with descriptive text.
"""
@spec list() :: [:geo | :health, ...]
def list do
@supported_extensions
end
def list(), do: @supported_extensions

@spec module(extension()) :: NervesHub.Extensions.Geo | NervesHub.Extensions.Health
def module(:health), do: NervesHub.Extensions.Health
Expand Down
2 changes: 1 addition & 1 deletion lib/nerves_hub/extensions/geo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule NervesHub.Extensions.Geo do
alias NervesHub.Devices

@impl NervesHub.Extensions
def description do
def description() do
"""
Reporting of GeoIP information or custom geo-location information sources
you've set up for your device.
Expand Down
2 changes: 1 addition & 1 deletion lib/nerves_hub/extensions/health.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule NervesHub.Extensions.Health do
require Logger

@impl NervesHub.Extensions
def description do
def description() do
"""
Reporting of fundamental device metrics, metadata, alarms and more.
Also supports custom metrics. Alarms require an alarm handler to be set.
Expand Down
2 changes: 1 addition & 1 deletion lib/nerves_hub/firmwares/upload/s3.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ defmodule NervesHub.Firmwares.Upload.S3 do
%{"s3_key" => Path.join([key_prefix(), Integer.to_string(org_id), filename])}
end

def bucket do
def bucket() do
Application.get_env(:nerves_hub, __MODULE__)[:bucket]
end

Expand Down
2 changes: 1 addition & 1 deletion lib/nerves_hub/products.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule NervesHub.Products do
@csv_certs_sep "\n\n"
@csv_header ["identifier", "description", "tags", "product", "org", "certificates"]

def __csv_header__, do: @csv_header
def __csv_header__(), do: @csv_header

@spec get_products_by_user_and_org(User.t(), Org.t()) :: [Product.t()]
def get_products_by_user_and_org(%User{id: user_id}, %Org{id: org_id}) do
Expand Down
6 changes: 3 additions & 3 deletions lib/nerves_hub/types.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule NervesHub.Types do
defmodule Tag do
@behaviour Ecto.Type

def type, do: {:array, :string}
def type(), do: {:array, :string}

def embed_as(_), do: :self

Expand Down Expand Up @@ -33,7 +33,7 @@ defmodule NervesHub.Types do
defmodule Resource do
@behaviour Ecto.Type

def type, do: :string
def type(), do: :string

def embed_as(_), do: :self

Expand Down Expand Up @@ -69,7 +69,7 @@ defmodule NervesHub.Types do

def load(resource), do: {:ok, String.to_existing_atom(resource)}

defp allowed_resources do
defp allowed_resources() do
[
"Elixir.NervesHub.Accounts.Org",
"Elixir.NervesHub.Accounts.User",
Expand Down
4 changes: 2 additions & 2 deletions lib/nerves_hub/views/email_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule NervesHub.EmailView do

import Phoenix.HTML

def base_url do
def base_url() do
config = Application.get_env(:nerves_hub, NervesHubWeb.Endpoint)

port =
Expand All @@ -21,7 +21,7 @@ defmodule NervesHub.EmailView do
Standard closing words.
"""

def closing do
def closing() do
"""
#{closing_message()}
Expand Down
30 changes: 15 additions & 15 deletions lib/nerves_hub_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ defmodule NervesHubWeb do
and import those modules here.
"""

def static_paths, do: ~w(assets fonts images favicon.ico robots.txt)
def static_paths(), do: ~w(assets fonts images favicon.ico robots.txt)

def plug do
def plug() do
quote do
import Plug.Conn
import Phoenix.Controller
end
end

def controller do
def controller() do
quote do
use Phoenix.Controller, namespace: NervesHubWeb
use Gettext, backend: NervesHubWeb.Gettext
Expand All @@ -50,7 +50,7 @@ defmodule NervesHubWeb do
end
end

def api_controller do
def api_controller() do
quote do
use Phoenix.Controller, namespace: NervesHubWeb
use Gettext, backend: NervesHubWeb.Gettext
Expand All @@ -71,7 +71,7 @@ defmodule NervesHubWeb do
end
end

def updated_live_view do
def updated_live_view() do
quote do
use NervesHubWeb.LiveView,
layout: {NervesHubWeb.LayoutView, :live},
Expand Down Expand Up @@ -110,7 +110,7 @@ defmodule NervesHubWeb do
end
end

def verified_routes do
def verified_routes() do
quote do
use Phoenix.VerifiedRoutes,
endpoint: NervesHubWeb.Endpoint,
Expand All @@ -119,15 +119,15 @@ defmodule NervesHubWeb do
end
end

def live_component do
def live_component() do
quote do
use Phoenix.LiveComponent

unquote(view_helpers())
end
end

def html do
def html() do
quote do
use Phoenix.Component

Expand All @@ -140,7 +140,7 @@ defmodule NervesHubWeb do
end
end

defp html_helpers do
defp html_helpers() do
quote do
# HTML escaping functionality
import Phoenix.HTML
Expand All @@ -156,7 +156,7 @@ defmodule NervesHubWeb do
end
end

def view do
def view() do
quote do
use Phoenix.View,
root: "lib/nerves_hub_web/templates",
Expand All @@ -183,7 +183,7 @@ defmodule NervesHubWeb do
end
end

def api_view do
def api_view() do
quote do
use Phoenix.View,
root: "lib/nerves_hub_web/templates",
Expand All @@ -206,7 +206,7 @@ defmodule NervesHubWeb do
end
end

def component do
def component() do
quote do
use Phoenix.Component

Expand All @@ -215,7 +215,7 @@ defmodule NervesHubWeb do
end
end

def router do
def router() do
quote do
use Phoenix.Router
import Plug.Conn
Expand All @@ -224,14 +224,14 @@ defmodule NervesHubWeb do
end
end

def channel do
def channel() do
quote do
use Phoenix.Channel
use Gettext, backend: NervesHubWeb.Gettext
end
end

defp view_helpers do
defp view_helpers() do
quote do
# Use all HTML functionality (forms, tags, etc)
use Phoenix.HTML
Expand Down
2 changes: 1 addition & 1 deletion lib/nerves_hub_web/live/dashboard/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ defmodule NervesHubWeb.Live.Dashboard.Index do
:ok
end

defp time do
defp time() do
System.monotonic_time(:millisecond)
end
end
2 changes: 1 addition & 1 deletion lib/nerves_hub_web/live/devices/settings.ex
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ defmodule NervesHubWeb.Live.Devices.Settings do
{:ok, socket}
end

defp extensions do
defp extensions() do
for extension <- Extensions.list(),
into: %{},
do: {extension, Extensions.module(extension).description()}
Expand Down
2 changes: 1 addition & 1 deletion lib/nerves_hub_web/live/org/products.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ defmodule NervesHubWeb.Live.Org.Products do
end
end

defp extensions do
defp extensions() do
for extension <- Extensions.list(),
into: %{},
do: {extension, Extensions.module(extension).description()}
Expand Down
2 changes: 1 addition & 1 deletion lib/nerves_hub_web/live/product/settings.ex
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ defmodule NervesHubWeb.Live.Product.Settings do
{:noreply, socket}
end

defp extensions do
defp extensions() do
for extension <- Extensions.list(),
into: %{},
do: {extension, Extensions.module(extension).description()}
Expand Down
4 changes: 2 additions & 2 deletions test/support/fixtures.ex
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,11 @@ defmodule NervesHub.Fixtures do
}
end

defp counter do
defp counter() do
System.unique_integer([:positive])
end

defp counter_in_alpha do
defp counter_in_alpha() do
counter()
|> Integer.to_string()
|> String.split("")
Expand Down

0 comments on commit 90d5fab

Please sign in to comment.