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

[bug] typescript-eslint warnings show up in svelte.config.js #3514

Closed
kelvindecosta opened this issue Jan 22, 2022 · 2 comments · Fixed by #3536
Closed

[bug] typescript-eslint warnings show up in svelte.config.js #3514

kelvindecosta opened this issue Jan 22, 2022 · 2 comments · Fixed by #3536

Comments

@kelvindecosta
Copy link

kelvindecosta commented Jan 22, 2022

Describe the bug

The skeleton project when configured with typescript and eslint run @typescript-eslint rules on the main configuration file, svelte.config.js. Although no warnings show up in the default skeleton configuration, when they do, they cannot be resolved since type annotations can only be used in TypeScript files.

Reproduction

Example change:

@@ -7,6 +7,10 @@ const config = {
        // for more information about preprocessors
        preprocess: preprocess(),
 
+       compilerOptions: {
+               cssHash: ({ hash, css }) => `svelte-${hash(css)}`
+       },
+
        kit: {
                adapter: adapter(),

Reproduction on CodeSandbox

Logs

The output of npm run lint:

/path/to/project/svelte.config.js
  11:12  warning  Missing return type on function          @typescript-eslint/explicit-module-boundary-types
  11:13  warning  Object pattern argument should be typed  @typescript-eslint/explicit-module-boundary-types

✖ 2 problems (0 errors, 2 warnings)

System Info

npx: installed 1 in 1.332s

  System:
    OS: Linux 5.10 Manjaro Linux
    CPU: (8) x64 Intel(R) Core(TM) i7-4700HQ CPU @ 2.40GHz
    Memory: 873.68 MB / 15.52 GB
    Container: Yes
    Shell: 5.8 - /usr/bin/zsh
  Binaries:
    Node: 14.18.1 - ~/.nvm/versions/node/v14.18.1/bin/node
    Yarn: 1.22.10 - ~/.nvm/versions/node/v14.18.1/bin/yarn
    npm: 6.14.15 - ~/.nvm/versions/node/v14.18.1/bin/npm
  Browsers:
    Brave Browser: 96.1.32.115
    Firefox: 95.0
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.14 
    @sveltejs/kit: next => 1.0.0-next.240 
    svelte: ^3.44.0 => 3.46.2

Severity

annoyance

Additional Information

This is a mild annoyance.
Still, I think it could use a workaround/modification to the default eslint configuration in the skeleton project.

Any help is appreciated!
Thank you for your time!

@benmccann
Copy link
Member

type annotations can only be used in TypeScript files

I don't think that's true. You can specify types via JSDocs. Look at the code of SvelteKit itself in this repo as that's how it handles typing in all files

@kelvindecosta
Copy link
Author

@benmccann Thank you for the response!

I understand it better now.
With JSDoc comments type annotations can be added to svelte.config.js even though it isn't a TypeScript file.

Although the config object is annotated with /** @type {import('@sveltejs/kit').Config} */ , the warnings still appear for some expressions within its definition.

In the example above, config.compilerOptions.cssHash is appropriately typed as a CssHashGetter but the linter still complains about a missing return type.

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

Successfully merging a pull request may close this issue.

3 participants