Skip to content

Commit 795a295

Browse files
author
Kent C. Dodds
authored
fix: upgrade to prettier@8 (#103)
1 parent 0d101e4 commit 795a295

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

__mocks__/prettier-eslint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// so we just return some spies here and assert
66
// that we're calling prettier-eslint APIs correctly
77
// eslint-disable-next-line require-await
8-
const format = jest.fn(async ({text, filePath = ''}) => {
8+
const format = jest.fn(({text, filePath = ''}) => {
99
if (text === 'MOCK_SYNTAX_ERROR' || filePath.includes('syntax-error')) {
1010
throw new Error('Mock error for a syntax error')
1111
} else if (filePath.includes('eslint-config-error')) {

package.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
"scripts": {
1313
"start": "nps",
1414
"test": "nps test",
15-
"precommit":
16-
"lint-staged && opt --in pre-commit --exec \"npm start validate\""
15+
"precommit": "lint-staged && opt --in pre-commit --exec \"npm start validate\""
1716
},
18-
"files": ["dist"],
17+
"files": [
18+
"dist"
19+
],
1920
"keywords": [],
2021
"author": "Kent C. Dodds <[email protected]> (http://kentcdodds.com/)",
2122
"license": "MIT",
@@ -35,7 +36,7 @@
3536
"lodash.memoize": "^4.1.2",
3637
"loglevel-colored-level-prefix": "^1.0.0",
3738
"messageformat": "^1.0.2",
38-
"prettier-eslint": "^7.0.0",
39+
"prettier-eslint": "^8.0.0",
3940
"rxjs": "^5.3.0",
4041
"yargs": "8.0.2"
4142
},
@@ -63,7 +64,10 @@
6364
"yargs-parser": "7.0.0"
6465
},
6566
"lint-staged": {
66-
"*.+(js|json)": ["node ./dist/index --write", "git add"]
67+
"*.+(js|json)": [
68+
"node ./dist/index --write",
69+
"git add"
70+
]
6771
},
6872
"repository": {
6973
"type": "git",

src/format-files.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function formatFilesFromArgv({
7878
async function formatStdin(prettierESLintOptions) {
7979
const stdinValue = (await getStdin()).trim()
8080
try {
81-
const formatted = await format({text: stdinValue, ...prettierESLintOptions})
81+
const formatted = format({text: stdinValue, ...prettierESLintOptions})
8282
process.stdout.write(formatted)
8383
return Promise.resolve(formatted)
8484
} catch (error) {
@@ -197,18 +197,11 @@ function getFilesFromGlob(ignoreGlobs, applyEslintIgnore, fileGlob) {
197197

198198
function formatFile(filePath, prettierESLintOptions, cliOptions) {
199199
const fileInfo = {filePath}
200-
let format$ = rxReadFile(filePath, 'utf8').mergeMap(text => {
201-
const promise = format({
202-
text,
203-
filePath,
204-
...prettierESLintOptions,
205-
}).then(formatted => {
206-
fileInfo.text = text
207-
fileInfo.formatted = formatted
208-
fileInfo.unchanged = fileInfo.text === fileInfo.formatted
209-
return fileInfo
210-
})
211-
return Rx.Observable.fromPromise(promise)
200+
let format$ = rxReadFile(filePath, 'utf8').map(text => {
201+
fileInfo.text = text
202+
fileInfo.formatted = format({text, filePath, ...prettierESLintOptions})
203+
fileInfo.unchanged = fileInfo.text === fileInfo.formatted
204+
return fileInfo
212205
})
213206

214207
if (cliOptions.write) {
@@ -276,3 +269,4 @@ function getIsIgnored(filename) {
276269
instance.add(ignoreLines)
277270
return instance.ignores.bind(instance)
278271
}
272+

0 commit comments

Comments
 (0)