yarn create next-app
pages/api
touch tsconfig.jsonyarn devyarn add --dev typescript @types/react @types/nodeyarn dev
Mudar "strict": false para "strict": true
- Criar pasta
srcna raiz do projeto - Mover pasta
pagespara dentro da pastasrc
Alterar nome do src/index.js para src/index.tsx
Obs.: usar tsx para arquivos com HTML e ts para arquivos sem HTML
- Criar arquivo
.editorconfigna raiz do projeto - Atualizar arquivo com o código abaixo:
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
npx eslint --initcom as configurações abaixo:
How would you like to use ESLint? · problems
✔ What type of modules does your project use? · esm
✔ Which framework does your project use? · react
✔ Does your project use TypeScript? · Yes
✔ Where does your code run? · browser
✔ What format do you want your config file to be in? · JSON
✔ Would you like to install them now with npm? · No
yarn add --dev eslint-plugin-react@latest @typescript-eslint/eslint-plugin@latest @typescript-eslint/parser@latest eslint@latest
yarn add eslint-plugin-react-hooks --dev- Adicionar
"react-hooks"dentro de.eslintrc.json>"plugins" - Adicionar o código abaixo dentro de
.eslintrc.json>"rules"
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn"
Adicionar "react/prop-types": "off" dentro de .eslintrc.json > "rules"
Adicionar "react/react-in-jsx-scope": "off" dentro de .eslintrc.json > "rules"
Adicionar "@typescript-eslint/explicit-module-boundary-types": "off" dentro de .eslintrc.json > "rules"
Adicionar o código abaixo em .eslintrc:
"settings": {
"react": {
"version": "detect"
}
},
Adicionar no package.json dentro de "scripts" o código "lint": "eslint src"
yarn add eslint-config-prettier --dev
- Criar o arquivo
.prettierrc - Adicionar o código abaixo:
{
"trailingComma": "none",
"semi": false,
"singleQuote": true
}
yarn add prettier eslint-config-prettier eslint-plugin-prettier --dev
Adicionar o código "plugin:prettier/recommended" dentro do arquivo .eslintrc.json > "extends"
- Criar a pasta
.vscode - Criar o arquivo
settings.jsondentro da pasta.vscode - Adicionar o código abaixo dentro do
settings.json:
{
"window.zoomLevel": 1,
"editor.fontSize": 12,
"terminal.integrated.fontSize": 12,
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
}
yarn add --dev lint-staged husky
No package.json alterar "lint": "eslint src" para "lint": "eslint src --max-warnings=0"
- Adicionar o código abaixo dentro do
package.json:
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
- Adicionar o código abaixo dentro do
package.json:
"lint-staged": {
"src/**/*": ["yarn lint --fix"]
},
yarn add --dev jest @babel/preset-typescript @types/jest
Adicionar "jest": true e "node": true no arquivo .eslintrc.json dentro de "env"
- Criar o arquivo
jest.config.js - Adicionar o código abaixo:
module.exports = {
testEnvironment: 'jsdom',
testPathIgnorePatterns: ['/node_modules/', '/.next/'],
collectCoverage: true,
collectCoverageFrom: ['src/**/*.ts(x)'],
setupFilesAfterEnv: ['<rootDir>/.jest/setup.ts']
}
- Criar o arquivo
.babelrc - Adicionar o código abaixo:
{
"presets": ["next/babel", "@babel/preset-typescript"]
}
- Criar pasta
.jest - Criar arquivo
setup.ts
Adicionar "test": "jest" no arquivo package.json > "scripts"
-
Instalar o testing-library
-
yarn add @testing-library/react @testing-library/jest-dom --dev -
Importar testing-library dentro do arquivo
./jest/setup.ts:import '@testing-library/jest-dom' -
Adicionar watch para o test
Adicionar "test:watch": "jest --watch" no arquivo package.json > "scripts"
- Adicionar test ao hook
Alterar "yarn lint --fix" para "yarn lint --fix", "yarn test --findRelatedTests --bail" em "lint-staged"