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

Question: How to treat trailing whitespace when stripping margins #180

Open
nikomatsakis opened this issue May 14, 2022 · 1 comment
Open
Labels
question Further information is requested

Comments

@nikomatsakis
Copy link
Member

The current margin stripping logic seems mildly inconsistent to me:

  • we ignore lines that consistent only of whitespace
  • but then we persist the trailing whitespace in them that comes after the margin

I am inclined to think we should just strip trailing whitespace from every line, and then ignore empty lines for purposes of margin computation. The margin stripping logic is already kind of 'dwim', this seems typically desirable.

The other internally consistent option in my mind would be to never strip trailing whitespace but also count all non-empty lines for margin computation (even if they are only whitespace).

I'm open to either of them, to be honest. The reason I mildly lean towards stripping trailing whitespace is that some editors, when you press enter, will add in the whitespace needed for the indent (at least I think they do), and I can imagine people not realizing that and being confused why something like

    foo
  
    bar

prints as " foo\n\n bar\n" (hint: it's because the middle line has two spaces, so the margin is only 2, not 4).

@nikomatsakis
Copy link
Member Author

Margin stripping logic was last implemented in #178 and is documented here.

@xffxff xffxff added the question Further information is requested label May 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants