Skip to content

Commit

Permalink
Add lint rule that enforces curly brace opinions (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixhabib authored Sep 22, 2023
1 parent 143b57d commit 762f864
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .changeset/wild-mayflies-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
'eslint-config-seek': minor
---

Adds [react/jsx-curly-brace-presence][docs] as an error.
This removes unnecessary braces around strings in props and children.

It also enforces braces around expressions in props and children.

[docs]: https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-curly-brace-presence.md

### Examples

```diff
// Unecessary braces around string prop
- <Column width={'content'}>
+ <Column width="content">
```
```diff
// Unecessary braces around string child
- <Text>{'Hello'}</Text>
+ <Text>Hello</Text>
```
```diff
// Mandatory braces around prop expression
- <Button icon=<IconSearch />>
+ <Button icon={<IconSearch />}>
```
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ const reactRules = {
'react/no-children-prop': ERROR,
'react/display-name': OFF,
'react/prop-types': OFF,
'react/jsx-curly-brace-presence': [
ERROR,
{ props: 'never', children: 'never', propElementValues: 'always' },
],
};

/** @type {import('eslint').Linter.Config} */
Expand Down

0 comments on commit 762f864

Please sign in to comment.