Language-tools: Unused export property warning is on the wrong line when using the TypeScript pre-processor.

Created on 27 Aug 2020  ·  18Comments  ·  Source: sveltejs/language-tools

Describe the bug
export let statements of an unused property cause a warning. The warning is displayed on the line above the actual property for me.

To Reproduce

Set the script language to typescript (lang="ts" or type="text/typescript").
Declare some export property, do not use it anywhere.

Expected behavior

The warning is on the property not being used.

Screenshots

image

If the property is in the first line of the script:

image

System (please complete the following information):

  • OS: Windows 10, 64bit
  • IDE: VSCode
  • Plugin/Package: Svelte for VSCode
bug

All 18 comments

Try update your @tsconfig/svelte to lastest

I am not using that.
Added it temporarily, did nothing.

Oh I thought you were using the official template. The package is a base config for svelte. You can update the extends of your tsconfig.json to match this.
https://github.com/sveltejs/template/blob/8194bf8f6452f8117195bf304ac99b15d329fbb3/scripts/setupTypeScript.js#L87

Duplicate of #333

@jasonlyu123 As i said, i added the base config temporarily but nothing changed. I still get the errors on the wrong line.

Then can you try run tsc to compile a ts file in your workspace and see if the output file has sourcemap?

The problem is with sourcemap. We use the svelte compiler to get svelte diagnostics. if you have a svelte.config.js and specify your preprocessor in it we would use that to preprocess, other than that we'll use the official svelte-preprocess. And if the preprocessor doesn't return a sourcemap the warning would be in a wrong position.

Also, we don't monitor change in the tsconfig.json so make sure you restart the language server after any changes.

It does not always generate source maps. If i call tsc on a single file it apparently does not load the tsconfig; if i use tsc -p . or tsc --build tsconfig.json it will output the source map as expected.

Can I take a look at your svelte.config.js if you have it, also which preprocessor do you use?

I use the default processor, which should be svelte-preprocess in auto mode. I made a minimal example repository which has the errors on the input component.

I tried creating a svelte.config.js, explicitly setting the pre-processor in auto mode, did not matter. Explicitly using only the typescript one with a path to the tsconfig.json did not do anything either.

Ummm... this is unexpected, it would only work when I also set sourcemap to true in tsconfig.json

Then the extends does not quite work. Well, i do not mind setting that explicitly for now.
Thanks

Yeah, I have a quick look at the source file of the svelte-preprocess. It looks like it doesn't parse the extends.
Thanks for the issue!

I opened this issue over at svelte-preprocess, because according to the docs, in auto-preprocessing mode, source maps should be generated. Update: The docs were wrong, so you need to set that to true yourself.

@brunnerh if you remove "sourceMaps": true and the base config reference from your tsconfig.json and instead do sveltePreprocess({sourceMap: true}) in your svelte.config.js, does it show the warnings at the correct line then?

@brunnerh if you remove "sourceMaps": true and the base config reference from your tsconfig.json and instead do sveltePreprocess({sourceMap: true}) in your svelte.config.js, does it show the warnings at the correct line then?

No, still off.

So it only works if you add "sourceMaps": true to the tsconfig.json?

Yes

Closing as these are problems related to svelte-preprocess. The "source map is not applied when I tell preprocess through its sourceMap-option"-problem is fixed in the latest version. The "extends-feature of tsconfig.json not supported" is tracked in https://github.com/sveltejs/svelte-preprocess/issues/300 .

Was this page helpful?
0 / 5 - 0 ratings