-
-
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
create-svelte TS ESLint config generally complaining about .cjs config files #706
Comments
Good observation, did not think about that. All these config files need to be Do you know how option 2 could look like? What would be needed to add such an override? To me that option feels superior to 1, but if there is no easy way I can live with option 1 just as well. |
So I've just whacked open a PR for option 1 for a quick fix! Then I'll share my own config that sort of implements option 2 (which could definitely be improved upon lol). |
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
extends: ['eslint:recommended', 'prettier'],
plugins: ['svelte3', '@typescript-eslint'],
ignorePatterns: ['.eslintrc.js'],
overrides: [
{ files: ['*.svelte'], processor: 'svelte3/svelte3' },
// For *.cjs, set env to node to remove the require() complaints.
{ files: ['*.cjs'], env: { node: true } },
// Enable the TS rules here instead, so the *.cjs override doesn't inherit them.
{ files: ['!*.cjs'], extends: 'plugin:@typescript-eslint/recommended' }
],
settings: {
'svelte3/typescript': require('typescript')
},
parserOptions: {
sourceType: 'module',
ecmaVersion: 2018
}
}; So this is what I've got in my project - it provisionally works okay, but it's not a particularly pretty config because I don't believe you can 'unextend' any extensions provided beforehand in your Wondering if there's a neater way, will have a think 🙃 |
Thanks for the fix! I'll go ahead and close this as this isn't a problem anymore in the newer templates |
Describe the bug
Further to #701, when it comes to the
.eslintrc.cjs
file generated by create-svelte for TypeScript projects, ESLint is moaning within the.cjs
files in the top directory, because.eslintrc.cjs
isn't really configured to deal with those files. It's particularly moaning aboutrequire()
calls in these files.By default, the only two
.cjs
files in the top directory are the ESLint and Svelte configs, but given it seems to be the convention that any other config files have a.cjs
extension (e.g:tailwind.config.cjs
andpostcss.config.cjs
added bysvelte-add tailwindcss
), you get complaints for these config files too.I'd guess there were a few ways round this:
ignorePatterns
in.eslintrc.cjs
to glob all.cjs
files ['*.cjs'
] so that ESLint by default ignores these config files entirely.overrides
to.eslintrc.cjs
such that any.cjs
files are parsed correctly.Thanks 🙃
Logs
The sorts of ESLint errors one would expect for the TS parser looking at JS, and also for the ESLint config not having
env
set to"node"
.In
svelte.config.js
:ESLint: 'require' is not defined.(no-undef)
ESLint: Require statement not part of import statement.(@typescript-eslint/no-var-requires)
Similar ESLint complaints in
tailwind.config.cjs
andpostcss.config.cjs
whensvelte-add
is used.To Reproduce
npm init svelte@next
), enabling TypeScript and ESLint for the project.Expected behavior
Nein red squiggles for the ESLint rules in the files above!
Information about your SvelteKit Installation:
Severity
It's not severe - you can just edit the config defaults, but might want to give it some thought 😄
The text was updated successfully, but these errors were encountered: