Skip to content

Instantly share code, notes, and snippets.

@akari0624
Last active July 12, 2019 14:52
Show Gist options
  • Save akari0624/e09968f7e1b23f188688129e1a8f33af to your computer and use it in GitHub Desktop.
Save akari0624/e09968f7e1b23f188688129e1a8f33af to your computer and use it in GitHub Desktop.
eslint for typescript
{
"env": {
"browser": true,
"es6": true
},
"parser": "@typescript-eslint/parser",
"extends": [
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended",
"plugin:prettier/recommended",
"prettier/@typescript-eslint"
],
"parserOptions": {
"ecmaVersion": 8,
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
"jsx": true
},
"sourceType": "module"
},
"plugins": ["react", "react-hooks", "@typescript-eslint"],
"rules": {
"indent": ["error", 2],
"linebreak-style": ["error", "unix"],
"quotes": ["error", "single"],
"semi": ["off", "never"],
"no-console": "off",
"react/display-name": ["off"],
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"@typescript-eslint/explicit-function-return-type": "off"
},
"globals": {
"describe": false,
"beforeEach": false,
"global": false,
"process": false,
"test": false,
"expect": false
}
}
yarn add eslint \
@typescript-eslint/eslint-plugin \
@typescript-eslint/parser \
eslint-plugin-react \
eslint-config-airbnb \
eslint-plugin-react-hooks \
eslint-plugin-prettier \
eslint-plugin-typescript \ // prettier plugin, prettier need both install in global or both in local, they need to be in same scope(global or local)
prettier \
-D
// set this in the vscode config file to make vscode eslint extension will work when we write our code
// ....and many other settings
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact"
],
@akari0624
Copy link
Author

akari0624 commented Jul 12, 2019

The future of TypeScript on ESLint
如何用 ESLint 检查 TypeScript 代码
Using ESLint and Prettier in a TypeScript Project
TypeScript | 當 TypeScript 遇上 React 的超級聯名 TSX 款

note:

this setup may not suitable for an application that has not not ejected from create-reacta-app template,
because CRA use its own eslint and has config that for their user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment