-
Notifications
You must be signed in to change notification settings - Fork 21
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
Does the plugin have Astro compatibility? #96
Comments
Yes, I use it in my own Astro project. |
@IanVS I mentioned it because I recently returned to a project using the latest version of Astro, and it stopped working. The imports are no longer being sorted, and since it's not listed in the compatibility table, I thought that might be the issue. |
@RodrigoTomeES can you share your |
@IanVS sure, here you have. thanks! {
"semi": true,
"singleQuote": true,
"endOfLine": "lf",
"tabWidth": 2,
"useTabs": false,
"printWidth": 80,
"overrides": [
{
"files": ["**/*.css"],
"options": {
"singleQuote": false
}
}
],
"plugins": [
"prettier-stylelint",
"prettier-plugin-astro",
"@ianvs/prettier-plugin-sort-imports",
"prettier-plugin-tailwindcss"
],
"importOrder": [
"<THIRD_PARTY_MODULES>",
"",
"^@/atoms/(.*)$",
"^@/molecules/(.*)$",
"^@/organisms/(.*)$",
"^@/templates/(.*)$",
"^@/pages/(.*)$",
"^@/layouts/(.*)$",
"",
"^@/(.*)$",
"^[./]",
"",
"<TYPES>",
"<TYPES>^[./]"
],
"importOrderMergeDuplicateImports": true,
"pluginSearchDirs": false
} |
It could be because you're using I upgraded my project to Astro 2.5.1, and was still able to sort correctly. I can look into it a bit more if you're willing to put together a small reproduction and share it. |
@IanVS mmm I have all my dependencies updated, look: $ yarn outdated
➤ YN0000: ┌ Checking for outdated dependencies
➤ YN0000: └ Completed in 2s 917ms
➤ YN0000: ✨ All your dependencies are up to date!
➤ YN0000: Done in 2s 918ms This is the project: https://github.com/RodrigoTomeES/awa-db |
It looks like the latest version of |
Restores compatibility with the latest version of `prettier-plugin-astro`. Fixes #96. To confirm, I made this change in the `node_modules` of the project in the above issue, and confirmed that sorting began working correctly again.
Support has been restored in 4.0.0-beta.0. I've opened a PR on your repo to update it. RodrigoTomeES/awa-db#1. Thanks for the report! |
@IanVS wow, thanks! I will test it this afternoon and aprove it 🚀 |
Is there an issue currently with Astro and the plugin? I am experiencing a
package.json {
"dependencies": {
"astro": "^4.10.2",
},
"devDependencies": {
"@ianvs/prettier-plugin-sort-imports": "^4.3.0",
"@typescript-eslint/parser": "7.14.1",
"eslint": "^9.6.0",
"eslint-plugin-astro": "1.2.2",
"prettier": "^3.3.2",
"prettier-plugin-astro": "^0.14.0",
"prettier-plugin-packagejson": "^2.5.0",
"prettier-plugin-tailwindcss": "^0.6.5"
},
} prettier.config.js /** @type {import("prettier").Config} */
export default {
printWidth: 100,
tabWidth: 2,
semi: true,
singleQuote: true,
useTabs: false,
trailingComma: 'es5',
plugins: [
'prettier-plugin-astro',
'prettier-plugin-packagejson',
'@ianvs/prettier-plugin-sort-imports',
'prettier-plugin-tailwindcss',
],
importOrder: [
'<TYPES>',
'',
'<TYPES>^[.]',
'',
'<BUILT_IN_MODULES>',
'',
'<THIRD_PARTY_MODULES>',
'',
'^@app/(.*)$',
'',
'^[./]',
],
overrides: [
{
files: ['.*', '*.md', '*.toml', '*.yml', '*.yaml'],
options: {
useTabs: false,
},
},
{
files: ['**/*.astro'],
options: {
parser: 'astro',
},
},
],
}; If I remove |
@bobalazek would you be willing to put together a minimal reproduction that I can look into? Does it fail on the command line, in vscode, or both? |
Hey @IanVS - sure, here it is: And yes, happens on both CLI and VSCode |
Thanks for the reproduction, @bobalazek, that was very helpful. I've got a PR up to address your issue. |
Addresses #96 (comment) In Astro, it's possible to [return a Response](https://docs.astro.build/en/guides/server-side-rendering/#return-a-response-object) from inside of a component script, without wrapping it in a function. This doesn't look like valid JavaScript, so the babel parser choked on it. This change checks to see if the file was parsed with the astro plugin, and if so, enables the `allowReturnOutsideFunction` parser option. This is admittedly a bit of a band-aid. I think the more correct approach is to parse the code into AST using the configured parser, rather than always using our version of babel. This is what some other prettier plugins do. Some, like tailwindcss, goes so far as to load a list of compatible other prettier plugins to enable cross-compatibility. But, that's a much bigger change that will potentially require a breaking change version bump, so I didn't tackle it here. The other thing I did do here, is update the README a bit. I added `Astro` to our supported frameworks as experimental (there may be other parser options we need to set), and also included support for Svelte, which we've always supported, as far as I know, but don't really test for (it would be good to make some tests sometime).
Hi,
Does the plugin have Astro compatibility?
Thanks!
The text was updated successfully, but these errors were encountered: