-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failing to format JSON files #2
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 |
Adding |
I am having the same issue with |
So it seems like one has to ignore all |
Thanks for confirming @mfru. I will need to dig into why this is happening, as I mentioned above, I would have expected Prettier to "just work" with JSON files. I'll update this issue with progress. |
As a workaround I found you can use this setup to workaround the json (and md) parsing issues (this example from package.json). "prettier": {
"singleQuote": true,
"overrides": [
{
"files": "*.md",
"options": {
"parser": "markdown"
}
},
{
"files": "*.json",
"options": {
"parser": "json"
}
}
]
} Edit On some playing around it actually seems that prettier can't work on partial commits of JSON files. This worked fine when adding a new json file but when editing the same file I get this:
|
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 :) |
I've got v1.0.2 and I'm getting similar errors.
Adding package.json to the ignore file will let the commit proceed. The commit has the following:
|
@SunburnedGoose Can you provide the exact diff? |
This is likely an issue with prettier rather than with this package, see prettier/prettier#4009 |
Probably. If precise-commits is just trying to prettify the delta, it could have this issue. When I switched back to husky and lint-staged, it was fine, but it was also processing the entire document. I'll try it again when prettier is updated. |
Interestingly if you include some form of jspn (like closing curly-bracket) it will not error. Probably difficult to guess the json context. |
I'll get you the diff when I'm at my home PC. Was using a local git to test. |
Most likely, it was a diff that only included one line in package.json to add the script to run precise-commits.
|
Thanks a lot for triaging @erik-lundgren :) |
@JamesHenry Happy to help :) EDIT: Should this be reopened with "reported prettier issue" label? @SunburnedGoose Yeah I believe you're running into the prettier issue linked above. I'll try to keep this place updated whem something happens to that issue |
precise-commits and prettier don't play well together when it comes to json files. See: nrwl/precise-commits#2
I'm still having the issue with
|
I can't format files using
My dependencies
.eslintrc
Output:
The text was updated successfully, but these errors were encountered: