microsoft / vscode-eslint

VSCode extension to integrate eslint into VSCode
MIT License
1.72k stars 333 forks source link

Support autodetecting Svelte #1468

Open miauk22 opened 2 years ago

miauk22 commented 2 years ago

Whenever I try to lint Svelte file I get Unexpected token error from eslint(ParseError) in very random places, but always at first few lines of file. Linting with CLI works fine, It's also working with Atom and Webstorm.

I'm using following stuff:

"eslint-plugin-svelte3": "4.0.0",
"svelte": "3.46.4",
"typescript": "4.6.2",
"eslint": "8.15.0"

with dbaeumer.vscode-eslint extension v2.2.2.

File .eslintrc.json (without our rules):

{
    "env": {
        "browser": true,
        "es6": true
    },
    "plugins": [
        "svelte3",
        "@typescript-eslint"
    ],
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
        "ecmaVersion": 2020,
        "sourceType": "module",
        "extraFileExtensions": [".svelte"],
        "project": "./tsconfig.json"
    },
    "overrides": [
        {
            "files": ["*.svelte"],
            "processor": "svelte3/svelte3"
          }
    ],
    "extends": [
        "eslint:recommended",
        "plugin:@typescript-eslint/eslint-recommended",
        "plugin:@typescript-eslint/recommended",
        "plugin:@typescript-eslint/recommended-requiring-type-checking"
    ],
    "globals": {
        "Atomics": "readonly",
        "SharedArrayBuffer": "readonly"
    },
    "ignorePatterns": [
        "node_modules/",
        "**/*.js"
    ],
   "rules": { ..... },
   "settings": {
        "svelte3/typescript": true
    }
}

Added following to settings.json for VS Code:

"eslint.validate": [
        "javascript",
        "svelte"
    ],

In output from ESLint extension there are no errors.

dbaeumer commented 2 years ago

@miauk22 can you please provide me with a GitHub repository I can clone that demos this?

miauk22 commented 2 years ago

https://github.com/miauk22/eslint-svelte-issue

dbaeumer commented 2 years ago

Can you please add an eslint configuration. I get

Error: No ESLint configuration found in /workspaces/eslint-svelte-issue/svelte-typescript-app/src.
    at CascadingConfigArrayFactory._finalizeConfigArray (/workspaces/eslint-svelte-issue/svelte-typescript-app/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3962:19)
    at CascadingConfigArrayFactory.getConfigArrayForFile (/workspaces/eslint-svelte-issue/svelte-typescript-app/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3753:21)
    at CLIEngine.getConfigForFile (/workspaces/eslint-svelte-issue/svelte-typescript-app/node_modules/eslint/lib/cli-engine/cli-engine.js:971:14)
    at ESLint.calculateConfigForFile (/workspaces/eslint-svelte-issue/svelte-typescript-app/node_modules/eslint/lib/eslint/eslint.js:664:26)
    at /home/codespace/.vscode-remote/extensions/dbaeumer.vscode-eslint-2.2.2/server/out/eslintServer.js:1:176344
    at Ce (/home/codespace/.vscode-remote/extensions/dbaeumer.vscode-eslint-2.2.2/server/out/eslintServer.js:1:186295)
    at h.then.o.validate (/home/codespace/.vscode-remote/extensions/dbaeumer.vscode-eslint-2.2.2/server/out/eslintServer.js:1:176323)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
miauk22 commented 2 years ago

Should be fine now, for some reason it was not uploaded earlier

dbaeumer commented 2 years ago

Which extension are you using to get Svelte support. An extension is necessary otherwise the language id "svelte" is not known.

miauk22 commented 2 years ago

svelte.svelte-vscode (this one)

dbaeumer commented 2 years ago

Thanks!

miauk22 commented 2 years ago

@dbaeumer , do you still need more info about this one?

dbaeumer commented 2 years ago

@miauk22

The auto detection of Svelte is not working. However, you can enforce it via the eslint.validate setting. Something like

    "eslint.validate": [
        "javascript",
        "svelte"
    ]
dbaeumer commented 2 years ago
capture
tobiasbueschel commented 2 years ago

Thanks @dbaeumer your comment helped me fix the issue I had!

My eslint output on the CLI produced very different output to what VS Code was showing and setting it explicitly solved it.

miauk22 commented 2 years ago

@dbaeumer I had this, as written at the beginning of this story. For some reason it is still not working for me for one specific project, it looks like it works for different ones though. In the original one I had "Unexpected token" every time and for every Svelte file. What helped (kind of) was removing VS Code, clearing AppData/Roaming/Code directory, installing again, now everything works fine.