Skip to content

Commit 6d47ee8

Browse files
committed
build: Update Credo rules, add proper linting, remove stale deps from mix.lock
1 parent 4e471fc commit 6d47ee8

73 files changed

Lines changed: 319 additions & 1249 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.credo.exs‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"apps/*/test/",
3232
"apps/*/web/"
3333
],
34-
excluded: [~r"/_build/", ~r"/deps/", ~r"/node_modules/"]
34+
excluded: [~r"/_build/", ~r"/deps/", ~r"/node_modules/", "lib/nosedrum/"]
3535
},
3636
#
3737
# Load and configure plugins here:
@@ -88,7 +88,7 @@
8888
# If you don't want TODO comments to cause `mix credo` to fail, just
8989
# set this value to 0 (zero).
9090
#
91-
{Credo.Check.Design.TagTODO, [exit_status: 2]},
91+
{Credo.Check.Design.TagTODO, [exit_status: 0]},
9292
{Credo.Check.Design.TagFIXME, []},
9393

9494
#
@@ -99,7 +99,6 @@
9999
{Credo.Check.Readability.LargeNumbers, []},
100100
{Credo.Check.Readability.MaxLineLength, [priority: :low, max_length: 130]},
101101
{Credo.Check.Readability.ModuleAttributeNames, []},
102-
{Credo.Check.Readability.ModuleDoc, []},
103102
{Credo.Check.Readability.ModuleNames, []},
104103
{Credo.Check.Readability.ParenthesesInCondition, []},
105104
{Credo.Check.Readability.ParenthesesOnZeroArityDefs, []},
@@ -115,6 +114,8 @@
115114
{Credo.Check.Readability.UnnecessaryAliasExpansion, []},
116115
{Credo.Check.Readability.VariableNames, []},
117116
{Credo.Check.Readability.WithSingleClause, []},
117+
{Credo.Check.Consistency.MultiAliasImportRequireUse, []},
118+
{Credo.Check.Readability.ImplTrue, []},
118119

119120
#
120121
## Refactoring Opportunities
@@ -159,7 +160,11 @@
159160
{Credo.Check.Warning.UnusedRegexOperation, []},
160161
{Credo.Check.Warning.UnusedStringOperation, []},
161162
{Credo.Check.Warning.UnusedTupleOperation, []},
162-
{Credo.Check.Warning.UnsafeExec, []}
163+
{Credo.Check.Warning.UnsafeExec, []},
164+
{Credo.Check.Warning.LeakyEnvironment, []},
165+
{Credo.Check.Warning.MapGetUnsafePass, []},
166+
{Credo.Check.Warning.MixEnv, []},
167+
{Credo.Check.Warning.UnsafeToAtom, []}
163168
],
164169
disabled: [
165170
#
@@ -169,14 +174,13 @@
169174
# Controversial and experimental checks (opt-in, just move the check to `:enabled`
170175
# and be sure to use `mix credo --strict` to see low priority checks)
171176
#
172-
{Credo.Check.Consistency.MultiAliasImportRequireUse, []},
173-
{Credo.Check.Consistency.UnusedVariableNames, []},
174-
{Credo.Check.Design.DuplicatedCode, []},
175-
{Credo.Check.Design.SkipTestWithoutComment, []},
177+
{Credo.Check.Consistency.UnusedVariableNames, [force: :meaningful]},
176178
{Credo.Check.Readability.AliasAs, []},
177179
{Credo.Check.Readability.BlockPipe, []},
178-
{Credo.Check.Readability.ImplTrue, []},
180+
{Credo.Check.Readability.ModuleDoc, []},
179181
{Credo.Check.Readability.MultiAlias, []},
182+
{Credo.Check.Design.DuplicatedCode, []},
183+
{Credo.Check.Design.SkipTestWithoutComment, []},
180184
{Credo.Check.Readability.NestedFunctionCalls, []},
181185
{Credo.Check.Readability.OneArityFunctionInPipe, []},
182186
{Credo.Check.Readability.SeparateAliasRequire, []},
@@ -198,11 +202,7 @@
198202
{Credo.Check.Refactor.PipeChainStart, []},
199203
{Credo.Check.Refactor.RejectFilter, []},
200204
{Credo.Check.Refactor.VariableRebinding, []},
201-
{Credo.Check.Warning.LazyLogging, []},
202-
{Credo.Check.Warning.LeakyEnvironment, []},
203-
{Credo.Check.Warning.MapGetUnsafePass, []},
204-
{Credo.Check.Warning.MixEnv, []},
205-
{Credo.Check.Warning.UnsafeToAtom, []}
205+
{Credo.Check.Warning.LazyLogging, []}
206206

207207
# {Credo.Check.Refactor.MapInto, []},
208208

‎.github/workflows/build_prs.yml‎

Lines changed: 0 additions & 29 deletions
This file was deleted.

‎.github/workflows/lint.yml‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Build PRs
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
8+
jobs:
9+
lint_pr:
10+
name: Lint PR
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout repo
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Elixir
17+
uses: erlef/setup-beam@v1
18+
with:
19+
otp-version: 27
20+
elixir-version: 1.19.5
21+
22+
- uses: actions/cache@v4
23+
env:
24+
base-key: 27-1.19
25+
with:
26+
path: |
27+
_build
28+
deps
29+
# Generate a hash of the OTP version and Elixir version
30+
key: ${{ env.base-key }}-mix-${{ hashFiles('**/mix.lock') }}
31+
restore-keys: ${{ env.base-key }}-mix
32+
33+
- name: Install dependencies
34+
run: mix deps.get
35+
36+
- name: Compile dependencies
37+
run: mix deps.compile
38+
39+
- name: Compile project
40+
run: mix compile --strict
41+
42+
- name: Lint (Credo)
43+
run: mix credo --strict --ignore 'TagTODO'
44+
45+
- name: Lint (mix format)
46+
run: mix format --check-formatted

‎lib/cluster/strategy/tailscale.ex‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ defmodule Cluster.Strategy.Tailscale do
2323

2424
def start_link(args), do: GenServer.start_link(__MODULE__, args)
2525

26-
@impl true
26+
@impl GenServer
2727
def init([%State{meta: nil} = state]) do
2828
init([%State{state | :meta => MapSet.new()}])
2929
end
@@ -32,7 +32,7 @@ defmodule Cluster.Strategy.Tailscale do
3232
{:ok, load(state)}
3333
end
3434

35-
@impl true
35+
@impl GenServer
3636
def handle_info(:timeout, state) do
3737
handle_info(:load, state)
3838
end

‎lib/octocon/accounts.ex‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ defmodule Octocon.Accounts do
100100
def region_for_user(system_identity) do
101101
case get_user_registry(system_identity) do
102102
nil -> nil
103-
%UserRegistry{region: region} -> String.to_atom(region)
103+
%UserRegistry{region: region} -> String.to_existing_atom(region)
104104
end
105105
end
106106

‎lib/octocon/application.ex‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ defmodule Octocon.Application do
2424

2525
require Logger
2626

27-
@impl true
27+
@impl Application
2828
def start(_type, _args) do
2929
group = Octocon.RPC.NodeTracker.current_group()
3030
Logger.warning("Starting node of type: #{group}")
@@ -44,13 +44,13 @@ defmodule Octocon.Application do
4444

4545
# Tell Phoenix to update the endpoint configuration
4646
# whenever the application is updated.
47-
@impl true
47+
@impl Application
4848
def config_change(changed, _new, removed) do
4949
OctoconWeb.Endpoint.config_change(changed, removed)
5050
:ok
5151
end
5252

53-
defp global_children() do
53+
defp global_children do
5454
[
5555
# Telemetry
5656
OctoconWeb.Telemetry,
@@ -106,7 +106,7 @@ defmodule Octocon.Application do
106106

107107
defp group_children(_), do: []
108108

109-
defp generate_libcluster_child() do
109+
defp generate_libcluster_child do
110110
node_list = Application.get_env(:octocon, :node_list, nil)
111111
use_tailscale = Application.get_env(:octocon, :use_tailscale, false)
112112

‎lib/octocon/channel_blacklists.ex‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ defmodule Octocon.ChannelBlacklists do
3838
3939
This should always be backed by a `OctoconDiscord.ChannelBlacklistManager` cache, as it is a latency-sensitive operation.
4040
"""
41-
def is_channel_blacklisted?(channel_id) do
41+
def channel_blacklisted?(channel_id) do
4242
from(c in ChannelBlacklist, where: c.channel_id == ^to_string(channel_id))
4343
|> Repo.all_regional(@region_specifier)
4444
|> case do

‎lib/octocon/cluster_utils.ex‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ defmodule Octocon.ClusterUtils do
88
@doc """
99
Check if the current node is a primary node.
1010
"""
11-
def is_primary?, do: NodeTracker.is_primary?()
11+
def primary?, do: NodeTracker.primary?()
1212

1313
def current_db_region do
1414
Application.get_env(:octocon, :current_db_region)
@@ -28,7 +28,7 @@ defmodule Octocon.ClusterUtils do
2828
def primary_nodes(true) do
2929
other_nodes = primary_nodes(false)
3030

31-
if is_primary?() do
31+
if primary?() do
3232
[Node.self() | other_nodes]
3333
else
3434
other_nodes
@@ -41,7 +41,7 @@ defmodule Octocon.ClusterUtils do
4141
"""
4242
def run_on_all_primary_nodes(fun) do
4343
# If we are a primary node, run the function locally as well
44-
if NodeTracker.is_primary?() do
44+
if NodeTracker.primary?() do
4545
fun.()
4646
end
4747

@@ -84,7 +84,7 @@ defmodule Octocon.ClusterUtils do
8484

8585
def check_primary(node) do
8686
Octocon.RPC.NodeTracker.rpc(node, fn ->
87-
NodeTracker.is_primary?()
87+
NodeTracker.primary?()
8888
end)
8989
end
9090
end

‎lib/octocon/fcm.ex‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ defmodule Octocon.FCM do
88

99
import Ecto.Query, warn: false
1010

11-
alias Octocon.Accounts
12-
alias Octocon.Alters
13-
alias Octocon.Alters.Alter
14-
alias Octocon.Friendships.Friendship
15-
alias Octocon.NotificationTokens
16-
alias Octocon.NotificationTokens.NotificationToken
17-
alias Octocon.Repo
11+
alias Octocon.{
12+
Accounts,
13+
Alters,
14+
Alters.Alter,
15+
Friendships.Friendship,
16+
NotificationTokens,
17+
NotificationTokens.NotificationToken,
18+
Repo
19+
}
1820

1921
@size_limit 500
2022

‎lib/octocon/friendships.ex‎

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ defmodule Octocon.Friendships do
1010
@query_concurrency 10
1111

1212
import Ecto.Query, warn: false
13-
alias Octocon.Alters.Alter
14-
alias Octocon.Repo
1513

16-
alias Octocon.Accounts
17-
18-
alias Octocon.Friendships.Friendship
19-
alias Octocon.Fronts
20-
21-
alias Octocon.Fronts.CurrentFront
14+
alias Octocon.{
15+
Accounts,
16+
Alters.Alter,
17+
Friendships.Friendship,
18+
Friendships.Request,
19+
Fronts,
20+
Fronts.CurrentFront,
21+
Repo
22+
}
2223

2324
@doc """
2425
Returns the friendship status between two users with the given identities, or `nil` if no friendship exists.
@@ -292,8 +293,6 @@ defmodule Octocon.Friendships do
292293
Friendship.changeset(friendship, attrs)
293294
end
294295

295-
alias Octocon.Friendships.Request
296-
297296
@doc """
298297
Returns the friend request between two users with the given identities, or `nil` if no request exists.
299298
"""
@@ -417,9 +416,7 @@ defmodule Octocon.Friendships do
417416
user_id = Accounts.id_from_system_identity(user_identity, :system)
418417
friend_id = Accounts.id_from_system_identity(friend_identity, :system)
419418

420-
if not friendship_exists?(user_identity, friend_identity) do
421-
{:error, :not_friends}
422-
else
419+
if friendship_exists?(user_identity, friend_identity) do
423420
from(
424421
f in Friendship,
425422
where: f.user_id == ^user_id and f.friend_id == ^friend_id
@@ -445,6 +442,8 @@ defmodule Octocon.Friendships do
445442
end)
446443

447444
:ok
445+
else
446+
{:error, :not_friends}
448447
end
449448
end
450449

0 commit comments

Comments
 (0)