sveltejs / eslint-plugin-svelte3

An ESLint plugin for Svelte v3 components.
MIT License
373 stars 43 forks source link

ESLint: Unexpected token 1 #135

Open kazzkiq opened 3 years ago

kazzkiq commented 3 years ago

I have a Vite project using their svelte-ts template.

I've manually added Prettier and ESLint, but for some reason keep getting this error when I load svelte3/svelte3 processor and open any .svelte file:

[Error - 10:50:27 PM] ESLint stack trace:
[Error - 10:50:27 PM] ParseError: Unexpected token
  1 | let count = 0;
  2 |
> 3 | {;}
    | ^
Occurred while linting /path/to/file.svelte

The component I've opened has this simple code:

<script>
  let count = 0;
</script>

This is my .eslintrc.cjs file content:

module.exports = {
  root: true,
  parser: '@typescript-eslint/parser',
  extends: [
    'eslint:recommended',
    'plugin:@typescript-eslint/recommended',
    'prettier',
    'plugin:prettier/recommended'
  ],
  plugins: ['svelte3', '@typescript-eslint'],
  ignorePatterns: ['*.cjs'],
  overrides: [{ files: ['*.svelte'], processor: 'svelte3/svelte3' }],
  settings: {
    'svelte3/typescript': () => require('typescript')
  },
  parserOptions: {
    sourceType: 'module',
    ecmaVersion: 2019
  },
  env: {
    browser: true,
    es2017: true,
    node: true
  },
  rules: {
    '@typescript-eslint/explicit-module-boundary-types': 'off',
    '@typescript-eslint/no-explicit-any': 'off'
  }
};

As soon as I remove the overrides line with the svelte3/svelte3 processor, the error goes away but no linting for Svelte files.

Has anyone experienced this issue?

Conduitry commented 3 years ago

It's listed on https://github.com/sveltejs/eslint-plugin-svelte3/blob/master/OTHER_PLUGINS.md#eslint-plugin-prettier that this plugin is known not to play nicely with the eslint-plugin-prettier, which I'm assuming you're pulling in via plugin:prettier/recommended. It's hard to tell what's going on without a clonable repo.

The code the error is pointing at

let count = 0;

{;}

is also valid JS, so I can't tell who is failing to parse that or why.

But in any case, if you're using eslint-plugin-prettier, this should be closed, as this is a known issue, and there's another open issue for it somewhere I believe.

JounQin commented 3 years ago

@Conduitry Did you read through https://github.com/sveltejs/eslint-plugin-svelte3/issues/16#issuecomment-847622683?

kazzkiq commented 3 years ago

It's hard to tell what's going on without a clonable repo.

Done: https://github.com/kazzkiq/svelte-eslint-prettier-error

I've reduced the repo to the minimal needed to run it and reproduce the error.

Not sure if this issue will be kept open or if its even eslint-plugin-svelte3 scope, but nonetheless, its important to have a simple repo to reproduce it for future adventurers who might want to give it a look.