Skip to content

Commit

Permalink
feat(options): add sillyLogs option
Browse files Browse the repository at this point in the history
Provides for configuration of whether to dump the eslintConfig and prettierOptions to the console,
defaults to false.

Test is still WIP.

refs #7
  • Loading branch information
edm00se committed Jan 19, 2017
1 parent e2fdfbf commit 5a92d88
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -109,6 +109,12 @@ one, then it will use the version that `prettier-eslint` has installed locally.

This is basically the same as `eslintPath` except for the `prettier` module.

#### sillyLogs (?Boolean)

When set to `true`, `prettier-eslint` will dump the contents of both the detected `eslintConfig` and `prettierOptions`
configuration objects to the console. This defaults to `false` as it is primarily for debugging.
"globally."

### throws

`prettier-eslint` will propagate errors when either `prettier` or `eslint` fails for one reason or another. In addition
Expand Down
12 changes: 11 additions & 1 deletion src/index.js
@@ -1,8 +1,9 @@

/* eslint no-console:0, global-require:0, import/no-dynamic-require:0 */
import path from 'path'
import {getPrettierOptionsFromESLintRules} from './utils'

const options = {disableLog: false}
const options = {disableLog: false, sillyLogs: false}
// CommonJS + ES6 modules... is it worth it? Probably not...
module.exports = format
module.exports.options = options
Expand All @@ -23,6 +24,7 @@ module.exports.options = options
* @param {Object} options.prettierOptions - the options to pass for
* formatting with `prettier`. If not provided, prettier-eslint will attempt
* to create the options based on the eslintConfig
* @param {Boolean} options.sillyLogs - enables silly logging (default: false)
* @return {String} - the formatted string
*/
function format({
Expand All @@ -33,9 +35,17 @@ function format({
disableLog = options.disableLog,
eslintConfig = getConfig(filePath, eslintPath),
prettierOptions = getPrettierOptionsFromESLintRules(eslintConfig),
sillyLogs = options.sillyLogs,
}) {
const originalLogValue = options.disableLog
options.disableLog = disableLog
if (sillyLogs) {
console.log('😜 logs for eslintConfig and prettierOptions:')
console.dir({
eslintConfig,
prettierOptions,
}, null, true)
}

try {
// console.log('text', text)
Expand Down
11 changes: 11 additions & 0 deletions src/index.test.js
Expand Up @@ -114,6 +114,17 @@ test('console.error will not be called if disableLog is set', () => {
getConfigForFile.throwError = null
})

test('console receives output of both eslintConfig and prettierOptions when sillyLogs is set', () => {
format.options.sillyLogs = true

format({text: ''})
// TODO: fix this test, since it fails on the matcher toHaveBeenCalledTimes
expect(console.log).toHaveBeenCalledTimes(1)
expect(console.dir).toHaveBeenCalledTimes(1)

format.options.sillyLogs = false
})

test(`when prettier throws, log to console.error but don't fail`, () => {
const {format: prettierMockFormat} = prettierMock
const error = 'something bad happened'
Expand Down

0 comments on commit 5a92d88

Please sign in to comment.