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

fix(stdout): remove extra newlines at EOF #54

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@
"bug",
"code"
]
},
{
"login": "BenoitZugmeyer",
"name": "Benoît Zugmeyer",
"avatar_url": "https://avatars2.githubusercontent.com/u/61787?v=3",
"profile": "https://github.com/BenoitZugmeyer",
"contributions": [
"code"
]
}
]
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CLI for [`prettier-eslint`][prettier-eslint]
[![downloads][downloads-badge]][npm-stat]
[![MIT License][license-badge]][LICENSE]

[![All Contributors](https://img.shields.io/badge/all_contributors-9-orange.svg?style=flat-square)](#contributors)
[![All Contributors](https://img.shields.io/badge/all_contributors-10-orange.svg?style=flat-square)](#contributors)
[![PRs Welcome][prs-badge]][prs]
[![Donate][donate-badge]][donate]
[![Code of Conduct][coc-badge]][coc]
Expand Down Expand Up @@ -177,9 +177,9 @@ The options supported are the same as [prettier-eslint](https://github.com/prett
Thanks goes to these people ([emoji key][emojis]):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
| [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub>Kent C. Dodds</sub>](https://kentcdodds.com)<br />[💻](https://github.com/prettier/prettier-eslint-cli/commits?author=kentcdodds) [📖](https://github.com/prettier/prettier-eslint-cli/commits?author=kentcdodds) 🚇 [⚠️](https://github.com/prettier/prettier-eslint-cli/commits?author=kentcdodds) | [<img src="https://avatars3.githubusercontent.com/u/3266363?v=3" width="100px;"/><br /><sub>Adam Harris</sub>](https://github.com/aharris88)<br />[💻](https://github.com/prettier/prettier-eslint-cli/commits?author=aharris88) [📖](https://github.com/prettier/prettier-eslint-cli/commits?author=aharris88) 👀 | [<img src="https://avatars.githubusercontent.com/u/622118?v=3" width="100px;"/><br /><sub>Eric McCormick</sub>](https://ericmccormick.io)<br />👀 | [<img src="https://avatars.githubusercontent.com/u/12389411?v=3" width="100px;"/><br /><sub>Joel Sequeira</sub>](https://github.com/joelseq)<br />[📖](https://github.com/prettier/prettier-eslint-cli/commits?author=joelseq) | [<img src="https://avatars.githubusercontent.com/u/103008?v=3" width="100px;"/><br /><sub>Frank Taillandier</sub>](https://frank.taillandier.me)<br /> | [<img src="https://avatars3.githubusercontent.com/u/292365?v=3" width="100px;"/><br /><sub>Adam Stankiewicz</sub>](http://sheerun.net)<br />[💻](https://github.com/prettier/prettier-eslint-cli/commits?author=sheerun) | [<img src="https://avatars3.githubusercontent.com/u/487068?v=3" width="100px;"/><br /><sub>Stephen John Sorensen</sub>](http://www.stephenjohnsorensen.com/)<br />[💻](https://github.com/prettier/prettier-eslint-cli/commits?author=spudly) |
| [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub>Kent C. Dodds</sub>](https://kentcdodds.com)<br />[💻](https://github.com/prettier/prettier-eslint-cli/commits?author=kentcdodds "Code") [📖](https://github.com/prettier/prettier-eslint-cli/commits?author=kentcdodds "Documentation") [🚇](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/prettier/prettier-eslint-cli/commits?author=kentcdodds "Tests") | [<img src="https://avatars3.githubusercontent.com/u/3266363?v=3" width="100px;"/><br /><sub>Adam Harris</sub>](https://github.com/aharris88)<br />[💻](https://github.com/prettier/prettier-eslint-cli/commits?author=aharris88 "Code") [📖](https://github.com/prettier/prettier-eslint-cli/commits?author=aharris88 "Documentation") [👀](#review-aharris88 "Reviewed Pull Requests") | [<img src="https://avatars.githubusercontent.com/u/622118?v=3" width="100px;"/><br /><sub>Eric McCormick</sub>](https://ericmccormick.io)<br />[👀](#review-edm00se "Reviewed Pull Requests") | [<img src="https://avatars.githubusercontent.com/u/12389411?v=3" width="100px;"/><br /><sub>Joel Sequeira</sub>](https://github.com/joelseq)<br />[📖](https://github.com/prettier/prettier-eslint-cli/commits?author=joelseq "Documentation") | [<img src="https://avatars.githubusercontent.com/u/103008?v=3" width="100px;"/><br /><sub>Frank Taillandier</sub>](https://frank.taillandier.me)<br /> | [<img src="https://avatars3.githubusercontent.com/u/292365?v=3" width="100px;"/><br /><sub>Adam Stankiewicz</sub>](http://sheerun.net)<br />[💻](https://github.com/prettier/prettier-eslint-cli/commits?author=sheerun "Code") | [<img src="https://avatars3.githubusercontent.com/u/487068?v=3" width="100px;"/><br /><sub>Stephen John Sorensen</sub>](http://www.stephenjohnsorensen.com/)<br />[💻](https://github.com/prettier/prettier-eslint-cli/commits?author=spudly "Code") |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| [<img src="https://avatars0.githubusercontent.com/u/11560964?v=3" width="100px;"/><br /><sub>Gandem</sub>](https://github.com/Gandem)<br />[💻](https://github.com/prettier/prettier-eslint-cli/commits?author=Gandem) [⚠️](https://github.com/prettier/prettier-eslint-cli/commits?author=Gandem) | [<img src="https://avatars0.githubusercontent.com/u/129991?v=3" width="100px;"/><br /><sub>Matteo Ronchi</sub>](https://github.com/cef62)<br />[🐛](https://github.com/prettier/prettier-eslint-cli/issues?q=author%3Acef62) [💻](https://github.com/prettier/prettier-eslint-cli/commits?author=cef62) |
| [<img src="https://avatars0.githubusercontent.com/u/11560964?v=3" width="100px;"/><br /><sub>Gandem</sub>](https://github.com/Gandem)<br />[💻](https://github.com/prettier/prettier-eslint-cli/commits?author=Gandem "Code") [⚠️](https://github.com/prettier/prettier-eslint-cli/commits?author=Gandem "Tests") | [<img src="https://avatars0.githubusercontent.com/u/129991?v=3" width="100px;"/><br /><sub>Matteo Ronchi</sub>](https://github.com/cef62)<br />[🐛](https://github.com/prettier/prettier-eslint-cli/issues?q=author%3Acef62 "Bug reports") [💻](https://github.com/prettier/prettier-eslint-cli/commits?author=cef62 "Code") | [<img src="https://avatars2.githubusercontent.com/u/61787?v=3" width="100px;"/><br /><sub>Benoît Zugmeyer</sub>](https://github.com/BenoitZugmeyer)<br />[💻](https://github.com/prettier/prettier-eslint-cli/commits?author=BenoitZugmeyer "Code") |
<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors][all-contributors] specification. Contributions of any kind welcome!
Expand Down
4 changes: 2 additions & 2 deletions src/format-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async function formatStdin(prettierESLintOptions) {
const stdinValue = (await getStdin()).trim()
try {
const formatted = format({text: stdinValue, ...prettierESLintOptions})
console.log(formatted)
process.stdout.write(formatted)
return Promise.resolve(formatted)
} catch (error) {
logger.error(
Expand Down Expand Up @@ -192,7 +192,7 @@ function formatFile(filePath, prettierESLintOptions, cliOptions) {
})
} else {
format$ = format$.map(info => {
console.log(info.formatted)
process.stdout.write(info.formatted)
return info
})
}
Expand Down
12 changes: 6 additions & 6 deletions src/format-files.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import formatFiles from './format-files'
jest.mock('fs')

beforeEach(() => {
console.log = jest.fn()
process.stdout.write = jest.fn()
console.error = jest.fn()
formatMock.mockClear()
fsMock.writeFile.mockClear()
Expand All @@ -23,11 +23,11 @@ test('sanity test', async () => {
expect(fsMock.readFile).toHaveBeenCalledTimes(6)
expect(formatMock).toHaveBeenCalledTimes(6)
expect(fsMock.writeFile).toHaveBeenCalledTimes(0)
expect(console.log).toHaveBeenCalledTimes(6)
expect(process.stdout.write).toHaveBeenCalledTimes(6)
expect(console.error).toHaveBeenCalledTimes(1)
const mockOutput = expect.stringMatching(/MOCK_OUTPUT.*index.js/)
const successOutput = expect.stringMatching(/success.*6.*files/)
expect(console.log).toHaveBeenCalledWith(mockOutput)
expect(process.stdout.write).toHaveBeenCalledWith(mockOutput)
expect(console.error).toHaveBeenCalledWith(successOutput)
})

Expand Down Expand Up @@ -61,8 +61,8 @@ test('should accept stdin', async () => {
// the trim is part of the test
const text = mockGetStdin.stdin.trim()
expect(formatMock).toHaveBeenCalledWith(expect.objectContaining({text}))
expect(console.log).toHaveBeenCalledTimes(1)
expect(console.log).toHaveBeenCalledWith('MOCK_OUTPUT for stdin')
expect(process.stdout.write).toHaveBeenCalledTimes(1)
expect(process.stdout.write).toHaveBeenCalledWith('MOCK_OUTPUT for stdin')
})

test('will write to files if that is specified', async () => {
Expand Down Expand Up @@ -91,7 +91,7 @@ test('handles file errors gracefully', async () => {
test('does not print success if there were no successful files', async () => {
await formatFiles({_: ['no-match/*.js']})
const successOutput = expect.stringMatching(/unhandled error/)
expect(console.log).not.toHaveBeenCalledWith(successOutput)
expect(process.stdout.write).not.toHaveBeenCalledWith(successOutput)
})

test('fails gracefully if something odd happens', async () => {
Expand Down