A Record Of Adding Eslint To My Nextjs Website
Written by Eddie ZhangatDecember 28, 2024
eslint
nextjs
prettier
what happened?
tldr, nextjs prompts you to extend "next" in your own .eslintrc.json
bash# this popped up ⚠ The Next.js plugin was not detected in your ESLint configuration. See https://nextjs.org/docs/basic-features/eslint#migrating-existing-config
json"@typescript-eslint/eslint-plugin": "^8.18.2", "@typescript-eslint/parser": "^8.18.2",// to let eslint understand typescript "eslint": "^9.17.0", "eslint-config-next": "^15.1.3",// to avoid conflict with nextjs eslint config "eslint-config-prettier": "^9.1.0", //to avoid conflict with prettier config "prettier": "^3.4.2",
is breaking changes ths mainstream in javascript? am I right, Nextjs official?
bashpnpx @eslint/migrate-config .eslintrc.json # these msgs will pop up Migrating .eslintrc.json Wrote new config to ./eslint.config.mjs You will need to install the following packages to use the new config: - globals - @eslint/js - @eslint/eslintrc You can install them using the following command: npm install globals @eslint/js @eslint/eslintrc -D
bashpnpx @eslint/migrate-config .eslintrc.json && eslint --no-cache
setup prettier
json"prettier-plugin-organize-imports": "^4.1.0",// this will conflict with eslint-import-sort, I recommend to use prettier "prettier-plugin-tailwindcss": "^0.6.9",// format tw classnames
json"plugins": [ "prettier-plugin-tailwindcss", "prettier-plugin-organize-imports" ],
prettier write .
to format all the files in your projectwhy this command can run globally?
json"lint": "pnpx @eslint/migrate-config .eslintrc.json && eslint --no-cache", "format": "pnpm run lint && prettier --write .",
I am not getting used to the latest eslint config syntax, you can make your own's
tsconst nextConfig: NextConfig = { eslint: { ignoreDuringBuilds: true, }, //... };
format
every time before build
so we don't need it anymore