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
joulev
After running it do you see an eslint configuration file in your project?
Russian BlueOP
Negative, nothing is created. Also tried with sudo.
joulev
Uhh
joulev
Create an .eslintrc.json file with this content
Answer
joulev
{
"extends": "next/core-web-vitals"
}
Russian BlueOP
In root correct?
joulev
Yes in root
Russian BlueOP
done
joulev
And install eslint and eslint-plugin-next if you haven’t already
Russian BlueOP
Lemme try lint now
joulev
Wait no
Russian BlueOP
Adding them now
joulev
eslint and eslint-config-next
Russian BlueOP
Done, is that it?
joulev
Yes now try running lint again
Russian BlueOP
Worked! Threw some errors on my project 🙂
@joulev Are there any other config settings?
joulev
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
Russian BlueOP
Could you share yours? I'd prefer strict too
joulev
I use vercel/style-guide for a stricter setup in my projects
Russian BlueOP
Could you send that to me?
joulev
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
joulev
Sure
I’m no eslint expert either I only know to use other people’s preset but I’ll help if I can
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
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: ["^#/.*$", "^~/.*$", "^\\.\\.?/.*$"],
joulev
Russian BlueOP
Also, should these be dev dependencies?
"devDependencies": {
"@vercel/style-guide": "^5.0.1",
"eslint-config-prettier": "^9.0.0"
}
joulev
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
Russian BlueOP
Perfect, this has been a massive help thank you so much!
joulev
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?
joulev
Maybe you have
"@typescript-eslint/no-misused-promises": true
somewhereRussian BlueOP
Ah yes that’s exactly what I have. Thank you
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
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?
joulev
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