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

Brackets in template literals #670

Open
mikeal opened this issue Oct 31, 2016 · 4 comments

Comments

@mikeal
Copy link

commented Oct 31, 2016

So, the current standardjs config enforces:

let init = () => {}
let text = 'asdf'
funky`
${init}
<div>
  <span>${text}</span>
  <span>${o => o.attr || 'default'}</span>
</div>
`

And does not allow:

let init = () => {}
let text = 'asdf'
funky`
${ init }
<div>
  <span>${ text }</span>
  <span>${ o => o.attr || 'default' }</span>
</div>
`

I find the latter much more readable and am surprised it is being enforced this way.

Is this particular use case intended to be enforced this way or is this just brackets being enforced inside of template literals the same way they are outside because of a broader setting?

@mikeal

This comment has been minimized.

Copy link
Author

commented Nov 6, 2016

@feross ^^

@LinusU

This comment has been minimized.

Copy link
Member

commented Nov 6, 2016

I personally prefer there to be only one way of doing things, and, perhaps unfortunately, we already enforce it to be without spaces. Switching now could potentially be painful for our users...

@mikeal

This comment has been minimized.

Copy link
Author

commented Nov 8, 2016

This just isn't consistent with other rules regarding brackets. For instance, all of these are allowed:

let test = { test: 'asdf' }
let testfunc = () => { 'asdf' }

In fact, the following is explicitly NOT ALLOWED.

let testfunc = () => {'asdf'}

Which is the exact opposite of the enforcement of brackets in template literals.

As far as switching costs is concerned, template literals are a relatively new feature and switching now in order to make it more consistent shouldn't be too costly.

Because of the way the literals work any whitespace before and after the brackets ends up being real whitespace in the string. In practice this means that shoving all the characters inside the replacement into the brackets ends up being really noisy and visually confusing.

I'm using template literals enough at this point that I'm considering getting off of standardjs if this ends up being what is enforced long term. It just doesn't make any sense and is out of alignment with the enforcement of white space in other places.

@feross

This comment has been minimized.

Copy link
Member

commented Nov 23, 2016

Point taken. We do need to make some decisions to make things more consistent in v9.

@feross feross added this to the standard v10 milestone Feb 9, 2017

@feross feross modified the milestones: standard v11, standard v10 Mar 2, 2017

@feross feross modified the milestones: standard v12, standard v13 Aug 28, 2018

@feross feross modified the milestones: standard v13, standard v14 Jul 5, 2019

@feross feross modified the milestones: standard 14, standard 15 Aug 15, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants
You can’t perform that action at this time.