Install ESLint and prettier-related dependencies on current project
npm install -D eslint eslint-config-prettier eslint-plugin-prettier
for Yarn, use
yarn add --devas an alternative
run the ESLint wizard
./node_modules/.bin/eslint --init
Wizard guidelines:
- Pick
To check syntax, find problems, and enforce code style - Use
JavaScript modulesfor Typescript project, ORCommonJSfor Javascript project - Use
None of Thesefor NodeJS project, ORReactfor React project - For Typescript project, please pick
Yes - Pick
Browserfor React project, otherwiseNode - Pick
Use a popular style guide, and chooseStandard - Pick
JavaScriptas the config file format - You will be prompted to install several eslint dependencies, please answer with
YesorY
Install prettier in your project and pin its version
npm install prettier -D --save-exact
{
"tabWidth": 2,
"useTabs": false,
"printWidth": 100,
"singleQuote": true,
"semi": true
}- Add
prettieras plugins - Append
plugin:prettier/recommendedon extends
// example
{
plugins: ['prettier'],
extends: ['standard', 'plugin:prettier/recommended'],
}Please install vscode prettier plugin and configure your default formatter.
- Open
Settings - Type
Default formatterin search bar - Pick
esbenp.prettier-vscodeas default formatter and save your setting