Closed virketrang closed 10 months ago
Just to clarify. I've also tried using the setup showed in the documentation, however it gives the following error message:
{ "ignored": false, "inferredParser": null } ["WARN" - 18.18.01] Parser not inferred, trying VS Code language. ["ERROR" - 18.18.01] Failed to resolve a parser, skipping file. If you registered a custom file extension, be sure to configure the parser.
I have found a working solution:
.prettierrc.js:
/** @type {import("prettier").Config} */ module.exports = { plugins: ['prettier-plugin-astro'], singleQuote: true, printWidth: 120, tabWidth: 4, arrowParens: 'always', bracketSpacing: true, quoteProps: 'consistent', bracketSameLine: false, jsxSingleQuote: false, semi: false, trailingComma: 'none', overrides: [ { files: '*.astro', options: { parser: 'astro' } } ] }
"editor.formatOnSave": true, "prettier.configPath": "./.prettierrc.js", "editor.defaultFormatter": "esbenp.prettier-vscode", "prettier.documentSelectors": ["**/*.astro"], "[astro]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }
I'm still in a pnpm workspace btw.
I have the prettier-plugin-astro installed at the root of the workspace using pnpm i -D prettier-plugin-astro -w
Hope it saves someone from spending a couple of hours on the issues as I have :)
I'm going to close the issue for now.
Just to clarify. I've also tried using the setup showed in the documentation, however it gives the following error message:
{ "ignored": false, "inferredParser": null } ["WARN" - 18.18.01] Parser not inferred, trying VS Code language. ["ERROR" - 18.18.01] Failed to resolve a parser, skipping file. If you registered a custom file extension, be sure to configure the parser.
Currently have this issue with Bun. I suppose this an issue related to the package manager because I set everything exactly as expected...
Describe the Bug
I have been trying for a couple of hours to get prettier to format my .astro files on save. I have tried multiple online solutions in vain.
I have the following setup in my .vscode/settings.json file:
{ "prettier.useEditorConfig": false, "prettier.configPath": ".prettierrc", "editor.formatOnSave": true, "editor.defaultFormatter": "esbenp.prettier-vscode", "prettier.documentSelectors": ["**/*.astro"], "[astro]": { "editor.defaultFormatter": "astro-build.astro-vscode", "editor.formatOnSave": true } }
I've also tried having the editor.defaultFormatter under [astro] as "esbenp.prettier-vscode", but to no avail.
I have the following .prettierrc:
{ "singleQuote": true, "printWidth": 120, "tabWidth": 4, "arrowParens": "always", "bracketSpacing": true, "quoteProps": "consistent", "bracketSameLine": false, "jsxSingleQuote": false, "semi": false, "trailingComma": "none", "astroAllowShorthand": true, "overrides": [ { "files": "*.astro", "options": { "parser": "astro" } } ], "pluginSearchDirs": ["."], "plugins": ["prettier-plugin-astro"] }
I've tried having my prettier config in the settings.json file inside .vscode and inside my package.json. I've also tried using a prettier.config.cjs.
I have installed prettier and the prettier-plugin-astro package as a devDependency. I have the astro VSCode extention installed.
I'm in a pnpm monorepo. I suspect it has something to do with pnpm.
I'll try to single out the problem.
Cheers to anyone, whos willing to help :)
Steps to Reproduce