ESLint Configuration Not Sticking
Answered
Russian Blue posted this in #help-forum
Russian BlueOP
Upon running
After running it again, it is the same loop over and over. It seems that the configuration isn't saving. How do I resolve this issue?
npm run lint
I receive the following message and confirm strict:npm run lint
> volvox.apollo.web@1.3 lint
> next lint
? How would you like to configure ESLint? https://nextjs.org/docs/basic-features/eslint
â–² ESLint has successfully been configured. Run next lint again to view warnings and errors.
After running it again, it is the same loop over and over. It seems that the configuration isn't saving. How do I resolve this issue?
53 Replies
@Russian Blue Upon running `npm run lint` I receive the following message and confirm strict:
npm run lint
> volvox.apollo.web@1.3 lint
> next lint
? How would you like to configure ESLint? https://nextjs.org/docs/basic-features/eslint
â–² ESLint has successfully been configured. Run next lint again to view warnings and errors.
After running it again, it is the same loop over and over. It seems that the configuration isn't saving. How do I resolve this issue?
After running it do you see an eslint configuration file in your project?
@joulev After running it do you see an eslint configuration file in your project?
Russian BlueOP
Negative, nothing is created. Also tried with sudo.
Uhh
@Russian Blue Negative, nothing is created. Also tried with sudo.
Create an .eslintrc.json file with this content
Answer
{
"extends": "next/core-web-vitals"
}
@joulev Create an .eslintrc.json file with this content
Russian BlueOP
In root correct?
Yes in root
Russian BlueOP
done
And install eslint and eslint-plugin-next if you haven’t already
Russian BlueOP
Lemme try lint now
@joulev And install eslint and eslint-plugin-next if you haven’t already
Russian BlueOP
Adding them now
eslint and eslint-config-next
@joulev eslint and eslint-**config**-next
Russian BlueOP
Done, is that it?
Yes now try running lint again
Russian BlueOP
Worked! Threw some errors on my project 🙂
@joulev Are there any other config settings?
@Russian Blue <@484037068239142956> Are there any other config settings?
You can customise the eslint config however you want, but the file above is the most basic form shipped with create-next-app
For me it’s not strict enough though
@joulev For me it’s not strict enough though
Russian BlueOP
Could you share yours? I'd prefer strict too
I use vercel/style-guide for a stricter setup in my projects
@joulev I use vercel/style-guide for a stricter setup in my projects
Russian BlueOP
Could you send that to me?
@Russian Blue Could you share yours? I'd prefer strict too
Mine is https://github.com/joulev/website/blob/main/.eslintrc.js but it requires some extra dependencies, most notably https://github.com/vercel/style-guide
vercel/style-guide is incredibly strict, you most likely have to disable a few rules
But would rather disable rules from a strict preset than enable rules from a relaxed preset yeah
Russian BlueOP
Going to use yours! Mind if I add you if I have questions on this since this topic is fixed? @joulev
Sure
I’m no eslint expert either I only know to use other people’s preset but I’ll help if I can
@Russian Blue Going to use yours! Mind if I add you if I have questions on this since this topic is fixed? <@484037068239142956>
Sorry but I can’t take friend requests because my DM is reserved for my friend circles now. Feel free to ping me here or make a new forum post
@joulev Sorry but I can’t take friend requests because my DM is reserved for my friend circles now. Feel free to ping me here or make a new forum post
Russian BlueOP
Oh sure thing! I got your version working
Do you have any other suggestions for ESLint or editorconfig or even prettier? @joulev
@Russian Blue Do you have any other suggestions for ESLint or editorconfig or even prettier? <@484037068239142956>
My repo linked above has all the personal choice I have for those kinds of things already
@joulev My repo linked above has all the personal choice I have for those kinds of things already
Russian BlueOP
Sweet thank you!
@joulev Could you explain this regex from your prettier config?
importOrder: ["^#/.*$", "^~/.*$", "^\\.\\.?/.*$"],
Russian BlueOP
Also, should these be dev dependencies?
"devDependencies": {
"@vercel/style-guide": "^5.0.1",
"eslint-config-prettier": "^9.0.0"
}
@Russian Blue Also, should these be dev dependencies?
json
"devDependencies": {
"@vercel/style-guide": "^5.0.1",
"eslint-config-prettier": "^9.0.0"
}
In a nextjs app then dependencies and devdependencies don’t have any differences, so I just put everything to dependencies
If you make a library though then yes move all prettier and eslint related stuff to devDeps
@joulev In a nextjs app then dependencies and devdependencies don’t have any differences, so I just put everything to dependencies
Russian BlueOP
Perfect, this has been a massive help thank you so much!
Np you’re welcome
Russian BlueOP
@joulev I had to do some updates because of this error
How come you don't get this error?
.eslintrc.js:
Configuration for rule "@typescript-eslint/no-misused-promises" is invalid:
Severity should be one of the following: 0 = off, 1 = warn, 2 = error (you passed 'true')."
How come you don't get this error?
Russian BlueOP
Newer version of the rules package maybe?
@Russian Blue <@484037068239142956> I had to do some updates because of this error
.eslintrc.js:
Configuration for rule "@typescript-eslint/no-misused-promises" is invalid:
Severity should be one of the following: 0 = off, 1 = warn, 2 = error (you passed 'true')."
How come you don't get this error?
Maybe you have
"@typescript-eslint/no-misused-promises": true
somewhere@joulev Maybe you have `"@typescript-eslint/no-misused-promises": true` somewhere
Russian BlueOP
Ah yes that’s exactly what I have. Thank you
@Russian Blue Ah yes that’s exactly what I have. Thank you
if you want to enable that rule use "error" or "warn", to disable use "off"
@joulev if you want to enable that rule use "error" or "warn", to disable use "off"
Russian BlueOP
Yeah going to turn it off as it required me to change the entire config
And doesn’t seem like a great rule
@Russian Blue And doesn’t seem like a great rule
it's actually a great rule, i just already know my way with promises so don't want it to bite me unnecessarily
@joulev it's actually a great rule, i just already know my way with promises so don't want it to bite me unnecessarily
Russian BlueOP
Oh then I’ll leave it on since I’m new to them
I already modified the configuration to fix it to 0,1,2 as well
Russian BlueOP
@joulev This is what I ended up with for my ESLint config:
Any suggestions for other rules that a new front end developer (coming from backend) should use?
const { resolve } = require("node:path")
const project = resolve(__dirname, "tsconfig.json")
module.exports = {
root: true,
extends: [
require.resolve("@vercel/style-guide/eslint/browser"),
require.resolve("@vercel/style-guide/eslint/react"),
require.resolve("@vercel/style-guide/eslint/next"),
require.resolve("@vercel/style-guide/eslint/node"),
require.resolve("@vercel/style-guide/eslint/typescript")
],
parserOptions: { project },
settings: { "import/resolver": { typescript: { project } } },
rules: {
"@typescript-eslint/explicit-function-return-type": 1,
"@typescript-eslint/no-confusing-void-expression": "off",
"@typescript-eslint/no-misused-promises": 2,
"import/no-extraneous-dependencies": 2,
"import/order": 2,
"import/no-default-export": "off",
"no-console": 1,
"react/jsx-sort-props": 2,
"react/no-array-index-key": "off"
}
}
Any suggestions for other rules that a new front end developer (coming from backend) should use?
@Russian Blue <@484037068239142956> This is what I ended up with for my ESLint config:
js
const { resolve } = require("node:path")
const project = resolve(__dirname, "tsconfig.json")
module.exports = {
root: true,
extends: [
require.resolve("@vercel/style-guide/eslint/browser"),
require.resolve("@vercel/style-guide/eslint/react"),
require.resolve("@vercel/style-guide/eslint/next"),
require.resolve("@vercel/style-guide/eslint/node"),
require.resolve("@vercel/style-guide/eslint/typescript")
],
parserOptions: { project },
settings: { "import/resolver": { typescript: { project } } },
rules: {
"@typescript-eslint/explicit-function-return-type": 1,
"@typescript-eslint/no-confusing-void-expression": "off",
"@typescript-eslint/no-misused-promises": 2,
"import/no-extraneous-dependencies": 2,
"import/order": 2,
"import/no-default-export": "off",
"no-console": 1,
"react/jsx-sort-props": 2,
"react/no-array-index-key": "off"
}
}
Any suggestions for other rules that a new front end developer (coming from backend) should use?
I don’t know any rule suggestions, I only use vercel style guide and disable rules that the style guide uses that I find to be too strict