zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
39.6k stars 2.07k forks source link

eslint-disable comments added on save in svelte files #13633

Open unlocomqx opened 1 week ago

unlocomqx commented 1 week ago

Check for existing issues

Describe the bug / provide steps to reproduce it

Simple Repro

I have a few custom eslint rules

{
    rules: {
        'no-console': ['error', { allow: ['warn', 'error'] }],
        '@typescript-eslint/no-unused-vars': 'warn',
        'no-restricted-syntax': [
            'warn',
            {
                message: "$inspect is not allowed",
                selector:
                    "CallExpression[callee.name='$inspect']"
            }
        ]
    },
},

When I have code inside a svelte file that triggers an eslint warning or error, I get an eslint-disable comment that is inserted automatically

CleanShot 2024-06-28 at 10 52 48@2x

It also happens for other svelte rules, not just custom rules

CleanShot 2024-06-28 at 10 55 22@2x

Environment

Zed: v0.141.2 (Zed) OS: macOS 14.5.0 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 ~/Library/Logs/Zed/Zed.log file to this issue.

Zed.log


Frank-vdm commented 1 week ago

i get this with a react/ typescript project, its super annoying, and only started happening since the last update for me

unlocomqx commented 1 week ago

i get this with a react/ typescript project, its super annoying, and only started happening since the last update for me

Same.

Here's a repro

xiduzo commented 1 week ago

This happened to me a while back for react projects, and it drives me nuts. I am back to vscode until this issue is solved

unlocomqx commented 1 week ago

This is tagged as relating to svelte. if any react guys can provide a repro, it would also be helpful to verify the issue.

eulke commented 1 week ago

Same with react / js project and prettier rules comments

mrnugget commented 3 days ago

Same.

Here's a repro

Thanks for that repo!

I cannot reproduce it though.

Here's what I did:

  1. Clone your repo
  2. Run pnpm install in it
  3. Open the repo with Zed
  4. Edit the +page.svelte file to remove the comments
  5. Hit save.

Code is formatted.

I then edited the ESLint config to add another rule:

diff --git a/eslint.config.js b/eslint.config.js
index b5b7d9b..310e012 100644
--- a/eslint.config.js
+++ b/eslint.config.js
@@ -32,6 +32,7 @@ export default [
        },
        {
                rules: {
+                       'prefer-const': 'error',
                        'no-console': ['error', { allow: ['warn', 'error'] }],
                        '@typescript-eslint/no-unused-vars': 'warn',
                        'no-restricted-syntax': [

When I then hit save, ESLint fixes the let to const but inserts no comments.

https://github.com/zed-industries/zed/assets/1185253/2062fc74-0fe0-4bc5-982d-24fd02aeae19

Here's the Zed settings.json that I was using:

{
  "languages": {
    "Svelte": {
      "code_actions_on_format": {
        "source.fixAll.eslint": true
      }
    },
    "TSX": {
      "code_actions_on_format": {
        "source.fixAll.eslint": true
      }
    },
    "Vue.js": {
      "code_actions_on_format": {
        "source.fixAll.eslint": true
      }
    },
    "JavaScript": {
      "code_actions_on_format": {
        "source.fixAll.eslint": true
      }
    }
  },
  "vim_mode": true
}
Laurin-Notemann commented 3 days ago

A similiar issue has occured with my tsx file, but it seemed like it occures more often when I had my settings page open as a tab. And for me it happened when I had two many line (for example two lines and I hit save, and then it adds a comment to ignore an eslint rule)

unlocomqx commented 3 days ago

@mrnugget I tried with these settings and the issue went away

"languages": {
    "Svelte": {
      "code_actions_on_format": {
        "source.fixAll.eslint": true
      }
    }
  }

Can you try without that setting to see if you can reproduce it?

Thanks

hmttrp commented 3 days ago

I am experiencing the same issue in a Typescript project. I noticed that this is only happening when I have source.organizeImports enabled. So removing the following snippet from my configuration makes the issue dissapear.

  "code_actions_on_format": {
    "source.organizeImports": true
  },

The issue is also reproducible in the example repo when the setting is enabled.

eulke commented 3 days ago

Here is my Log

2024-07-04T17:36:36-03:00 [INFO] Language server with id 22 sent unhandled notification eslint/status:
{
  "uri": "file:///Users/eulke/development/mpfc-balance-frontend/app/components/OpenFinance/Totalizator/TotalAmount/index.js",
  "state": 1,
  "validationTime": 69
}
2024-07-04T17:36:36-03:00 [INFO] Language server with id 22 sent unhandled notification eslint/openDoc:
{
  "url": "https://github.com/prettier/eslint-plugin-prettier#options"
}
eulke commented 3 days ago

Is true that if i comment source.organizeImports that issue dissapear

  "languages": {
    "JavaScript": {
      "formatter": {
        "code_actions": {
          "source.fixAll.eslint": true
          // "source.organizeImports": true
        }
      }
    }
  },

But i want to be able of have both things

unlocomqx commented 2 days ago

Is true that if i comment source.organizeImports that issue dissapear

  "languages": {
    "JavaScript": {
      "formatter": {
        "code_actions": {
          "source.fixAll.eslint": true
          // "source.organizeImports": true
        }
      }
    }
  },

But i want to be able of have both things

Yes, same here, if I comment this, it doesn't happen

"code_actions_on_format": {
  "organize_imports": true
},
mrnugget commented 2 days ago

So it's a language server that adds these comments then? Which language server is that? Is there a way to disable that behaviour? Or is it about the order of the code actions?

unlocomqx commented 2 days ago

So it's a language server that adds these comments then? Which language server is that? Is there a way to disable that behaviour? Or is it about the order of the code actions?

Must be the eslint ls