I'd like to suggest a new rule which disallows this:
<MyComponent someProp={'foo'} />
where it should be:
<MyComponent someProp="foo" />
And the same for children/nodes:
<MyComponent>{'Foo'}</MyComponent>
Where it should be:
<MyComponent>Foo</MyComponent>
I feel convinced this already exists, but can't find it anywhere.
This is an essential thing to cover; it definitely should be a rule.
It would need to be separately configurable for props and children (curlies are often needed for children for explicit whitespace) to require, forbid, or ignore.
Hello @ljharb, I would like to give this one a shot. Hopefully, I won't run into a lot of difficulties. I would appreciate any pointer though especially regarding the last thing you mentioned in your comment. Thank you!
@jackyho112 essentially what I mean is that the rule configuration must allow an option like { props: 'always', children: 'never' } (where always/never/ignore are the three valid values)
Hello @ljharb, I am working on this right now and I have one question. By always, never and ignore, do you mean respectively enforce always having curly braces, enforce never having unnecessary curly braces and ignore the rule or always check for unnecessary curly braces, never check for unnecessary curly braces and ignore the rule?
If it is the latter, it doesn't seem like we need both never and ignore.
I mean the former - "always require", "always prohibit", and "ignore the rule"
@ljharb
Thanks for replying! I will make the changes.
Thanks! (It'd be great if you reused #1349 instead of opening up a new PR)
Will do!
Very cool rule! 馃槃
Just out of interest, is there a technical reason that the fixer only works for one of the options (only for never but not for always) ?
@jseminck
My bad. I misinterpreted the eslint docs. I think I can fix for always as well.
I think this can be closed (via #1349)
Yes, thanks - closed by #1349.
Most helpful comment
@jseminck
My bad. I misinterpreted the eslint docs. I think I can fix for
alwaysas well.