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

Add compability with 'import' eslint plugin #453

Closed
stalkerg opened this issue Apr 28, 2023 · 7 comments
Closed

Add compability with 'import' eslint plugin #453

stalkerg opened this issue Apr 28, 2023 · 7 comments
Labels
needs repro Need a repository that can reproduce the problem

Comments

@stalkerg
Copy link

Description

Currently, If I add import plugin and this rule:

 rules: {
    'import/no-unresolved': ['error', { commonjs: true, caseSensitive: true }],
  }

it will produce errors like:

tests/eslint-svelte-repro/src/routes/Header.svelte
  2:23  error  Unable to resolve path to module '$app/stores'                  import/no-unresolved
  3:19  error  Unable to resolve path to module '$lib/images/svelte-logo.svg'  import/no-unresolved
  4:21  error  Unable to resolve path to module '$lib/images/github.svg'       import/no-unresolved

These rules are part of airbnb rules set https://www.npmjs.com/package/eslint-config-airbnb and many others.
To solve it, I tried to use eslint-import-resolver-custom-alias and eslint-import-resolver-jsconfig but it's seems like break eslint-plugin-svelte (but it's works for eslint-plugin-svelte3):

npx eslint src/lib/Image.svelte 

Error while parsing /home/stalkerg/projects/mjv-art.org/spa/src/lib/i18n.js
Line 15, column 0: Unexpected token
`parseForESLint` from parser `/home/stalkerg/projects/mjv-art.org/spa/node_modules/svelte-eslint-parser/lib/index.js` is invalid and will just be ignored

Error while parsing /home/stalkerg/projects/mjv-art.org/spa/src/lib/helpers.js
Line 3, column 14: Expected }
`parseForESLint` from parser `/home/stalkerg/projects/mjv-art.org/spa/node_modules/svelte-eslint-parser/lib/index.js` is invalid and will just be ignored

/home/stalkerg/projects/mjv-art.org/spa/src/lib/Image.svelte
  48:1  error  This line has a length of 101. Maximum allowed is 100  max-len

seems like if such libs became resolvable, it's break eslint-plugin-svelte.

As I understand, we have two options:

  1. Fix compatibility with resolvers for import plugin.
  2. Implement our own resolver inside eslint-plugin-svelte.

Regards,

@stalkerg stalkerg added the enhancement New feature or request label Apr 28, 2023
@stalkerg
Copy link
Author

stalkerg commented Apr 28, 2023

Okey, I found what only this one rule:

'import/named': 'error',

make such parsing errors. Because this module was disabled in typescript set maybe it's related to TS again https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/named.md

UPDATE:
One more rule break svelte plugin:

'import/no-cycle': ['error', { maxDepth: '∞' }],

@stalkerg stalkerg changed the title Add compability with 'import' easlint plugin Add compability with 'import' eslint plugin Apr 28, 2023
@ota-meshi ota-meshi added the needs repro Need a repository that can reproduce the problem label Apr 28, 2023
@ota-meshi
Copy link
Member

Could you please provide a repository to reproduce so someone can look into the cause?

@ota-meshi ota-meshi removed the enhancement New feature or request label Apr 29, 2023
@stalkerg
Copy link
Author

Okey, I have one. I will do it tomorrow.

@stalkerg
Copy link
Author

Please https://github.com/stalkerg/eslint-svelte-import-issue if you do after npm install just npx eslint src/ you will see:

Error while parsing /home/stalkerg/projects/tests/eslint-svelte-import-issue/src/lib/test.js
Line 4, column 0: Unexpected token
`parseForESLint` from parser `/home/stalkerg/projects/tests/eslint-svelte-import-issue/node_modules/svelte-eslint-parser/lib/index.js` is invalid and will just be ignored

Error while parsing /home/stalkerg/projects/tests/eslint-svelte-import-issue/src/routes/sverdle/reduced-motion.js
Line 7, column 1: Unexpected token
`parseForESLint` from parser `/home/stalkerg/projects/tests/eslint-svelte-import-issue/node_modules/svelte-eslint-parser/lib/index.js` is invalid and will just be ignored

This repo it's just a default project after create-svelte with a few tweaks.

@ota-meshi
Copy link
Member

You need to add the following to your configuration.

  settings: {
    // ...
    'import/parsers': {
      'svelte-eslint-parser': ['.svelte'],
      'espree': ['.js'],
    }

https://github.com/import-js/eslint-plugin-import#importparsers

@stalkerg
Copy link
Author

Thanks! It's worked! Should we add this to eslint-plugin-svelte docs?

@ota-meshi
Copy link
Member

Yeah, could you please open a PR to add it to the FAQ section?
https://sveltejs.github.io/eslint-plugin-svelte/user-guide/#faq

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs repro Need a repository that can reproduce the problem
Projects
None yet
Development

No branches or pull requests

2 participants