Skip to content

chore: Use consistent limit language and permission-accurate guidance#4640

Merged
Rockyy174 merged 2 commits into
operately:mainfrom
Rockyy174:update-limit-language
Jun 8, 2026
Merged

chore: Use consistent limit language and permission-accurate guidance#4640
Rockyy174 merged 2 commits into
operately:mainfrom
Rockyy174:update-limit-language

Conversation

@Rockyy174

Copy link
Copy Markdown
Collaborator

No description provided.

Signed-off-by: Adriano Lazzaretti <lazzaretti136@gmail.com>

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="app/lib/operately/billing/enforce_limits.ex" line_range="143-147" />
<code_context>
+
+  defp format_storage_bytes(bytes) do
+    [
+      {"PB", 1024 ** 5},
+      {"TB", 1024 ** 4},
+      {"GB", 1024 ** 3},
+      {"MB", 1024 ** 2},
+      {"KB", 1024}
+    ]
+    |> Enum.find(fn {_unit, size} -> bytes >= size end)
</code_context>
<issue_to_address>
**issue (bug_risk):** Use a valid power implementation instead of the non-Elixir `**` operator.

Elixir doesn’t support `**`, so this code won’t compile. Since these are fixed powers of 1024, please replace them with precomputed integer constants (e.g. `1_125_899_906_842_624` for PB, etc.), or use `:math.pow/2` and convert to integers, though literals are simpler and more efficient here.
</issue_to_address>

### Comment 2
<location path="app/lib/operately/billing/enforce_limits.ex" line_range="139-159" />
<code_context>
     end
   end

+  defp format_storage_bytes(bytes) when bytes < 1024, do: "#{bytes} B"
+
+  defp format_storage_bytes(bytes) do
+    [
+      {"PB", 1024 ** 5},
+      {"TB", 1024 ** 4},
+      {"GB", 1024 ** 3},
+      {"MB", 1024 ** 2},
+      {"KB", 1024}
+    ]
+    |> Enum.find(fn {_unit, size} -> bytes >= size end)
+    |> case do
+      {unit, size} ->
+        value = bytes / size
+        rounded = if value >= 10, do: Float.round(value), else: Float.round(value, 1)
+        "#{format_storage_value(rounded)} #{unit}"
+
+      nil ->
+        "#{bytes} B"
+    end
</code_context>
<issue_to_address>
**suggestion:** Avoid duplicated `bytes < 1024` handling in `format_storage_bytes`.

The guard clause and the `nil -> "#{bytes} B"` branch both handle `bytes < 1024`. Consider removing one: either drop the guard and rely on the `nil` case, or ensure `Enum.find` always returns a unit (e.g. add `{"B", 1}`). This avoids redundancy and clarifies behavior for sub‑KB values.

```suggestion
  defp format_storage_bytes(bytes) do
    units = [
      {"PB", 1024 ** 5},
      {"TB", 1024 ** 4},
      {"GB", 1024 ** 3},
      {"MB", 1024 ** 2},
      {"KB", 1024},
      {"B", 1}
    ]

    {unit, size} = Enum.find(units, fn {_unit, size} -> bytes >= size end)

    value = bytes / size
    rounded =
      if value >= 10 do
        Float.round(value)
      else
        Float.round(value, 1)
      end

    "#{format_storage_value(rounded)} #{unit}"
  end
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread app/lib/operately/billing/enforce_limits.ex Outdated
Comment thread app/lib/operately/billing/enforce_limits.ex Outdated
Signed-off-by: Adriano Lazzaretti <lazzaretti136@gmail.com>
@Rockyy174
Rockyy174 merged commit c2f1c2f into operately:main Jun 8, 2026
3 checks passed
@Rockyy174
Rockyy174 deleted the update-limit-language branch June 8, 2026 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant