Skip to content

Commit 8a328a3

Browse files
authored
Merge pull request beyond-all-reason#903 from dmarcoux/fix-credo-issues
Fix Credo issues
2 parents 20dbfc6 + fd58b67 commit 8a328a3

52 files changed

Lines changed: 106 additions & 39 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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
{Credo.Check.Warning.MissedMetadataKeyInLoggerConfig,
77
[
88
metadata_keys: [:request_id, :user_id, :pid, :actor_type, :actor_id]
9-
]}
9+
]},
10+
# TODO: Enable this check and fix the issues
11+
{Credo.Check.Design.AliasUsage, false}
12+
# {Credo.Check.Design.AliasUsage, [if_nested_deeper_than: 2, if_called_more_often_than: 1]}
1013
]
1114
}
1215
]

.github/workflows/lint.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,7 @@ jobs:
7676

7777
- name: Compile the project
7878
run: mix compile
79+
80+
# TODO: We need to ignore issues we haven't addressed yet.
81+
- name: Lint Elixir code to enforce code consistency # https://hexdocs.pm/credo/
82+
run: mix credo --ignore Readability,Refactor

lib/teiserver/account.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2217,6 +2217,7 @@ defmodule Teiserver.Account do
22172217
@spec update_client(T.userid(), map()) :: nil | :ok
22182218
defdelegate update_client(userid, partial_client), to: ClientLib
22192219

2220+
# credo:disable-for-next-line Credo.Check.Design.TagTODO
22202221
# TODO: Remove these in favour of update_client
22212222
@spec merge_update_client(map()) :: nil | :ok
22222223
defdelegate merge_update_client(client), to: ClientLib

lib/teiserver/account/reports/week_on_week_report.ex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ defmodule Teiserver.Account.WeekOnWeekReport do
4343
previous_key = {week - 1, weekday}
4444
previous_value = data_map[previous_key]
4545

46-
if previous_value not in [nil, 0] do
46+
if previous_value in [nil, 0] do
47+
{key, nil}
48+
else
4749
delta = NumberHelper.percent(this_value / previous_value) - 100
4850

4951
{key, delta}
50-
else
51-
{key, nil}
5252
end
5353
end)
5454

@@ -80,12 +80,12 @@ defmodule Teiserver.Account.WeekOnWeekReport do
8080
previous_key = key - 1
8181
previous_value = week_data[previous_key]
8282

83-
if previous_value not in [nil, 0] do
83+
if previous_value in [nil, 0] do
84+
{key, nil}
85+
else
8486
delta = NumberHelper.percent(this_value / previous_value) - 100
8587

8688
{key, delta}
87-
else
88-
{key, nil}
8989
end
9090
end)
9191

lib/teiserver/account/schemas/user.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ defmodule Teiserver.Account.User do
55

66
alias Argon2
77

8+
# credo:disable-for-next-line Credo.Check.Design.TagTODO
89
# TODO: this is where a user should be defined. This is only a placeholder for now
910
@type t :: term()
1011

lib/teiserver/account/servers/login_throttle_server.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ defmodule Teiserver.Account.LoginThrottleServer do
351351
{key, new_queue}
352352
end)
353353

354+
# credo:disable-for-next-line Credo.Check.Design.TagFIXME
354355
# FIXME: Waited for counter can be here with the now_ms value
355356
new_heartbeats = Map.drop(state.heartbeats, released_users)
356357

lib/teiserver/autohost/tachyon_handler.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ defmodule Teiserver.Autohost.TachyonHandler do
2323

2424
@type start_response :: %{ips: [String.t()], port: integer()}
2525

26+
# credo:disable-for-next-line Credo.Check.Design.TagTODO
2627
# TODO: there should be some kind of retry here
2728
@spec start_battle(Bot.id(), Teiserver.TachyonBattle.id(), Teiserver.Autohost.start_script()) ::
2829
{:ok, start_response()} | {:error, term()}
@@ -167,6 +168,7 @@ defmodule Teiserver.Autohost.TachyonHandler do
167168
current_battles: current
168169
}) do
169170
{:error, {:already_registered, _pid}} ->
171+
# credo:disable-for-next-line Credo.Check.Design.TagTODO
170172
# TODO: maybe we should handle that by disconnecting the existing one?
171173
{:stop, :normal, state}
172174

@@ -227,6 +229,7 @@ defmodule Teiserver.Autohost.TachyonHandler do
227229

228230
@impl true
229231
def handle_response("autohost/subscribeUpdates", _, _response, state) do
232+
# credo:disable-for-next-line Credo.Check.Design.TagTODO
230233
# TODO: handle potential failure here
231234
# for example, autohost refuses any subscription with `since` older than 5 minutes
232235
{:ok, state}

lib/teiserver/battle.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ defmodule Teiserver.Battle do
468468
already_finished? = match.finished != nil
469469
winning_ally_team = List.first(winning_ally_teams)
470470

471+
# credo:disable-for-next-line Credo.Check.Design.TagTODO
471472
# TODO Currently trusting the first received event, should be reworked to accept what the majority agrees on
472473
if winning_ally_team != nil && match.winning_team != nil &&
473474
winning_ally_team != match.winning_team do
@@ -619,6 +620,7 @@ defmodule Teiserver.Battle do
619620
# because the bot itself is in a new lobby since the last one finished
620621
script_tags = data["battleContext"]["scriptTags"]
621622

623+
# credo:disable-for-next-line Credo.Check.Design.TagTODO
622624
# TODO the server/match/id is legacy and should be removed
623625
# After updating Teiserver, there may be some ongoing matches with the legacy tags
624626
id = script_tags["game/server_match_id"] || script_tags["server/match/id"]

lib/teiserver/battle/balance/auto_balance.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ defmodule Teiserver.Battle.Balance.AutoBalance do
8787
# If the top two players are in the same party, this will return true
8888
@spec has_op_party?([DB.player()]) :: boolean()
8989
def has_op_party?(players) do
90-
if(Enum.count(players) >= 2) do
90+
if Enum.count(players) >= 2 do
9191
sorted_players =
9292
Enum.sort_by(
9393
players,

lib/teiserver/battle/balance/brute_force.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ defmodule Teiserver.Battle.Balance.BruteForce do
132132

133133
@spec get_st_dev([BF.player()]) :: any()
134134
def get_st_dev(team) do
135-
if(length(team) > 0) do
135+
if length(team) > 0 do
136136
ratings = Enum.map(team, fn player -> player.rating end)
137137
Statistics.stdev(ratings)
138138
else
@@ -142,7 +142,7 @@ defmodule Teiserver.Battle.Balance.BruteForce do
142142

143143
@spec get_captain_rating([BF.player()]) :: any()
144144
def get_captain_rating(team) do
145-
if(length(team) > 0) do
145+
if length(team) > 0 do
146146
captain = Enum.max_by(team, fn player -> player.rating end, &>=/2)
147147
captain.rating
148148
else

0 commit comments

Comments
 (0)