Skip to content

Commit 9ad50df

Browse files
committed
chore: fix rust warnings
1 parent 82e3c5d commit 9ad50df

File tree

9 files changed

+299
-93
lines changed

9 files changed

+299
-93
lines changed

apps/core/src/application/services/analytics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ impl AnalyticsEngine {
367367
percentage: (count as f64 / events.len() as f64) * 100.0,
368368
})
369369
.collect();
370-
top_event_types.sort_by(|a, b| b.count.cmp(&a.count));
370+
top_event_types.sort_by_key(|x| std::cmp::Reverse(x.count));
371371
top_event_types.truncate(10);
372372

373373
// Top entities
@@ -379,7 +379,7 @@ impl AnalyticsEngine {
379379
percentage: (count as f64 / events.len() as f64) * 100.0,
380380
})
381381
.collect();
382-
top_entities.sort_by(|a, b| b.count.cmp(&a.count));
382+
top_entities.sort_by_key(|x| std::cmp::Reverse(x.count));
383383
top_entities.truncate(10);
384384

385385
let time_range = TimeRange {

apps/core/src/infrastructure/persistence/backup.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ impl BackupManager {
223223
}
224224

225225
// Sort by creation time, newest first
226-
backups.sort_by(|a, b| b.created_at.cmp(&a.created_at));
226+
backups.sort_by_key(|x| std::cmp::Reverse(x.created_at));
227227

228228
Ok(backups)
229229
}
@@ -257,7 +257,7 @@ impl BackupManager {
257257
}
258258

259259
// Sort by date, oldest last
260-
backups.sort_by(|a, b| b.created_at.cmp(&a.created_at));
260+
backups.sort_by_key(|x| std::cmp::Reverse(x.created_at));
261261

262262
let to_delete = backups.split_off(keep_count);
263263
let delete_count = to_delete.len();

apps/core/src/infrastructure/persistence/lock_free/metrics.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,7 @@ impl LockFreeMetrics {
161161
let total = self.total_latency_ns.load(Ordering::Relaxed);
162162
let count = self.events_queried.load(Ordering::Relaxed);
163163

164-
if count == 0 {
165-
None
166-
} else {
167-
Some(Duration::from_nanos(total / count))
168-
}
164+
total.checked_div(count).map(Duration::from_nanos)
169165
}
170166

171167
/// Get minimum query latency

apps/core/src/infrastructure/persistence/snapshot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl SnapshotManager {
176176
entity_snapshots.push(snapshot.clone());
177177

178178
// Sort by timestamp (newest first)
179-
entity_snapshots.sort_by(|a, b| b.as_of.cmp(&a.as_of));
179+
entity_snapshots.sort_by_key(|x| std::cmp::Reverse(x.as_of));
180180

181181
// Prune old snapshots if over limit
182182
let mut pruned = 0;

apps/core/src/store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ impl EventStore {
535535
.collect();
536536

537537
// Sort by timestamp (ascending)
538-
results.sort_by(|a, b| a.timestamp.cmp(&b.timestamp));
538+
results.sort_by_key(|x| x.timestamp);
539539

540540
// Apply limit
541541
if let Some(limit) = request.limit {

apps/query-service/.credo.exs

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# .credo.exs - Credo configuration for query-service
2+
%{
3+
configs: [
4+
%{
5+
name: "default",
6+
files: %{
7+
included: [
8+
"lib/",
9+
"test/"
10+
],
11+
excluded: [~r"/_build/", ~r"/deps/", ~r"/node_modules/"]
12+
},
13+
plugins: [],
14+
requires: [],
15+
strict: true,
16+
parse_timeout: 5000,
17+
color: true,
18+
checks: %{
19+
enabled: [
20+
# Consistency checks
21+
{Credo.Check.Consistency.ExceptionNames, []},
22+
{Credo.Check.Consistency.LineEndings, []},
23+
{Credo.Check.Consistency.ParameterPatternMatching, []},
24+
{Credo.Check.Consistency.SpaceAroundOperators, []},
25+
{Credo.Check.Consistency.SpaceInParentheses, []},
26+
{Credo.Check.Consistency.TabsOrSpaces, []},
27+
28+
# Design checks
29+
{Credo.Check.Design.AliasUsage, [priority: :low, if_nested_deeper_than: 2, if_called_more_often_than: 0]},
30+
{Credo.Check.Design.DuplicatedCode, [excluded_macros: [], mass_threshold: 40]},
31+
{Credo.Check.Design.TagFIXME, []},
32+
{Credo.Check.Design.TagTODO, [exit_status: 0]},
33+
34+
# Readability checks
35+
{Credo.Check.Readability.AliasOrder, []},
36+
{Credo.Check.Readability.FunctionNames, []},
37+
{Credo.Check.Readability.LargeNumbers, []},
38+
{Credo.Check.Readability.MaxLineLength, [priority: :low, max_length: 120]},
39+
{Credo.Check.Readability.ModuleAttributeNames, []},
40+
{Credo.Check.Readability.ModuleDoc, []},
41+
{Credo.Check.Readability.ModuleNames, []},
42+
{Credo.Check.Readability.ParenthesesInCondition, []},
43+
{Credo.Check.Readability.ParenthesesOnZeroArityDefs, []},
44+
{Credo.Check.Readability.PipeIntoAnonymousFunctions, []},
45+
{Credo.Check.Readability.PredicateFunctionNames, []},
46+
{Credo.Check.Readability.PreferImplicitTry, []},
47+
{Credo.Check.Readability.RedundantBlankLines, []},
48+
{Credo.Check.Readability.Semicolons, []},
49+
{Credo.Check.Readability.SpaceAfterCommas, []},
50+
{Credo.Check.Readability.StringSigils, []},
51+
{Credo.Check.Readability.TrailingBlankLine, []},
52+
{Credo.Check.Readability.TrailingWhiteSpace, []},
53+
{Credo.Check.Readability.UnnecessaryAliasExpansion, []},
54+
{Credo.Check.Readability.VariableNames, []},
55+
{Credo.Check.Readability.WithSingleClause, []},
56+
57+
# Refactoring checks
58+
{Credo.Check.Refactor.Apply, []},
59+
{Credo.Check.Refactor.CondStatements, []},
60+
{Credo.Check.Refactor.CyclomaticComplexity, [max_complexity: 10]},
61+
{Credo.Check.Refactor.DoubleBooleanNegation, []},
62+
{Credo.Check.Refactor.FilterFilter, []},
63+
{Credo.Check.Refactor.FilterReject, []},
64+
{Credo.Check.Refactor.FunctionArity, []},
65+
{Credo.Check.Refactor.LongQuoteBlocks, []},
66+
{Credo.Check.Refactor.MapJoin, []},
67+
{Credo.Check.Refactor.MatchInCondition, []},
68+
{Credo.Check.Refactor.NegatedConditionsInUnless, []},
69+
{Credo.Check.Refactor.NegatedConditionsWithElse, []},
70+
{Credo.Check.Refactor.Nesting, [max_nesting: 3]},
71+
{Credo.Check.Refactor.RejectReject, []},
72+
{Credo.Check.Refactor.UnlessWithElse, []},
73+
{Credo.Check.Refactor.WithClauses, []},
74+
75+
# Warning checks
76+
{Credo.Check.Warning.ApplicationConfigInModuleAttribute, []},
77+
{Credo.Check.Warning.BoolOperationOnSameValues, []},
78+
{Credo.Check.Warning.ExpensiveEmptyEnumCheck, []},
79+
{Credo.Check.Warning.IExPry, []},
80+
{Credo.Check.Warning.IoInspect, []},
81+
{Credo.Check.Warning.MixEnv, []},
82+
{Credo.Check.Warning.OperationOnSameValues, []},
83+
{Credo.Check.Warning.OperationWithConstantResult, []},
84+
{Credo.Check.Warning.RaiseInsideRescue, []},
85+
{Credo.Check.Warning.SpecWithStruct, []},
86+
{Credo.Check.Warning.UnsafeExec, []},
87+
{Credo.Check.Warning.UnusedEnumOperation, []},
88+
{Credo.Check.Warning.UnusedFileOperation, []},
89+
{Credo.Check.Warning.UnusedKeywordOperation, []},
90+
{Credo.Check.Warning.UnusedListOperation, []},
91+
{Credo.Check.Warning.UnusedPathOperation, []},
92+
{Credo.Check.Warning.UnusedRegexOperation, []},
93+
{Credo.Check.Warning.UnusedStringOperation, []},
94+
{Credo.Check.Warning.UnusedTupleOperation, []},
95+
{Credo.Check.Warning.WrongTestFileExtension, []}
96+
],
97+
disabled: [
98+
# Disable the Logger metadata check since we use dynamic metadata
99+
# and the check doesn't work well with :all or comprehensive key lists
100+
{Credo.Check.Warning.UnsafeToAtom, []},
101+
{Credo.Check.Warning.LeakyEnvironment, []}
102+
]
103+
}
104+
}
105+
]
106+
}

apps/query-service/config/config.exs

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,78 @@ config :query_service_ex,
55
ecto_repos: [QueryServiceEx.Repo]
66

77
# Configure structured logging defaults
8-
# Include all metadata keys used across the application to avoid Credo warnings
8+
# Include all metadata keys used across the application
99
config :logger, :console,
10-
metadata: :all
10+
metadata: [
11+
# Standard metadata
12+
:request_id,
13+
:correlation_id,
14+
:entity_id,
15+
:event_type,
16+
:module,
17+
:function,
18+
# Auth and user context
19+
:user_id,
20+
:tenant_id,
21+
:provider,
22+
:api_key_id,
23+
:name,
24+
:old_api_key_id,
25+
:new_api_key_id,
26+
# Billing metadata
27+
:customer_id,
28+
:variant_id,
29+
:subscription_id,
30+
:status,
31+
:usage_type,
32+
:overage_count,
33+
:count,
34+
:percentage,
35+
:threshold,
36+
:reason,
37+
:event_name,
38+
# Error handling metadata
39+
:error,
40+
:kind,
41+
:stacktrace,
42+
:exception_type,
43+
:error_type,
44+
# Telemetry and metrics
45+
:telemetry_event,
46+
:duration_ms,
47+
:source,
48+
:queue_time_ms,
49+
:decode_time_ms,
50+
:method,
51+
:path,
52+
:event_id,
53+
:processing_time_ms,
54+
:projection_count,
55+
:sync_time_ms,
56+
:event_ids,
57+
:projection_name,
58+
# WebSocket metadata
59+
:url,
60+
:message_type,
61+
:message_size_bytes,
62+
:attempt,
63+
:backoff_ms,
64+
:attempts,
65+
:last_error,
66+
:total_reconnects,
67+
:reconnect_attempts,
68+
# Circuit breaker metadata
69+
:circuit,
70+
:from_state,
71+
:failure_count,
72+
# Health check metadata
73+
:check,
74+
:timeout_ms,
75+
:core_available,
76+
:failed_syncs,
77+
# Step tracking
78+
:step
79+
]
1180

1281
# Configure the Phoenix endpoint
1382
config :query_service_ex, QueryServiceExWeb.Endpoint,

apps/query-service/mix.exs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ defmodule QueryServiceEx.MixProject do
99
elixirc_paths: elixirc_paths(Mix.env()),
1010
start_permanent: Mix.env() == :prod,
1111
deps: deps(),
12-
releases: releases()
12+
releases: releases(),
13+
aliases: aliases()
1314
]
1415
end
1516

@@ -85,4 +86,18 @@ defmodule QueryServiceEx.MixProject do
8586
]
8687
]
8788
end
89+
90+
defp aliases do
91+
[
92+
# Run tests with testcontainers (spins up PostgreSQL in Docker)
93+
# Use `mix test.container` for convenient testcontainers-based testing
94+
"test.container": ["testcontainers.test --database postgres"],
95+
# Run tests with cached database container (faster subsequent runs)
96+
"test.container.cached": ["testcontainers.test --database postgres --db-volume query_service_test_vol"],
97+
# Setup task runs migrations
98+
setup: ["deps.get", "ecto.setup"],
99+
"ecto.setup": ["ecto.create", "ecto.migrate"],
100+
"ecto.reset": ["ecto.drop", "ecto.setup"]
101+
]
102+
end
88103
end

0 commit comments

Comments
 (0)