I too have been waiting for a PR which was released with 1.14 https://github.com/prettier/prettier/pull/4830
YAML formatting can also be supported after upgrading to 1.14.0:
https://prettier.io/blog/2018/07/29/1.14.0.html#support-yaml-4563-4742-4773-4854-by-ikatyang
is there any way that the vs-code extension could use the prettier version already installed in a project (or your global prettier version). Since versions change styles, it can be really annoying when your git commits get formatted and then your editor says you have problems (because they use two different versions of prettier).
IMO, would be better to default to version used by project, if its in their package.json as a devDependency.
@joshuarossi that should already be the case. Hover over the Prettier status bar item in the bottom right and see which version it uses.
@RobinMalfait So, that part is working (i can see that when i hover it says 1.14.0), the issue I was having was that my editor wants to format it one way, but my precommit hook wants to format it a different way. I have an exact dependency on version 1.14.0
my precommit script runs "lint-staged", which looks like this
"lint-staged": {
"src/**/*.{js,jsx,json,css}": [
"prettier --write --single-quote --jsx-bracket-same-line",
"git add"
]
}
and my editor config looks like this
"prettier.singleQuote": true,
"prettier.jsxBracketSameLine": true,
So, they should be the same thing (assuming they are running the same version.
so the precommit hook makes it look like this
const {
user: { UserId }
} = store.getState();
which throws linting errors, and when I save it gets formatted like this
const { user: { UserId } } = store.getState();
until i commit and push the change, then it reverts back to the first example.
You get linting errors. Are you using eslint and a local prettier together somehow which are both not on the same version?
they all should be the same version, that is what is confusing me. Its set up like this.
{
"scripts": {
"precommit": "lint-staged"
},
"devDependencies": {
"eslint-config-prettier": "^2.7.0",
"eslint-config-react-tools": "^1.0.10",
"eslint-plugin-react": "^7.4.0",
"lint-staged": "^4.3.0",
"prettier": "1.14.0"
},
"lint-staged": {
"src/**/*.{js,jsx,json,css}": [
"prettier --write --single-quote --jsx-bracket-same-line",
"git add"
]
}
}
and then my eslint file looks like this
{
"parser": "babel-eslint",
"extends": ["prettier", "react-app"],
"plugins": ["prettier"],
"rules": {
"prettier/prettier": [
"error",
{
"singleQuote": true,
"jsxBracketSameLine": true
}
]
}
}
so that is the precommit hook and the eslint rules, I have in my settings for vscode
{
"editor.formatOnSave": true,
"files.autoSave": "onWindowChange",
"prettier.singleQuote": true,
"prettier.jsxBracketSameLine": true
}
and i have the latest version of vscode extension
so...lots of moving parts, but it seems like the one place where they differ is in those destructuring assignments.
my formatOnSave wants to put them on multiple lines, while my precommit hook wants to put them on a single line.
Those are the only files I have in the project that reference any prettier stuff (no .editorconfig, etc)
I'm sure its just something dumb on my side, but thanks for helping me out.
when i hover on the prettier in the bottom right, it says [email protected] so it looks like the editor is using the right version, and I assume that the lint-staged prettier should also use that version.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
I too have been waiting for a PR which was released with
1.14https://github.com/prettier/prettier/pull/4830