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 curly brace erroring on child text nodes #133

Merged
merged 2 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .changeset/strange-rings-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
'eslint-config-seek': patch
---

Prevents the new curly-brace-presence rule from affecting children.

In the previous version, [react/jsx-curly-brace-presence][brace rule] was added to the eslint rules.
This was primarily intended to catch unnecessarily using braces around string props.

```diff
- <Stack space={'medium'}>
+ <Stack space="medium">
```

Because of the configuration we provided, this had the unintended side effect of removing curly braces inside child text that were being used to prevent the [unescaped entities rule].

```diff
- <Text>The available props are {'"up"'} and {'"down"'}</Text>
+ <Text>The available props are "up" and "down"</Text>
// This is now an unescaped entity error
```

To fix this, the curly brace rule will now ignore children, and only alert on prop values.

[brace rule]: https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-curly-brace-presence.md
[unescaped entities rule]: https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-unescaped-entities.md
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const reactRules = {
'react/prop-types': OFF,
'react/jsx-curly-brace-presence': [
ERROR,
{ props: 'never', children: 'never', propElementValues: 'always' },
{ props: 'never', children: 'ignore', propElementValues: 'always' },
Copy link
Member

Choose a reason for hiding this comment

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

sounds marginally better than a never child policy

],
};

Expand Down