sveltejs / eslint-plugin-svelte

ESLint plugin for Svelte using AST
https://sveltejs.github.io/eslint-plugin-svelte/
MIT License
279 stars 30 forks source link

ESLint plugin configuration not working on a Turborepo SvelteKit Project "Parsing error: '>' " error #631

Closed MarArMar closed 7 months ago

MarArMar commented 7 months ago

I tried to apply the eslint-plugin-svelte to my Sveltekit & Turborepo project

I got different errors, but on .svelte files I get :

<script lang="ts">
Parsing error: '>' expected.eslint

Here is my complete repo: https://github.com/MarArMar/TurboMin

This is my eslint config : packages\eslint-config\base.js

module.exports = {
  parserOptions: {
    sourceType: "module",
    ecmaVersion: 2020,
    // Is overriden in each project
    project: "./tsconfig.json",
    extraFileExtensions: [".svelte"], // This is a required setting in `@typescript-eslint/parser` v4.24.0.
  },

  parser: "@typescript-eslint/parser",
  extends: [
    "eslint:recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:import/recommended",
    "plugin:import/errors",
    "plugin:import/warnings",
    "plugin:import/typescript",
    "plugin:svelte/base",
    "plugin:svelte/recommended",
    "turbo",
  ],
  plugins: ["@typescript-eslint"],
  ignorePatterns: [
    "*.cjs",
    ".eslintrc.cjs",
    ".eslintrc.js",
    "svelte.config.js",
    "*.min.js",
    "node_modules/",
    "dist/",
    "build/",
    "coverage/",
    ".svelte-kit/",
    ".vercel/",
    ".netlify/",
  ],
  overrides: [
    {
      // From https://github.com/sveltejs/eslint-plugin-svelte
      files: ["*.svelte"],
      parser: "svelte-eslint-parser",
      parserOptions: {
        parser: "@typescript-eslint/parser",
      },
      rules: {
        "@typescript-eslint/no-inferrable-types": "off",
      },
    },
  ],
  env: {
    browser: true,
    node: true,
    es2020: true,
    commonjs: true,
  },
  rules: {
    "@typescript-eslint/no-inferrable-types": "off",
  },
};

Overriden by apps\SvelteKitExample.eslintrc.cjs

module.exports = {
  root: true,
  extends: ['@repo/eslint-config/base.js'],
  parser: '@typescript-eslint/parser',
  parserOptions: {
    project: './tsconfig.json',
  },
}

This is my tsconfigs : packages\tsconfig\sveltekit.json

{
  "compilerOptions": {
    "importsNotUsedAsValues": "error",
    "isolatedModules": true,
    "preserveValueImports": true,
    "lib": ["esnext", "DOM", "DOM.Iterable"],
    "moduleResolution": "node",
    "module": "esnext",
    "target": "esnext",
    "ignoreDeprecations": "5.0",

    "allowJs": true,
    "checkJs": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "sourceMap": true,
    "strict": true
  },

  "exclude": [
    "./[!ambient.d.ts]**",
    "../src/service-worker.js",
    "../src/service-worker.ts",
    "../src/service-worker.d.ts",

    "../../**/functions/*",
    "../../**/static/*",

    "../../**/node_modules/**",
    "../../**/.svelte-kit/**",
    "../../**/dist/**",
    "../../**/build/**",
    "../../**/.svelte/**",
    "../../**/.vercel_build_output/**",
    "../../**/.vercel/**",
    "../../**/coverage/**",
    "../../**/_/**",
    "../../**/static/**.min.js",
    "../../**/vite.config.js.timestamp-*",
    "../../**/vite.config.ts.timestamp-*"
  ]
}

Overriden by apps\SvelteKitExample\tsconfig.json

{
  "extends": "tsconfig/sveltekit.json",
  "compilerOptions": {
    // PS : Have to duplicate in vite.config.ts for routing !
    "paths": {
      "$src/*": ["./src/*"],
      "$lib": ["./src/lib"],
      "$lib/*": ["./src/lib/*"]
    }
  },
}

What is wrong with my setup ?

MarArMar commented 7 months ago

Ok solved it

OrahKokos commented 7 months ago

@MarArMar How did you fix it? I'm using Svelte without svelte kit with ts, followed all the recommendations, but lang="ts" throws the same error always

MarArMar commented 7 months ago

@OrahKokos I believe I created a new Sveltekit + TS project with eslint, and the eslint config worked, so I tried to change step by step my own eslint config to make it similar to the working one and it ended up working at some point