Skip to content

Linting for svetle file with lang="ts" not matching typescript file linting #206

@AutomateAaron

Description

@AutomateAaron

I have the following two files:

+page.svelte:

<script lang="ts">
  var test = 'test';
</script>

and

+page.ts:

var test = 'test';

However, when I run eslint I get different results for the files:

[...]\+page.svelte
  2:6  warning  'test' is assigned a value but never used  @typescript-eslint/no-unused-vars

[...]\+page.ts
  1:1  error    Unexpected var, use let or const instead   no-var
  1:5  warning  'test' is assigned a value but never used  @typescript-eslint/no-unused-vars

Notably the ts(no-var) is being applied to the typescript file, however it isn't being applied to the svelte file. I'd like to have this handled consistently across svelte and typescript files?

For context, here are my config files (let me know if you need to see any other files):

.eslintrc.cjs
module.exports = {
	root: true,
	parser: '@typescript-eslint/parser',
	extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
	plugins: ['svelte3', '@typescript-eslint'],
	ignorePatterns: ['*.cjs'],
	overrides: [
		{
			files: ['*.svelte'],
			processor: 'svelte3/svelte3'
		}
	],
	settings: {
		'svelte3/typescript': () => require('typescript')
	},
	parserOptions: {
		sourceType: 'module',
		ecmaVersion: 2020
	},
	env: {
		browser: true,
		es2017: true,
		node: true
	}
};
tsconfig.json
{
	"extends": "./.svelte-kit/tsconfig.json",
	"compilerOptions": {
		"allowJs": true,
		"checkJs": true,
		"esModuleInterop": true,
		"forceConsistentCasingInFileNames": true,
		"resolveJsonModule": true,
		"skipLibCheck": true,
		"sourceMap": true,
		"strict": true,
		"outDir": "dist",
		"types": ["unplugin-icons/types/svelte"]
	}
	// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
	//
	// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
	// from the referenced tsconfig.json - TypeScript does not merge them in
}

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