Skip to content

Commit 973dfa6

Browse files
authored
ci: ratchet risky architecture patterns (#175)
1 parent 0edfb5d commit 973dfa6

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

scripts/check-architecture-ratchets.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@
5454
"unsafe block" => /unsafe\s*\{/
5555
}.freeze
5656

57+
# These counts are not style rules. They are ratchets for patterns that tend to
58+
# grow accidental architecture surface area: shared mutable state, stringly
59+
# typed maps, unjoined background tasks, and unsafe code. If a future PR needs
60+
# more of one, bump the budget in that PR so reviewers see the tradeoff.
61+
WATCH_PATTERN_BUDGETS = {
62+
"Arc<Mutex" => 40,
63+
"Arc<RwLock" => 11,
64+
"HashMap<String, String>" => 70,
65+
"tokio::spawn" => 141,
66+
"unsafe block" => 15
67+
}.freeze
68+
5769
def rust_files
5870
files = []
5971
Find.find(ROOT.join("crates").to_s) do |path|
@@ -103,4 +115,12 @@ def relative(path)
103115
puts " #{name}: #{count}"
104116
end
105117

118+
WATCH_PATTERN_BUDGETS.each do |name, budget|
119+
count = pattern_counts.fetch(name, 0)
120+
next unless count > budget
121+
122+
warn "#{name}: #{count} occurrences exceeds architecture budget #{budget}"
123+
failed = true
124+
end
125+
106126
abort("architecture ratchets failed") if failed

0 commit comments

Comments
 (0)