-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Fix AGENTS.md including Ecto references in --no-ecto projects #6581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
bmalum
wants to merge
4
commits into
phoenixframework:main
Choose a base branch
from
bmalum:fix-agents-md-ecto-references
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c3fff01
Remove Ecto references from AGENTS.md for --no-ecto projects
bmalum 95c4c8b
Isolate AGENTS.md content for all phx.new flags
bmalum adf95a7
Fix LiveView leakage in --no-live projects with Ecto
bmalum e04da94
Remove UI/CSS guidelines from API-only projects
bmalum File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -29,7 +29,7 @@ | |||||
| end | ||||||
|
|
||||||
| - **Never** nest multiple modules in the same file as it can cause cyclic dependencies and compilation errors | ||||||
| - **Never** use map access syntax (`changeset[:field]`) on structs as they do not implement the Access behaviour by default. For regular structs, you **must** access the fields directly, such as `my_struct.field` or use higher level APIs that are available on the struct if they exist, `Ecto.Changeset.get_field/2` for changesets | ||||||
| - **Never** use map access syntax on structs as they do not implement the Access behaviour by default. For structs, you **must** access the fields directly, such as `my_struct.field` or use higher level APIs that are available on the struct if they exist | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| - Elixir's standard library has everything necessary for date and time manipulation. Familiarize yourself with the common `Time`, `Date`, `DateTime`, and `Calendar` interfaces by accessing their documentation as necessary. **Never** install additional dependencies unless asked or for date/time parsing (which you can use the `date_time_parser` package) | ||||||
| - Don't use `String.to_atom/1` on user input (memory leak risk) | ||||||
| - Predicate function names should not start with `is_` and should end in a question mark. Names like `is_thing` should be reserved for guards | ||||||
|
|
||||||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -186,29 +186,6 @@ You can also specify a name to nest the params: | |
| {:noreply, assign(socket, form: to_form(user_params, as: :user))} | ||
| end | ||
|
|
||
| #### Creating a form from changesets | ||
|
|
||
| When using changesets, the underlying data, form params, and errors are retrieved from it. The `:as` option is automatically computed too. E.g. if you have a user schema: | ||
|
|
||
| defmodule MyApp.Users.User do | ||
| use Ecto.Schema | ||
| ... | ||
| end | ||
|
|
||
| And then you create a changeset that you pass to `to_form`: | ||
|
|
||
| %MyApp.Users.User{} | ||
| |> Ecto.Changeset.change() | ||
| |> to_form() | ||
|
|
||
| Once the form is submitted, the params will be available under `%{"user" => user_params}`. | ||
|
|
||
| In the template, the form form assign can be passed to the `<.form>` function component: | ||
|
|
||
| <.form for={@form} id="todo-form" phx-change="validate" phx-submit="save"> | ||
| <.input field={@form[:field]} type="text" /> | ||
| </.form> | ||
|
|
||
| Always give the form an explicit, unique DOM ID, like `id="todo-form"`. | ||
|
|
||
| #### Avoiding form errors | ||
|
|
@@ -223,9 +200,8 @@ Always give the form an explicit, unique DOM ID, like `id="todo-form"`. | |
| And **never** do this: | ||
|
|
||
| <%!-- NEVER do this (invalid) --%> | ||
| <.form for={@changeset} id="my-form"> | ||
| <.input field={@changeset[:field]} type="text" /> | ||
| <.form for={@data} id="my-form"> | ||
| <.input field={@data[:field]} type="text" /> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this change is good, as nobody would write that, and it probably doesn't really get the point across to the LLM. |
||
| </.form> | ||
|
|
||
| - You are FORBIDDEN from accessing the changeset in the template as it will cause errors | ||
| - **Never** use `<.form let={f} ...>` in the template, instead **always use `<.form for={@form} ...>`**, then drive all form references from the form assign as in `@form[:field]`. The UI should **always** be driven by a `to_form/2` assigned in the LiveView module that is derived from a changeset | ||
| - **Never** use `<.form let={f} ...>` in the template, instead **always use `<.form for={@form} ...>`**, then drive all form references from the form assign as in `@form[:field]`. The UI should **always** be driven by a `to_form/1` or `to_form/2` assigned in the LiveView module | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only moves the problem around. Now, you'd get LiveView content when you use
--no-live. For the AGENTS.md, we could solve this by using .md.eex files and then checking<%= if live do %>etc., but since these files are also valid usage_rules, so we can't use eex :(Maybe we need to split this even further, into an
ecto-liveview.mdand concat that conditionally? Although this refers to LiveView, the content is also valid for Phoenix forms without LiveView.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch!