-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Possible jsx-no-allocation-in-props rule #1888
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
base: master
Are you sure you want to change the base?
Possible jsx-no-allocation-in-props rule #1888
Conversation
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.
I don't think the name "no bind" makes sense for objects and arrays :-/
## Rule Options | ||
|
||
```js | ||
"react/jsx-no-allocation-in-props": [<enabled>, { |
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.
array literals, and object literals, should probably have separate controls
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.
I actually couldn't come up with a use case where an array would be supplied as a prop to a DOM component, that probably is not a valid case?
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.
for DOM components sure, but i meant, i should be able to configure this rule to only warn on object literals, or to only warn on array literals.
README.md
Outdated
@@ -150,6 +150,7 @@ Enable the rules that you would like to use. | |||
* [react/jsx-key](docs/rules/jsx-key.md): Validate JSX has key prop when in array or iterator | |||
* [react/jsx-max-depth](docs/rules/jsx-max-depth.md): Validate JSX maximum depth | |||
* [react/jsx-max-props-per-line](docs/rules/jsx-max-props-per-line.md): Limit maximum of props on a single line in JSX (fixable) | |||
* [react/jsx-no-allocation-in-props](docs/rules/jsx-no-allocation-in-props.md): Prevent usage of `[]` and `{}` in JSX props |
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.
does this need a jsx-
prefix? couldn't it also apply to React.createElement
?
Oh yeah, a new rule (if we go that way) would have a different name. |
Removed |
776638b
to
027fb23
Compare
I don't think "allocations" is the best word to use in a memory-managed language, where allocations aren't user-observable. |
Oh, for sure, this name leaves much to be desired. I guess this is more |
59af733
to
865ed16
Compare
069314a
to
181c68f
Compare
I see this was updated recently. Any chance it'll ship anytime soon? Would love to see this one live! |
@benasher44 it hasn't been updated since 2018; those 4 force pushes are to master, not this PR. If you'd like to help, please comment a link to an updated branch (NOT a new PR) and i can update this one :-) |
@ljharb just pushed to no-allocation-in-props in benasher44/eslint-plugin-react. Only thing I'm having trouble with right now is this error running the test locally:
I get this error running other tests locally though too, so I think I'm just missing some configuration in my local env/setup. Any idea what it might be? |
Ah wait I think I figured that out. Hold please! |
Sweet okay pushed again. Tests pass now! |
Looks like last thing being discussed was naming. Are we good with |
@ljharb just checking in — happy to do the work if more is needed! |
380e32c
to
51d342b
Compare
cc @ljharb
So... now that I know what future prospects are for
jsx-no-bind
(#1633 (comment)) I actually have doubts that it makes sense to add this new rule on its own. The code here is basically the same asjsx-no-bind
. Perhaps we could instead just update that rule to handle object creation. Thoughts?