precise-commits: Failing to format JSON files

I can’t format files using

./node_modules/.bin/precise-commits

My dependencies

"devDependencies": {
  "eslint": "4.17.0",
  "eslint-config-airbnb": "16.1.0",
  "eslint-plugin-import": "2.8.0",
  "eslint-plugin-jsx-a11y": "6.0.3",
  "eslint-plugin-react": "7.6.1",
  "husky": "0.14.3",
  "precise-commits": "1.0.0",
  "prettier": "1.10.2",
  "prettier-eslint": "8.8.1",
  "prettier-eslint-cli": "4.7.0",
}

.eslintrc

{
  "extends": "airbnb",
  "plugins": ["import", "react"],
  "env": {
    "browser": true,
    "node": true,
    "jest": true
  },
  "rules": {
    "jsx-quotes": ["error", "prefer-single"],
    "comma-dangle": ["error", "never"],
    "function-paren-newline": ["error", "consistent"],
    "react/jsx-no-bind": [0],
    "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
    "react/forbid-prop-types": [1, { "forbid": ["any", "array"] }]
  }
}

Output:

✔  precise-commits: 21 modified file(s) found
✔  [1/21] Processing file: package.json
✖  precise-commits: An Error occurred

{ SyntaxError: Unexpected token, expected ";" (2:9)
  1 | {
> 2 |   "name": "@urbica/celldata",
    |         ^
  3 |   "version": "0.1.0",
  4 |   "private": true,
  5 |   "scripts": {
    at createError (/Users/stepan/projects/celldata/node_modules/prettier/parser-babylon.js:1:110)
    at Object.parse (/Users/stepan/projects/celldata/node_modules/prettier/parser-babylon.js:1:986)
    at Object.parse$4 [as parse] (/Users/stepan/projects/celldata/node_modules/prettier/index.js:24274:19)
    at formatWithCursor (/Users/stepan/projects/celldata/node_modules/prettier/index.js:33650:27)
    at format (/Users/stepan/projects/celldata/node_modules/prettier/index.js:33695:10)
    at Object.format (/Users/stepan/projects/celldata/node_modules/prettier/index.js:33945:12)
    at /Users/stepan/projects/celldata/node_modules/precise-commits/lib/precise-formatters/prettier.js:42:64
    at Array.forEach (<anonymous>)
    at Object.formatRanges (/Users/stepan/projects/celldata/node_modules/precise-commits/lib/precise-formatters/prettier.js:41:25)
    at ModifiedFile.formatCharacterRangesWithinContents (/Users/stepan/projects/celldata/node_modules/precise-commits/lib/modified-file.js:25:61)
    at /Users/stepan/projects/celldata/node_modules/precise-commits/lib/index.js:72:26
    at Array.forEach (<anonymous>)
    at main (/Users/stepan/projects/celldata/node_modules/precise-commits/lib/index.js:45:27)
    at Object.<anonymous> (/Users/stepan/projects/celldata/node_modules/precise-commits/bin/index.js:74:1)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
  loc: { start: { line: 2, column: 9 } },
  codeFrame: '\u001b[0m \u001b[90m 1 | \u001b[39m{\u001b[0m\n\u001b[0m\u001b[31m\u001b[1m>\u001b[22m\u001b[39m\u001b[90m 2 | \u001b[39m  \u001b[32m"name"\u001b[39m\u001b[33m:\u001b[39m \u001b[32m"@urbica/celldata"\u001b[39m\u001b[33m,\u001b[39m\u001b[0m\n\u001b[0m \u001b[90m   | \u001b[39m        \u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[0m\n\u001b[0m \u001b[90m 3 | \u001b[39m  \u001b[32m"version"\u001b[39m\u001b[33m:\u001b[39m \u001b[32m"0.1.0"\u001b[39m\u001b[33m,\u001b[39m\u001b[0m\n\u001b[0m \u001b[90m 4 | \u001b[39m  \u001b[32m"private"\u001b[39m\u001b[33m:\u001b[39m \u001b[36mtrue\u001b[39m\u001b[33m,\u001b[39m\u001b[0m\n\u001b[0m \u001b[90m 5 | \u001b[39m  \u001b[32m"scripts"\u001b[39m\u001b[33m:\u001b[39m {\u001b[0m' }

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 9
  • Comments: 17 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Interesting, I would not expect it to throw on a package.json, because in theory prettier would just pick the right parser behind the scenes for the file type.

Please could you try adding a .prettierignore file with *.json as the contents and see if that temporarily gets rid of the issue?

Most likely, it was a diff that only included one line in package.json to add the script to run precise-commits.

"precisecommits": "precise-commits",

I think it’s possible that the prettier parser inference is just not working correctly when formatting ranges, hence the need to explicitly specify it as you have above. I will do some digging 😃