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

Trailing spaces inside a multi-line string #482

Closed
simonratner opened this issue Apr 4, 2016 · 5 comments

Comments

@simonratner
Copy link

commented Apr 4, 2016

The following triggers an error:

let str = `
${a}
      <-- significant trailing whitespace
${b}
`

Current workaround is to surround the block with /* eslint-disable no-trailing-space */, but it would be better if whitespace inside strings was ignored for the purposes of this check.

@feross

This comment has been minimized.

Copy link
Member

commented Apr 4, 2016

Reported this to ESLint: eslint/eslint#5786

@feross feross added bug blocked labels Apr 4, 2016

@LinusU

This comment has been minimized.

Copy link
Member

commented Apr 5, 2016

Hmm, I don't know though, many people uses editors that trim trailing whitespace and I think that it might just be a very idea to force the author of the code to solve it in another way up front, rather than having the code break later when someone saves the file in e.g. Atom. If you really need trailing whitespace in the string you could write it as follows.

let str = [
  '',
  a,
  '      ',
  b,
  ''
].join('\n')
@feross

This comment has been minimized.

Copy link
Member

commented Apr 5, 2016

Yeah, I sort of agree with you @LinusU.

@simonratner

This comment has been minimized.

Copy link
Author

commented Apr 5, 2016

Actually I agree, automatic trimming of trailing whitespace is common and will just cause problems later.
In my particular case, I needed any whitespace, so \t is a solution that isn't too ugly, but in other cases something like your suggestion or even ${ ' ' } will work in a template string.

@feross

This comment has been minimized.

Copy link
Member

commented Apr 5, 2016

Okay, going to close this since it's reported to ESLint and they'll do with it what they will at this point.

@feross feross closed this Apr 5, 2016

@lock lock bot locked as resolved and limited conversation to collaborators May 10, 2018

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