yarn add --dev prettier eslint-plugin-prettier eslint-config-prettier eslint-config-google lint-staged husky
yarn husky install && husky add .husky/pre-commit "yarn lint-fix"
- Prettier is run as an ESLint Plugin, rather than as a stand-alone tool
- Prettier rules are the last to be applied, which overrides some Google rules (some desirably, some not); therefore we have a small
.prettierrc
:
{
"singleQuote": true
}
{
"extends": ["next/core-web-vitals", "plugin:import/recommended", "plugin:import/typescript", "google", "prettier"],
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error",
"no-console": "warn",
"max-len": ["warn", {
"code": 120,
"tabWidth": 2
}],
"require-jsdoc": "off"
}
}
- Reminder:
lint-fix
is called on the gitpre-commit
hook via Husky + Lint-Staged
{
"scripts": {
"prepare": "husky install",
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"lint-fix": "next lint --fix"
}
}
- Ensure you have
serve
installed, ieyarn add --dev serve
{
"scripts": {
"prepare": "husky install",
"dev": "next dev",
"build": "next build",
"preexport": "npm run build",
"export": "next export",
"prestart": "npm run export",
"start": "serve out",
"lint": "next lint",
"lint-fix": "next lint --fix"
}
}
NOTE: For a Static Only NextJS Site, you need to DISABLE Image Optimization in next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
images: {
unoptimized: true, // CANNOT use while exporting site as "Static" only
}
}
module.exports = nextConfig
- Install the
ESLint
extension- Do NOT Install the
Prettier
extension. It's not needed because we are using Prettier as an ESLint Plugin, rather than as a stand-alone tool.
- Do NOT Install the
- Configure VSCode as you wish via
User Settings JSON (settings.json)
- Enable/Disable (suggestions)
"eslint.enable": false
(default: true) - Enable/Disable (fix on save)
"editor.codeActionsOnSave": { "source.fixAll": true }
(default: false)
- Enable/Disable (suggestions)