- install
npm i -D prettier
- create .prettierrc file and paste this:
{
"semi": false,
"trailingComma": "es5",
"singleQuote": true,
"printWidth": 80,
"endOfLine": "lf",
"tabWidth": 2
}
- add in package.json this command:
"prettier": "prettier --config .prettierrc \"src/**/*.ts\" --write"
{
...
"script": {
...
"prettier": "prettier --config .prettierrc \"src/**/*.ts\" --write",
...
}
...
}
- install
npm i -D eslint
- configure
npm init @eslint/config
- select:
- To check syntax, find problems, and enforce code style
- JavaScript modules (import/export)
- React (is use react), None of these (is use node.js)
- Yes (use typescript)
- Browser (if use a widget) or Node (if use a integration)
- Use a popular style guide
- Standard: https://github.com/standard/standard
- File format in: JSON
- select:
- add in package.json this command:
"lint": "eslint src --ext .js,.jsx,.ts,.tsx --ignore-pattern node_modules/"
{
...
"script": {
...
"lint": "eslint src --ext .js,.jsx,.ts,.tsx --ignore-pattern node_modules/",
...
}
...
}
{
...
"rules": {
"no-console": "warn",
TODO
}
}
- install
npm i -D eslint-config-prettier eslint-plugin-prettier
- in .eslintrc add with command:
{
...
"extends": [
...
"prettier"
],
...
"plugins": [
...
"prettier"
],
...
"rules": {
...
"prettier/prettier": 2
}
...
}