-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
ESLint misses broken imports, incorrectly reports $lib imports as broken or reports nothing at all #1560
Comments
Point 3 is "works as designed". Your assumption is correct, and if you want to change that, format the files first or switch the order of invocation. |
Is there any fix for this? All of my files are underlined in red with ESLint, and I'd rather not disable the entire rule checking unresolved imports. Would be awesome. Thanks 😄 |
I added a bit of stuff to the setup to resolve the issue like this:
{
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
+ 'plugin:import/recommended',
'prettier'
],
plugins: [
...
+ 'import'
],
settings: {
+ 'import/resolver': {
+ typescript: {}
+ },
...
},
parserOptions: {
+ project: ['./tsconfig.json', './tsconfig.lint.json'],
+ tsconfigRootDir: './',
...
}
}
{
"extends": "./tsconfig.json",
"include": ["./playwright.config.ts", "./svelte.config.js", "./tests/**/*.ts"]
}
"compilerOptions": {
...
+ "paths": {
+ "$app": ["./.svelte-kit/runtime/app"],
+ "$app/*": ["./.svelte-kit/runtime/app/*"],
+ "$lib": ["./src/lib"],
+ "$lib/*": ["./src/lib/*"]
+ }
}
} These changes fix the issue for me. I think those deserve to be added to svelte-kit templates. |
Does somebody have a solution? |
Okay, I solve it for ESLint by "settings": {
"import/resolver": {
"eslint-import-resolver-custom-alias": {
"alias": {
"$lib":"./src/lib",
"$app":"./.svelte-kit/runtime/app",
"@sveltejs":"./.svelte-kit/dev"
},
"extensions": [".js"]
},
}
}, I think we should have this in the default template. |
@ota-meshi seems like
Basically, it's happened if I import such JS from .svelte |
It seems like it will be good to write a new |
Okey, seems like 'eslint-config-airbnb-base' for some reason breaks the default resolver. |
Because new "rules": {
"import/named": "off",
"import/no-cycle": "off"
},
"settings": {
"import/resolver": {
"eslint-import-resolver-custom-alias": {
"alias": {
"$lib": "src/lib",
"$app": "node_modules/@sveltejs/kit/src/runtime/app",
"@sveltejs/kit": "node_modules/@sveltejs/kit/src/exports/index.js"
},
"extensions": [
".js"
]
}
}
} it's of course it's addition to the default config from svelte-create and aribnb preset. @dummdidumm can we add it in svelte-create? Also, I created a feature request here sveltejs/eslint-plugin-svelte#453 |
Are these rules ( |
@dummdidumm As I can see, no, but it's not fair because the typescript setup does such a test by TS tools. |
Okey, I should say thanks @ota-meshi he find a better setup: "import/parsers": {
"svelte-eslint-parser": [".svelte"],
"espree": [".js"]
},
"settings": {
"import/resolver": {
"eslint-import-resolver-custom-alias": {
"alias": {
"$lib": "src/lib",
"$app": "node_modules/@sveltejs/kit/src/runtime/app",
"@sveltejs/kit": "node_modules/@sveltejs/kit/src/exports/index.js"
},
"extensions": [
".js"
]
}
}
} basically, we need an extra parser if we want to use |
Closing this because I can't seem to reproduce the issue with the latest SvelteKit. $lib aliases are correctly resolved by eslint without the custom alias resolver plugin. |
Describe the bug
I had the problem that my ESLint configuration throws errors on
$lib/...
imports so I created a new SvelteKit project to find out how that should be handled. However there I have the opposite problem that ESLint import checking is not working at all, as it doesn't even warn me when an import does not exist.Logs and To Reproduce
There is no output from
eslint
even though 'thisdoesnot/exist.js' is not there and fails in thenpm run dev
step:Expected behavior
$lib
.npm run lint
.Information about your SvelteKit Installation:
Diagnostics
npx envinfo --system --npmPackages svelte,@sveltejs/kit,vite --binaries --browsers
Your browser: Firefox 89
Your adapter (e.g. Node, static, Vercel, Begin, etc...): The default one from npm init svelte@next, maybe static?
Severity
It is not blocking but annoying.
Additional context
I think there are three issues relating to ESLint:
npm run lint
does not output them. I assume that prettier exits with an error code and stops the second part of the&&
from being executed.The text was updated successfully, but these errors were encountered: