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.
Fix typespec warning in finding_log.ex
The current implementation attempts to access the id field directly from Sobelow.get_mod(mod) result, but the typespec indicates this function might return something that's not a struct. This causes a warning during compilation.
This PR adds a safety check using is_struct/1 to ensure we only access the id field when we have a proper struct, falling back to nil otherwise.
Before:
ruleId: Sobelow.get_mod(mod).id
After:
mod_struct = Sobelow.get_mod(mod)
rule_id = if is_struct(mod_struct), do: mod_struct.id, else: nil
This maintains the same functionality while resolving the typespec warning during compilation.
The warning on our code was:
==> sobelow
warning: expected a map or struct when accessing .id in expression:
113 │ ruleId: Sobelow.get_mod(mod).id,
│ ~
│
└─ lib/sobelow/finding_log.ex:113:36: Sobelow.FindingLog.format_sarif/1