Skip to content

Instantly share code, notes, and snippets.

@Tuan-T-Nguyen
Last active July 10, 2021 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tuan-T-Nguyen/d2d27767daa14f1cd65f47c2bd14696b to your computer and use it in GitHub Desktop.
Save Tuan-T-Nguyen/d2d27767daa14f1cd65f47c2bd14696b to your computer and use it in GitHub Desktop.
eslint prettier in reactjs
  1. npx eslint --init

Choose your options

  1. Install prettier
  • Install VSCode prettier extension
  • touch .prettierrc
  • Basic .prettierrc setting
{
  "semi": true,
  "trailingComma": "none",
  "singleQuote": true,
  "printWidth": 80
}
  • setting.json
// Default (format when you paste)
"editor.formatOnPaste": true,
// Default (format when you save)
"editor.formatOnSave": true,
  1. Config Prettier to work with ESLint
  • Install packages:
npm install --save-dev prettier eslint-config-prettier eslint-plugin-prettier
  • Config in .eslintrc
 "plugins": [
    "prettier"
  ],
"extends": [
    "prettier"
  ],
"rules": {
    "prettier/prettier": 2, // Means error
    "react/react-in-jsx-scope": 0,
    "react/jsx-filename-extension": [
			1,
			{ "extensions": [".js", ".jsx", ".ts", ".tsx"] }
		],
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment