Skip to content

Getting "Unexpected token(parse-error)" with a SvelteKit Typescript project #343

Closed
@flayks

Description

@flayks

I'm trying to add eslint to my TS SvelteKit boilerplate and I discovered this plugin over eslint-plugin-svelte3 as it allows more control over rules, which is great! Although I keep running into parse errors with simple code like so:

<script lang="ts">
    export let domain: string
               ^^^^^^
    export let enabled = !import.meta.env.DEV
    import type { PageData } from './$types'
                ^
</script>
Unexpected token(parse-error) eslint[svelte/valid-compile]

Am I missing something or did I config something in a funny way?

Here is my config:

module.exports = {
    root: true,
    env: {
        browser: true,
        es2017: true,
        node: true
    },
    parserOptions: {
        sourceType: 'module',
        ecmaVersion: 2020,
    },
    parser: '@typescript-eslint/parser',
    plugins: [
        '@typescript-eslint'
    ],
    extends: [
        'eslint:recommended',
        'plugin:@typescript-eslint/recommended',
        'plugin:svelte/recommended',
    ],
    ignorePatterns: ['*.cjs', '*.d.ts'],
    overrides: [
        {
            files: ['*.svelte'],
            parser: 'svelte-eslint-parser',
            parserOptions: {
                parser: '@typescript-eslint/parser',
            },
        },
    ],
    settings: {

    },
    rules: {
        /* Javascript / Typescript
        ========================================= */
        // Use spaces over tabs
        'no-tabs': 'error',
        indent: ['error', 4],
        // Use single quote in javascript
        quotes: ['error', 'single', {
            avoidEscape: true,
            allowTemplateLiterals: true
        }],
        // Avoid semicolons
        semi: ['error', 'never'],
        // Avoid trailing spaces
        'no-trailing-spaces': ['error', { skipBlankLines: true }],
        // Add a space between curlies
        'object-curly-spacing': ['error', 'always'],
        // Require a line at end of file
        'eol-last': ['error', 'always'],
        // Allow ts exceptions
		'@typescript-eslint/ban-ts-comment': ['error', {
			'ts-ignore': false,
			'ts-nocheck': false,
			'ts-expect-error': 'allow-with-description',
		}],

        /* Svelte
        ========================================= */
        // Use double quotes
        'svelte/html-quotes': ['error', {
            prefer: 'double',
            dynamic: {
                quoted: false,
                avoidInvalidUnquotedInHTML: false,
            }
        }],
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions