From 795a2953cb6d6ad28f721b856c369abf3c24e0d9 Mon Sep 17 00:00:00 2001 From: "Kent C. Dodds" Date: Thu, 7 Sep 2017 22:23:11 -0600 Subject: [PATCH] fix: upgrade to prettier@8 (#103) --- __mocks__/prettier-eslint.js | 2 +- package.json | 14 +++++++++----- src/format-files.js | 20 +++++++------------- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/__mocks__/prettier-eslint.js b/__mocks__/prettier-eslint.js index 450a832..b263a6b 100644 --- a/__mocks__/prettier-eslint.js +++ b/__mocks__/prettier-eslint.js @@ -5,7 +5,7 @@ // so we just return some spies here and assert // that we're calling prettier-eslint APIs correctly // eslint-disable-next-line require-await -const format = jest.fn(async ({text, filePath = ''}) => { +const format = jest.fn(({text, filePath = ''}) => { if (text === 'MOCK_SYNTAX_ERROR' || filePath.includes('syntax-error')) { throw new Error('Mock error for a syntax error') } else if (filePath.includes('eslint-config-error')) { diff --git a/package.json b/package.json index 31ecab0..1191884 100644 --- a/package.json +++ b/package.json @@ -12,10 +12,11 @@ "scripts": { "start": "nps", "test": "nps test", - "precommit": - "lint-staged && opt --in pre-commit --exec \"npm start validate\"" + "precommit": "lint-staged && opt --in pre-commit --exec \"npm start validate\"" }, - "files": ["dist"], + "files": [ + "dist" + ], "keywords": [], "author": "Kent C. Dodds (http://kentcdodds.com/)", "license": "MIT", @@ -35,7 +36,7 @@ "lodash.memoize": "^4.1.2", "loglevel-colored-level-prefix": "^1.0.0", "messageformat": "^1.0.2", - "prettier-eslint": "^7.0.0", + "prettier-eslint": "^8.0.0", "rxjs": "^5.3.0", "yargs": "8.0.2" }, @@ -63,7 +64,10 @@ "yargs-parser": "7.0.0" }, "lint-staged": { - "*.+(js|json)": ["node ./dist/index --write", "git add"] + "*.+(js|json)": [ + "node ./dist/index --write", + "git add" + ] }, "repository": { "type": "git", diff --git a/src/format-files.js b/src/format-files.js index ed1cb2c..5923d20 100644 --- a/src/format-files.js +++ b/src/format-files.js @@ -78,7 +78,7 @@ function formatFilesFromArgv({ async function formatStdin(prettierESLintOptions) { const stdinValue = (await getStdin()).trim() try { - const formatted = await format({text: stdinValue, ...prettierESLintOptions}) + const formatted = format({text: stdinValue, ...prettierESLintOptions}) process.stdout.write(formatted) return Promise.resolve(formatted) } catch (error) { @@ -197,18 +197,11 @@ function getFilesFromGlob(ignoreGlobs, applyEslintIgnore, fileGlob) { function formatFile(filePath, prettierESLintOptions, cliOptions) { const fileInfo = {filePath} - let format$ = rxReadFile(filePath, 'utf8').mergeMap(text => { - const promise = format({ - text, - filePath, - ...prettierESLintOptions, - }).then(formatted => { - fileInfo.text = text - fileInfo.formatted = formatted - fileInfo.unchanged = fileInfo.text === fileInfo.formatted - return fileInfo - }) - return Rx.Observable.fromPromise(promise) + let format$ = rxReadFile(filePath, 'utf8').map(text => { + fileInfo.text = text + fileInfo.formatted = format({text, filePath, ...prettierESLintOptions}) + fileInfo.unchanged = fileInfo.text === fileInfo.formatted + return fileInfo }) if (cliOptions.write) { @@ -276,3 +269,4 @@ function getIsIgnored(filename) { instance.add(ignoreLines) return instance.ignores.bind(instance) } +