Skip to content

Commit

Permalink
fix: upgrade to prettier@8 (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kent C. Dodds authored Sep 8, 2017
1 parent 0d101e4 commit 795a295
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion __mocks__/prettier-eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down
14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]> (http://kentcdodds.com/)",
"license": "MIT",
Expand All @@ -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"
},
Expand Down Expand Up @@ -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",
Expand Down
20 changes: 7 additions & 13 deletions src/format-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -276,3 +269,4 @@ function getIsIgnored(filename) {
instance.add(ignoreLines)
return instance.ignores.bind(instance)
}

0 comments on commit 795a295

Please sign in to comment.