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

chore(utils): improve stripWhitespace utility #9668

Merged
merged 1 commit into from Aug 13, 2021
Merged

chore(utils): improve stripWhitespace utility #9668

merged 1 commit into from Aug 13, 2021

Conversation

mrazauskas
Copy link

@mrazauskas mrazauskas commented Aug 13, 2021

Types of changes

  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

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:

<% if (options.debug) { %>
import { debug } from '<%= options.import.path %>'
<% } %>
// rest of the file

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. (Alternatively g 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 adding foo before (or bar after) \n as if these samples are taken from the middle of a string. Also after strip multiple blank lines regexp there must be only double \n\ns left in the string, so two last expects simply checks double \n\ns.

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly. (PR: #)
  • I have added tests to cover my changes (if not applicable, please state why)
  • All new and existing tests are passing.

@pi0 pi0 changed the title fix(utils): improve stripWhitespace utility chore(utils): improve stripWhitespace utility Aug 13, 2021
Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@pi0 pi0 merged commit 0145578 into nuxt:dev Aug 13, 2021
@mrazauskas mrazauskas deleted the fix-stripWhitespace branch August 13, 2021 11:22
@pi0 pi0 mentioned this pull request Jun 23, 2022
@danielroe danielroe added the 2.x label Jan 18, 2023
@danielroe danielroe mentioned this pull request Jan 19, 2023
@danielroe danielroe mentioned this pull request Feb 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants