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: adding duplicate import statment #425

Closed
xkeshav opened this issue Aug 12, 2024 · 2 comments
Closed

🐛 BUG: adding duplicate import statment #425

xkeshav opened this issue Aug 12, 2024 · 2 comments
Labels
needs response Need a response from the original author

Comments

@xkeshav
Copy link

xkeshav commented Aug 12, 2024

Describe the Bug

done all required settings for Astro project along with eslint and prettier plugin but when , save the file ; the last import statment being added below and the duplicate import statement error comes and when remove and save the file ; it again add the import statement

below are frelevent ile content

project.code-worspace

{
"prettier.documentSelectors": [
      "**/*.astro"
    ],
    "[astro]": {
      "editor.defaultFormatter": "esbenp.prettier-vscode",
      "editor.codeActionsOnSave": {
        "source.fixAll": "always",
        "source.organizeImports": "always"
      }
    }
}

package.json

  "devDependencies": {
    "prettier": "3.1.0",
    "prettier-plugin-astro": "^0.14.1"
}

.prettierrc.mjs ( Not Working )

/** @type {import("prettier").Config} */
export default {
  plugins: ['prettier-plugin-astro'],
  overrides: [
    {
      files: '*.astro',
      options: {
        parser: 'astro',
      },
    },
  ],
};

.prettierrc.js

/** @type {import("@types/prettier").Options} */
module.exports = {
  printWidth: 120,
  semi: true,
  singleQuote: false,
  tabWidth: 2,
  useTabs: false,
  bracketSpacing: true,
  arrowParens: "always",
  endOfLine: "lf",
  trailingComma: "none",
  htmlWhitespaceSensitivity: "css",
  plugins: ["prettier-plugin-astro"],
  overrides: [
    {
      files: "*.astro",
      options: {
        parser: "astro"
      }
    }
  ]
};

src/pages/about.astro

---
import Header from "@/components/Header";
import Layout from "@/layouts/Layout";
---

<Layout title="About Us">
  <Header title="About Us">
    <div>popover content</div>
  </Header>
  <main>
    <div>
      <h1>Hello There</h1>
    </div>
  </main>
</Layout>

when we hit save ; one more duplicate import statement getting added as below

---
import Header from "@/components/Header";
import Layout from "@/layouts/Layout";
import Layout from "@/layouts/Layout";
---

NOTE: functionality is working fine ( tsconfig has path alias and we are using that )

Steps to Reproduce

  1. npm init astro using template blog
  2. install eslint and prettier and prettier-plugin-astro
  3. added the .prettierrc.js file ( .mjs not working )
  4. Format on save setting added in workspace ( VS Code )
  5. import Layout file ( .astro ) in one of .astro file
  6. Hit Save ( Ctrl + S ) then import statment get duplicated
@Princesseuh
Copy link
Member

Make sure you're using the latest version of the VS Code extension. The Prettier plugin is not at fault here.

@xkeshav
Copy link
Author

xkeshav commented Aug 14, 2024

Issue is connected with this below issue

withastro/language-tools#933

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs response Need a response from the original author
Projects
None yet
Development

No branches or pull requests

2 participants