Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Enable Dialyzer and Credo in CI (#2315)

Uku Taht8bdbabbdad02
diff --git a/.github/workflows/elixir.yml b/.github/workflows/elixir.yml
index be302f79e9..b523cb86ac 100644
--- a/.github/workflows/elixir.yml
+++ b/.github/workflows/elixir.yml
@@ -40,7 +40,9 @@ jobs:
--health-retries 5
steps:
- - uses: actions/checkout@v2
+ - uses: actions/checkout@v3
+ with:
+ fetch-depth: 0
- name: Read .tool-versions
uses: marocchino/tool-versions-action@v1
id: versions
@@ -66,11 +68,11 @@ jobs:
run: mix compile --warnings-as-errors --all-warnings
- name: Generate tracker files
run: npm run deploy --prefix ./tracker
+ - name: Check Credo Warnings
+ run: mix credo diff --from-git-merge-base origin/master
- name: Run tests
run: mix test
- #- name: Check Dialyzer
- # run: mix dialyzer <-- false negatives
- - name: Check Credo Warnings
- run: mix credo --strict --only warning --ignore Consistency
+ - name: Check Dialyzer
+ run: mix dialyzer
env:
MIX_ENV: test
diff --git a/lib/plausible/billing/billing.ex b/lib/plausible/billing/billing.ex
index 70a1e05933..04d5ef331b 100644
--- a/lib/plausible/billing/billing.ex
+++ b/lib/plausible/billing/billing.ex
@@ -13,12 +13,10 @@ defmodule Plausible.Billing do
end
defp active_subscription_query(user_id) do
- from(
- s in Subscription,
+ from s in Subscription,
where: s.user_id == ^user_id and s.status == "active",
order_by: [desc: s.inserted_at],
limit: 1
- )
end
def subscription_created(params) do
@@ -47,7 +45,7 @@ defmodule Plausible.Billing do
Repo.get(Plausible.Auth.User, subscription.user_id)
|> Map.put(:subscription, subscription)
- {:ok, user}
+ user
|> maybe_remove_grace_period
|> check_lock_status
|> maybe_adjust_api_key_limits
@@ -251,12 +249,13 @@ defmodule Plausible.Billing do
defp has_active_enterprise_subscription(user) do
Plausible.Repo.exists?(
- from s in Plausible.Billing.Subscription,
+ from(s in Plausible.Billing.Subscription,
join: e in Plausible.Billing.EnterprisePlan,
on: s.user_id == e.user_id and s.paddle_plan_id == e.paddle_plan_id,
where: s.user_id == ^user.id,
where: s.paddle_plan_id == ^user.enterprise_plan.paddle_plan_id,
where: s.status == "active"
+ )
)
end
@@ -278,7 +277,7 @@ defmodule Plausible.Billing do
defp present?(nil), do: false
defp present?(_), do: true
- defp maybe_remove_grace_period({:ok, user}) do
+ defp maybe_remove_grace_period(%Plausible.Auth.User{} = user) do
alias Plausible.Auth.GracePeriod
case user.grace_period do
@@ -298,8 +297,6 @@ defmodule Plausible.Billing do
end
end
- defp maybe_remove_grace_period(err), do: err
-
defp check_lock_status({:ok, user}) do
Plausible.Billing.SiteLocker.check_sites_for(user)
{:ok, user}
diff --git a/lib/plausible/billing/subscription.ex b/lib/plausible/billing/subscription.ex
index 806b217e45..b2dcfcca2d 100644
--- a/lib/plausible/billing/subscription.ex
+++ b/lib/plausible/billing/subscription.ex
@@ -1,7 +1,10 @@
defmodule Plausible.Billing.Subscription do
+ @moduledoc false
use Ecto.Schema
import Ecto.Changeset
+ @type t() :: %__MODULE__{}
+
@required_fields [
:paddle_subscription_id,
:paddle_plan_id,
diff --git a/lib/plausible/stats/base.ex b/lib/plausible/stats/base.ex
index c9b70223bc..b381a9165b 100644
--- a/lib/plausible/stats/base.ex
+++ b/lib/plausible/stats/base.ex
@@ -3,6 +3,8 @@ defmodule Plausible.Stats.Base do
alias Plausible.Stats.{Query, Filters}
import Ecto.Query
+ # Ecto typespec has not been updated for this PR: https://github.com/elixir-ecto/ecto/pull/3592
+ @dialyzer {:nowarn_function, add_sample_hint: 2}
@no_ref "Direct / None"
def base_event_query(site, query) do
diff --git a/lib/plausible_web/controllers/stats_controller.ex b/lib/plausible_web/controllers/stats_controller.ex
index 8a4e7d9906..fc99b47729 100644
--- a/lib/plausible_web/controllers/stats_controller.ex
+++ b/lib/plausible_web/controllers/stats_controller.ex
@@ -46,7 +46,7 @@ defmodule PlausibleWeb.StatsController do
alias Plausible.Stats.{Query, Filters}
alias PlausibleWeb.Api
- plug PlausibleWeb.AuthorizeSiteAccess when action in [:stats, :csv_export]
+ plug(PlausibleWeb.AuthorizeSiteAccess when action in [:stats, :csv_export])
def stats(%{assigns: %{site: site}} = conn, _params) do
stats_start_date = Plausible.Sites.stats_start_date(site)
@@ -106,7 +106,7 @@ defmodule PlausibleWeb.StatsController do
|> Enum.join()
filename =
- "Plausible export #{params["domain"]} #{Timex.format!(query.date_range.first, "{ISOdate} ")} to #{Timex.format!(query.date_range.last, "{ISOdate} ")}.zip"
+ 'Plausible export #{params["domain"]} #{Timex.format!(query.date_range.first, "{ISOdate} ")} to #{Timex.format!(query.date_range.last, "{ISOdate} ")}.zip'
params = Map.merge(params, %{"limit" => "300", "csv" => "True", "detailed" => "True"})
limited_params = Map.merge(params, %{"limit" => "100"})
@@ -181,9 +181,10 @@ defmodule PlausibleWeb.StatsController do
def shared_link(conn, %{"domain" => slug}) do
shared_link =
Repo.one(
- from l in Plausible.Site.SharedLink,
+ from(l in Plausible.Site.SharedLink,
where: l.slug == ^slug and l.inserted_at < ^@old_format_deprecation_date,
preload: :site
+ )
)
if shared_link do
@@ -217,12 +218,13 @@ defmodule PlausibleWeb.StatsController do
defp find_shared_link(domain, auth) do
link_query =
- from link in Plausible.Site.SharedLink,
+ from(link in Plausible.Site.SharedLink,
inner_join: site in assoc(link, :site),
where: link.slug == ^auth,
where: site.domain == ^domain,
limit: 1,
preload: [site: site]
+ )
case Repo.one(link_query) do
%Plausible.Site.SharedLink{password_hash: hash} = link when not is_nil(hash) ->
diff --git a/test/support/test_utils.ex b/test/support/test_utils.ex
index f9c6015e88..ed2b41f076 100644
--- a/test/support/test_utils.ex
+++ b/test/support/test_utils.ex
@@ -141,8 +141,8 @@ defmodule Plausible.TestUtils do
end
end)
- if native, do: populate_native_stats(native)
- if imported, do: populate_imported_stats(imported)
+ populate_native_stats(native)
+ populate_imported_stats(imported)
end
defp populate_native_stats(events) do