zed icon indicating copy to clipboard operation
zed copied to clipboard

Weird behavior with prettier using plugins

Open affanshahid opened this issue 1 year ago • 3 comments

Check for existing issues

  • [X] Completed

Describe the bug / provide steps to reproduce it

I am using prettier with the plugin prettier-plugin-organize-imports. Using it with Zed is causing the format command to remove all generics from a tsx file.

Before:

import * as Headless from '@headlessui/react';
import { Link as RemixLink, type LinkProps } from '@remix-run/react';
import React, { forwardRef } from 'react';

export const Link = forwardRef(function Link(
  props: { href: string | LinkProps['to'] } & Omit<LinkProps, 'to'>,
  ref: React.ForwardedRef<HTMLAnchorElement>,
) {
  return (
    <Headless.DataInteractive>
      <RemixLink {...props} to={props.href} ref={ref} />
    </Headless.DataInteractive>
  );
});

After formatting with Zed:

import * as Headless from '@headlessui/react';
import { Link as RemixLink, type LinkProps } from '@remix-run/react';
import React, { forwardRef } from 'react';

export const Link = forwardRef(function Link(
  props: { href: string | LinkProps['to'] } & Omit,
  ref: React.ForwardedRef,
) {
  return (
    <Headless.DataInteractive>
      <RemixLink {...props} to={props.href} ref={ref} />
    </Headless.DataInteractive>
  );
});

This seems to work fine with the prettier cli. Output of npx prettier frontend/app/components/ui/link.tsx:

import * as Headless from '@headlessui/react';
import { Link as RemixLink, type LinkProps } from '@remix-run/react';
import React, { forwardRef } from 'react';

export const Link = forwardRef(function Link(
  props: { href: string | LinkProps['to'] } & Omit<LinkProps, 'to'>,
  ref: React.ForwardedRef<HTMLAnchorElement>,
) {
  return (
    <Headless.DataInteractive>
      <RemixLink {...props} to={props.href} ref={ref} />
    </Headless.DataInteractive>
  );
});

Removing the plugin from my prettier config fixes the behaviour in Zed. Prettier config:

{
    "singleQuote": true,
    "trailingComma": "all",
    "plugins": [
      "prettier-plugin-organize-imports"
    ]
}

Note my prettier config is inside ./package.json, whereas the file is inside ./frontend/app/components/, the ./frontend folder also has a package.json.

Environment

Zed: v0.145.0 (Zed Preview) OS: macOS 14.4.1 Memory: 16 GiB Architecture: aarch64

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your Zed.log file to this issue.

Zed.log

[Zed.log](https://github.com/user-attachments/files/16300350/Zed.log)

affanshahid avatar Jul 19 '24 01:07 affanshahid

I have the same strange behavior when using this import sort plugin.

"plugins": ["@trivago/prettier-plugin-sort-imports"],

baboons avatar Aug 21 '24 12:08 baboons

I'm having this behavior now also, not using the sort plugin though, or any prettier plugins.

garand avatar Oct 05 '24 01:10 garand

+1 here, facing with prettier-plugin-organize-imports

jjram19 avatar Oct 09 '24 23:10 jjram19

I'm having a similar issue.

Before formatting with Zed: function MailIcon(props: React.ComponentPropsWithoutRef<'svg'>) {

After formatting with Zed: function MailIcon(props: React.ComponentPropsWithoutRef) {

Any fixes to this issue? I've been searching the docs for hours trying to fix this.

austin-karren avatar Dec 24 '24 00:12 austin-karren

Hi there! 👋 We're working to clean up our issue tracker by closing older issues that might not be relevant anymore. If you are able to reproduce this issue in the latest version of Zed, please let us know by commenting on this issue, and we will keep it open. If you can't reproduce it, feel free to close the issue yourself. Otherwise, we'll close it in 7 days. Thanks for your help!

github-actions[bot] avatar Jun 11 '25 07:06 github-actions[bot]