Skip to content
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

🐛 BUG: Shorthand attributes passed to components are turned into regular strings when astroAllowShortHand is false. #87

Closed
yamac-kurtulus opened this issue Dec 14, 2021 · 0 comments · Fixed by #88

Comments

@yamac-kurtulus
Copy link
Contributor

Describe the Bug

Prettier changes <Component {attribute} /> to <Component attribute="attribute"> when shorthand attributes are not allowed whereas it should actually be <Component attribute={attribute}>

Steps to Reproduce

  1. npm init astro using template Vue (template does not matter probably)
  2. install prettier plugin npm i -D prettier-plugin-astro
  3. Configure prettier:
//prettierrc.json:
{
  "trailingComma": "es5",
  "tabWidth": 2,
  "semi": false,
  "singleQuote": true,
  "astroAllowShorthand": true,
  "printWidth": 120,
  "plugins": [
    "./node_modules/prettier-plugin-astro"
  ],
  "overrides": [
    {
      "files": "*.astro",
      "options": {
        "parser": "astro"
      }
    }
  ]
}
  1. Setup vscode (probably unrelated)
//settings.json
{
  "prettier.documentSelectors": ["**/*.astro"],
  "prettier.configPath": "./.prettierrc.json"
}

  1. Create an astro component, for ex. a layout:
//Layout.astro:
---
import HeadLayout from './HeadLayout.astro'
const { title } = Astro.props
const { metaDesc } = Astro.props
---
const 
<HeadLayout {title} {metaDesc} /> 
  1. Save file in vscode or run prettier. And the file becomes
//Layout.astro:
---
import HeadLayout from './HeadLayout.astro'
const { title } = Astro.props
const { metaDesc } = Astro.props
---
const 
<HeadLayout title="title" metaDesc="metaDesc" /> 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant