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

Feature request: no-unnecessary-curly #1310

Closed
Billy- opened this issue Jul 20, 2017 · 12 comments
Closed

Feature request: no-unnecessary-curly #1310

Billy- opened this issue Jul 20, 2017 · 12 comments

Comments

@Billy-
Copy link

Billy- commented Jul 20, 2017

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>

@ljharb
Copy link
Member

ljharb commented Jul 20, 2017

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.

@jackyho112
Copy link
Contributor

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!

@ljharb
Copy link
Member

ljharb commented Jul 31, 2017

@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)

@jackyho112
Copy link
Contributor

jackyho112 commented Aug 7, 2017

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.

@ljharb
Copy link
Member

ljharb commented Aug 7, 2017

I mean the former - "always require", "always prohibit", and "ignore the rule"

@jackyho112
Copy link
Contributor

@ljharb

Thanks for replying! I will make the changes.

@ljharb
Copy link
Member

ljharb commented Aug 7, 2017

Thanks! (It'd be great if you reused #1349 instead of opening up a new PR)

@jackyho112
Copy link
Contributor

Will do!

@jseminck
Copy link
Contributor

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) ?

@jackyho112
Copy link
Contributor

jackyho112 commented Aug 10, 2017

@jseminck
My bad. I misinterpreted the eslint docs. I think I can fix for always as well.

@alexzherdev
Copy link
Contributor

I think this can be closed (via #1349)

@ljharb
Copy link
Member

ljharb commented Jun 28, 2018

Yes, thanks - closed by #1349.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants