55
loading...
This website collects cookies to deliver better user experience
yarn create next-app
or npx create-next-app
and follow the instructionsyarn add -D typescript @types/react @types/nodes
npm install --save-dev typescript @types/react @types/nodes
yarn dev
or npm run dev
index.js
and _app.js
to index.tsx
and _app.tsx
yarn add -D eslint
or npm install --save-dev eslint
npx eslint --init
and choose your configuration, here we will choose to go with Google style guide. Here is a screenshot of the config we choose :yarn add -D prettier eslint-config-prettier
or npm install --save-dev prettier eslint-config-prettier
{
"env": {
"browser": true,
"es2021": true
},
"extends": ["plugin:react/recommended", "google", "prettier"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": ["react", "@typescript-eslint"],
"rules": {
"require-jsdoc": "off",
"react/react-in-jsx-scope": "off"
}
}
{
"endOfLine": "auto",
"printWidth": 100,
"tabWidth": 2,
"trailingComma": "es5"
}
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local
# vercel
.vercel
{
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
"source.fixAll.format": true
}
}
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
yarn lint
or npm run lint
eslint should check your code and indicates some errors or warnings that you need to fix."scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint --fix"
},
yarn add -D husky lint-staged
or npm install --save-dev husky lint-staged
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"type-check": "tsc --project tsconfig.json --pretty --noEmit",
"postinstall": "husky install"
},
module.exports = {
// Run type-check on changes to TypeScript files
'**/*.ts?(x)': () => 'yarn type-check',
// Run ESLint on changes to JavaScript/TypeScript files
'**/*.(ts|js)?(x)': (filenames) => `yarn lint . ${filenames.join(' ')}`,
}
yarn husky add .husky/pre-commit "yarn lint-staged"
ornpm run husky install .husky/pre-commit "npm run lint-staged"