Skip to content

Commit

Permalink
Trims the textual content on "addFile"
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Jun 12, 2021
1 parent d900df4 commit dfc1600
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/createTeardown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ export function addFile(
await fsExtra.createFile(absoluteFilePath)

if (content) {
const writeContent =
typeof content === 'string'
? util.promisify(fs.writeFile)
: fsExtra.writeJSON

await writeContent(absoluteFilePath, content)
if (typeof content === 'string') {
const normalizedContent = content.trim()

This comment has been minimized.

Copy link
@tjenkinson

tjenkinson Jul 4, 2021

Contributor

👋 hi @kettanaito curious what triggered this change?

Removing the white space was actually a breaking change for eslint/eslintrc#44 (comment) because it broke the indentation in a yaml file that was already partly indented.

This comment has been minimized.

Copy link
@kettanaito

kettanaito Jul 4, 2021

Author Owner

Hey, @tjenkinson. My bad for not releasing this as a breaking change.

Whitespace trimming was added to prevent newline escaping when specifying multi-line file contents:

addFile('name.js', `
foo
`

This would result in a file like so:

foo

Does it corrupt other whitespace in the file's content?

This comment has been minimized.

Copy link
@tjenkinson

tjenkinson Jul 4, 2021

Contributor

IMO the output above is what I’d expect. It should be up to the user to do the trim() in their code if they want that :)

This comment has been minimized.

Copy link
@tjenkinson

tjenkinson Jul 4, 2021

Contributor

The reason it failed in the yaml file is because

    a:
        - b
    c:

becomes

a:
        - b
    c:

This comment has been minimized.

Copy link
@kettanaito

kettanaito Jul 4, 2021

Author Owner

This doesn't seem right. Please, would you have a chance to issue a pull request that reverts the .trim() change?
I can indeed handle the trimming on the usage surface when needed.

This comment has been minimized.

Copy link
@tjenkinson

tjenkinson Jul 4, 2021

Contributor

done #3

await fs.promises.writeFile(absoluteFilePath, normalizedContent)
} else {
await fsExtra.writeJSON(absoluteFilePath, content)
}
}

return absoluteFilePath
Expand Down

0 comments on commit dfc1600

Please sign in to comment.