Ps: The current setup was done on 01-04-19
Project Dependency Versions at the time ๐
"react": "^16.7.0",
"react-dom": "^16.7.0",
"react-scripts": "2.1.3",
"typescript": "^3.2.2"
"tslint": "^5.12.0",
"tslint-config-prettier": "^1.17.0",
"tslint-plugin-prettier": "^2.0.1",
"tslint-react": "^3.6.0"
Directions:
-
Install Prettier and TypeScript TSLint Plugin extensions on your VSCode
-
Edit (per your desire) the following on your VSCode settings ๐
{
"editor.formatOnSave": false,
"[javascript]": {
"editor.formatOnSave": true
},
"[typescript]": {
"editor.formatOnSave": true
},
"[typescriptreact]": {
"editor.formatOnSave": true
},
"prettier.tslintIntegration": true,
"prettier.eslintIntegration": true,
"prettier.jsxSingleQuote": false,
"prettier.singleQuote": true,
}
-
npx create-react-app [project-name] --typescript
-
cd into [project-name]
-
Install the following dependecies to package.json ๐
yarn add --dev typescript
yarn add @types/node @types/react @types/react-dom @types/jest
yarn add --dev tslint
yarn add --dev tslint-config-prettier
yarn add --dev tslint-plugin-prettier
yarn add --dev tslint-react
- Create a
tslint.json
file with the following config ๐
{
"extends": [
"tslint:recommended",
"tslint-react",
"tslint-config-prettier"
],
"rulesDirectory": [
"tslint-plugin-prettier"
],
"rules": {
"prettier": true,
"interface-name": false
}
}
- Create a
.prettierrc
file and add your desired rules i.e ๐
{
"trailingComma": "es5",
"printWidth": 100,
"semi": false,
"singleQuote": true
}
- Quit and restart VSCode again
Note: tslint-config-prettier is shipped with a little CLI tool to help you check if your configuration contains any rules that are in conflict with Prettier. (require tslint installed
In order to execute the CLI tool, first add a script for it topackage.json
:
{
"scripts": {
"tslint-check": "tslint-config-prettier-check ./tslint.json"
}
}
Then run
yarn tslint-check or npm run tslint-check
You may also run TS lint directlly as a script
on your package.json
"scripts": {
"lint": "tslint -c tslint.json src/**/*.{ts,tsx} --fix --format verbose"
}
Then run
yarn lint or npm run lint
thank you very much