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

stripIndent removes any run of the "right" number of whitespaces #21

Open
MWumpusZ opened this issue Apr 29, 2019 · 2 comments
Open

stripIndent removes any run of the "right" number of whitespaces #21

MWumpusZ opened this issue Apr 29, 2019 · 2 comments

Comments

@MWumpusZ
Copy link

stripIndent(" foo\n\t\tbar")

Results in "foo\nbar"

stripIndent has apparently determined that the ident is "two whitespaces", and will consume such from the beginning of every line of the file - regardless of what kind of whitespace it is.

Almost certainly a very minor corner case, but it still seems incorrect?

@jmdavis
Copy link
Owner

jmdavis commented May 3, 2019

No, stripIndent doesn't care what combination of ' ', '\t', and '\r' is used - only how many whitespace characters there are. It's designed with the idea that for it to have any chance of working reasonably, the text has to be reasonably formatted. If a file does something like mix normal spaces and tabs, then there's pretty much no way that you're going to be able to cleanly strip whitespace. stripIndent could certainly be made to remember exactly what the whitespace was on the first line and only strip that, but I would expect it to be less efficient, and I seriously question that it would actually work well in the general case. If the text isn't cleanly formatted, then the best way to strip the whitespace is going to depend on exactly what was done with that particular document.

I don't know. I can see why someone might want to strip only a specific sequence of whitespace, but stripIndent is doing exactly what it was intended to do, and the assumption from the get-go was that a function like this was only going to have any chance of working if the document was well-formatted.

@MWumpusZ
Copy link
Author

MWumpusZ commented May 6, 2019

Fair enough.
For our case, we decided we don't want to do stripIndent at all - at least not in the very general case where we were doing it until now.

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

No branches or pull requests

2 participants