chore: Use consistent limit language and permission-accurate guidance#4640
Merged
Conversation
Signed-off-by: Adriano Lazzaretti <lazzaretti136@gmail.com>
Contributor
There was a problem hiding this comment.
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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.