feat: Add UnusedLiveViewAssign rule#9
Open
ftes wants to merge 2 commits into
Open
Conversation
s3cur3
reviewed
May 22, 2026
Collaborator
s3cur3
left a comment
There was a problem hiding this comment.
Wow, this is really exciting! It surfaces 268 issues on our codebase at Jump. 👀 😄 I'd like to go through those and make sure there aren't any false positives (by the terms of the contract in the docs), but me and my team are out of the office until Tuesday next week. I'll plan to get back to you next week, though. 👍
Comment on lines
+23
to
+25
| - Helper functions should read the assigns map through a variable named | ||
| `assigns` or through `socket.assigns`. Reads like `opts.foo` are not | ||
| inferred to mean LiveView assigns. |
Collaborator
There was a problem hiding this comment.
It took me a second to understand what this was saying. Might be clearer as something like:
Suggested change
| - Helper functions should read the assigns map through a variable named | |
| `assigns` or through `socket.assigns`. Reads like `opts.foo` are not | |
| inferred to mean LiveView assigns. | |
| - Helper functions should read the assigns map through a variable named | |
| `assigns` or through `socket.assigns`. If you bind assigns to another | |
| name (like `%{assigns: opts} = socket`, followed by using | |
| `opts.my_attr`), the reads will not be recognized as being related | |
| to LiveView assigns. |
Comment on lines
+28
to
+30
| - Dynamic assign keys are not tracked. Examples include | ||
| `assign(socket, field, value)`, `socket.assigns[field]`, and | ||
| `Map.get(assigns, field)`. |
Collaborator
There was a problem hiding this comment.
Suggested change
| - Dynamic assign keys are not tracked. Examples include | |
| `assign(socket, field, value)`, `socket.assigns[field]`, and | |
| `Map.get(assigns, field)`. | |
| - Writes to dynamic assign keys are not tracked. Examples include | |
| `assign(socket, field, value)`, `socket.assigns[field]`, and | |
| `Map.get(assigns, field)`. |
| Prefer explicit `attr` declarations and `attr :rest, :global` for | ||
| forwarded attributes. | ||
| - Some assigns are intended to be consumed by framework or layout code | ||
| outside the current LiveView module. Use `ignored_assigns` to whitelist |
Collaborator
There was a problem hiding this comment.
Suggested change
| outside the current LiveView module. Use `ignored_assigns` to whitelist | |
| outside the current LiveView module. Use `ignored_assigns` to allowlist |
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.
Detect unused LiveView/LiveComponent assigns.
Conventions and limitations
assignsor throughsocket.assigns. Reads likeopts.fooare not inferred to mean LiveView assigns.assign,assign_new,assign_async,allow_upload,stream,stream_async, andupdateare checked.assign(socket, field, value),socket.assigns[field], andMap.get(assigns, field).Phoenix.Component.assigns_to_attributes/2is not treated as a read. Prefer explicitattrdeclarations andattr :rest, :globalfor forwarded attributes.ignored_assignsto whitelist those keys.