diff --git a/.all-contributorsrc b/.all-contributorsrc index 012e447..ed84e56 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -131,6 +131,15 @@ "bug", "code" ] + }, + { + "login": "jackfranklin", + "name": "Jack Franklin", + "avatar_url": "https://avatars0.githubusercontent.com/u/193238?v=3", + "profile": "http://www.jackfranklin.co.uk", + "contributions": [ + "code" + ] } ] } diff --git a/README.md b/README.md index 1aa9c85..c3b6f67 100644 --- a/README.md +++ b/README.md @@ -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-13-orange.svg?style=flat-square)](#contributors) +[![All Contributors](https://img.shields.io/badge/all_contributors-14-orange.svg?style=flat-square)](#contributors) [![PRs Welcome][prs-badge]][prs] [![Donate][donate-badge]][donate] [![Code of Conduct][coc-badge]][coc] @@ -183,7 +183,7 @@ Thanks goes to these people ([emoji key][emojis]): | [
Kent C. Dodds](https://kentcdodds.com)
[๐Ÿ’ป](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") | [
Adam Harris](https://github.com/aharris88)
[๐Ÿ’ป](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") | [
Eric McCormick](https://ericmccormick.io)
[๐Ÿ‘€](#review-edm00se "Reviewed Pull Requests") | [
Joel Sequeira](https://github.com/joelseq)
[๐Ÿ“–](https://github.com/prettier/prettier-eslint-cli/commits?author=joelseq "Documentation") | [
Frank Taillandier](https://frank.taillandier.me)
| [
Adam Stankiewicz](http://sheerun.net)
[๐Ÿ’ป](https://github.com/prettier/prettier-eslint-cli/commits?author=sheerun "Code") | [
Stephen John Sorensen](http://www.stephenjohnsorensen.com/)
[๐Ÿ’ป](https://github.com/prettier/prettier-eslint-cli/commits?author=spudly "Code") | | :---: | :---: | :---: | :---: | :---: | :---: | :---: | -| [
Gandem](https://github.com/Gandem)
[๐Ÿ’ป](https://github.com/prettier/prettier-eslint-cli/commits?author=Gandem "Code") [โš ๏ธ](https://github.com/prettier/prettier-eslint-cli/commits?author=Gandem "Tests") | [
Matteo Ronchi](https://github.com/cef62)
[๐Ÿ›](https://github.com/prettier/prettier-eslint-cli/issues?q=author%3Acef62 "Bug reports") [๐Ÿ’ป](https://github.com/prettier/prettier-eslint-cli/commits?author=cef62 "Code") | [
Benoรฎt Zugmeyer](https://github.com/BenoitZugmeyer)
[๐Ÿ’ป](https://github.com/prettier/prettier-eslint-cli/commits?author=BenoitZugmeyer "Code") [โš ๏ธ](https://github.com/prettier/prettier-eslint-cli/commits?author=BenoitZugmeyer "Tests") | [
Charlike Mike Reagent](https://i.am.charlike.online)
[๐Ÿ’ป](https://github.com/prettier/prettier-eslint-cli/commits?author=tunnckoCore "Code") [โš ๏ธ](https://github.com/prettier/prettier-eslint-cli/commits?author=tunnckoCore "Tests") | [
Dion Dirza](https://github.com/diondirza)
[๐Ÿ›](https://github.com/prettier/prettier-eslint-cli/issues?q=author%3Adiondirza "Bug reports") | [
mrm007](https://github.com/mrm007)
[๐Ÿ›](https://github.com/prettier/prettier-eslint-cli/issues?q=author%3Amrm007 "Bug reports") [๐Ÿ’ป](https://github.com/prettier/prettier-eslint-cli/commits?author=mrm007 "Code") | +| [
Gandem](https://github.com/Gandem)
[๐Ÿ’ป](https://github.com/prettier/prettier-eslint-cli/commits?author=Gandem "Code") [โš ๏ธ](https://github.com/prettier/prettier-eslint-cli/commits?author=Gandem "Tests") | [
Matteo Ronchi](https://github.com/cef62)
[๐Ÿ›](https://github.com/prettier/prettier-eslint-cli/issues?q=author%3Acef62 "Bug reports") [๐Ÿ’ป](https://github.com/prettier/prettier-eslint-cli/commits?author=cef62 "Code") | [
Benoรฎt Zugmeyer](https://github.com/BenoitZugmeyer)
[๐Ÿ’ป](https://github.com/prettier/prettier-eslint-cli/commits?author=BenoitZugmeyer "Code") [โš ๏ธ](https://github.com/prettier/prettier-eslint-cli/commits?author=BenoitZugmeyer "Tests") | [
Charlike Mike Reagent](https://i.am.charlike.online)
[๐Ÿ’ป](https://github.com/prettier/prettier-eslint-cli/commits?author=tunnckoCore "Code") [โš ๏ธ](https://github.com/prettier/prettier-eslint-cli/commits?author=tunnckoCore "Tests") | [
Dion Dirza](https://github.com/diondirza)
[๐Ÿ›](https://github.com/prettier/prettier-eslint-cli/issues?q=author%3Adiondirza "Bug reports") | [
mrm007](https://github.com/mrm007)
[๐Ÿ›](https://github.com/prettier/prettier-eslint-cli/issues?q=author%3Amrm007 "Bug reports") [๐Ÿ’ป](https://github.com/prettier/prettier-eslint-cli/commits?author=mrm007 "Code") | [
Jack Franklin](http://www.jackfranklin.co.uk)
[๐Ÿ’ป](https://github.com/prettier/prettier-eslint-cli/commits?author=jackfranklin "Code") | This project follows the [all-contributors][all-contributors] specification. Contributions of any kind welcome! diff --git a/src/format-files.js b/src/format-files.js index 5b9805e..2412913 100644 --- a/src/format-files.js +++ b/src/format-files.js @@ -126,7 +126,13 @@ function formatFilesFromGlobs( } function onComplete() { - if (successes.length) { + const isNotSilent = logger.getLevel() !== logger.levels.SILENT + + /* use console.error directly here because + * - we don't want these messages prefixed + * - we want them to go to stderr, not stdout + */ + if (successes.length && isNotSilent) { console.error( messages.success({ success: chalk.green('success'), @@ -135,7 +141,7 @@ function formatFilesFromGlobs( }), ) } - if (failures.length) { + if (failures.length && isNotSilent) { process.exitCode = 1 console.error( messages.failure({ @@ -145,7 +151,7 @@ function formatFilesFromGlobs( }), ) } - if (unchanged.length) { + if (unchanged.length && isNotSilent) { console.error( messages.unchanged({ unchanged: chalk.gray('unchanged'), diff --git a/src/format-files.test.js b/src/format-files.test.js index edb1dc6..895960c 100644 --- a/src/format-files.test.js +++ b/src/format-files.test.js @@ -4,6 +4,7 @@ import findUpMock from 'find-up' import formatMock from 'prettier-eslint' import globMock from 'glob' import mockGetStdin from 'get-stdin' +import getLogger from 'loglevel-colored-level-prefix' import formatFiles from './format-files' jest.mock('fs') @@ -123,6 +124,18 @@ test('logs errors to the console if something goes wrong', async () => { ) }) +test('does not log anything to the console if logLevel is silent', async () => { + const log = getLogger() + const globs = ['eslint-config-error/*.js', 'src/**/2*.js'] + await formatFiles({ + _: globs, + write: true, + logLevel: log.levels.SILENT, + }) + expect(fsMock.writeFile).toHaveBeenCalledTimes(4) + expect(console.error).not.toHaveBeenCalled() +}) + test('forwards logLevel onto prettier-eslint', async () => { await formatFiles({_: ['src/**/1*.js'], logLevel: 'debug'}) const options = expect.objectContaining({logLevel: 'debug'})