Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESLint: Unexpected token 1 #135

Open
kazzkiq opened this issue Oct 3, 2021 · 3 comments
Open

ESLint: Unexpected token 1 #135

kazzkiq opened this issue Oct 3, 2021 · 3 comments

Comments

@kazzkiq
Copy link

kazzkiq commented Oct 3, 2021

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
Copy link
Member

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
Copy link

JounQin commented Oct 3, 2021

@Conduitry Did you read through #16 (comment)?

@kazzkiq
Copy link
Author

kazzkiq commented Oct 4, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants