chore(utils): improve stripWhitespace
utility
#9668
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Types of changes
Description
This is a minor fix. I was playing with plugin templates and found that
stripWhitespace
utility is not removing empty lines if these appear at the beginning of a file. For instance, empty lines will be left if a template begins like this one:A regexp was added to remove empty lines if they appear at the beginning of a file.
g
, global search flag seemed to be unnecessary, because globally there is just one beginning (or end) of a string. Or I missed something important?g
is not included in the new regexp. For consistency I removed it in the regexp which was targeting the end of a string. (Alternativelyg
flag could be added to both.)Test
After the change, the
expect
with'\n\n\n\f\r\f}'
string was failing. I improved this and other tests by addingfoo
before (orbar
after)\n
as if these samples are taken from the middle of a string. Also afterstrip multiple blank lines
regexp there must be only double\n\n
s left in the string, so two lastexpect
s simply checks double\n\n
s.Checklist: