Skip to content
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

fix(rw-eslint): Implement more specific checking on Routes #10404

Merged
merged 7 commits into from
Apr 3, 2024

Conversation

dac09
Copy link
Contributor

@dac09 dac09 commented Apr 3, 2024

Fixes #10383

See issue for more details.

This change does the following:

  1. Searches for the return statement from the Routes component
  2. If the body contains JSXElements, check each JSXElement and it's children recursively

Point (1) is the real fix. Technically, you could call your Routes component something else though, and this linter won't catch it - but it won't break either.

@dac09 dac09 added this to the next-release milestone Apr 3, 2024
@dac09 dac09 added the release:fix This PR is a fix label Apr 3, 2024
@@ -18,28 +42,42 @@ export const unsupportedRouteComponents = createRule({
unexpected:
'Unexpected JSX element <{{name}}>. Only <Router>, <Route>, <Set>, <PrivateSet> and <Private> are allowed in the Routes file.',
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to change the error message to be more specific too?

Copy link
Contributor Author

@dac09 dac09 Apr 3, 2024

Choose a reason for hiding this comment

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

No I don't think so, because the problem was that it was targetting all JSX Elements. The behaviour actually hasn't changed, just stops incorrectly targetting irrelavnt elements

Copy link
Member

@Tobbe Tobbe Apr 3, 2024

Choose a reason for hiding this comment

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

Only <Router>, <Route>, <Set>, <PrivateSet> and <Private> are allowed in the Routes file.

It's not true though, is it? You can have const AnotherThing = <Bazinga><p>Hello</p></Bazinga> in your Routes file and it's still perfectly valid, right? We just want to warn against doing crazy things inside the <Router> element itself, not the entire file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I see what you're saying!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated!

@dac09 dac09 enabled auto-merge (squash) April 3, 2024 11:27
@dac09 dac09 merged commit 7864b72 into redwoodjs:main Apr 3, 2024
46 checks passed
@dac09 dac09 deleted the fix/routes-linting-specificity branch April 3, 2024 20:28
@ahaywood ahaywood modified the milestones: next-release, v7.4.0 Apr 5, 2024
@jtoar jtoar modified the milestones: v7.4.0, next-release-major Apr 8, 2024
@jtoar
Copy link
Contributor

jtoar commented Apr 8, 2024

Marking this one as next release major since it builds on #10266 and isn't trivial to cherry pick over

jtoar added a commit that referenced this pull request Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:fix This PR is a fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Routes eslint targets too many elements
5 participants