Last active
July 16, 2021 18:30
-
-
Save ChechoCZ/707708b1ddd91a1b738cbeaa62656d4d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Generate Editor Config (Install editor config dependency VSCode). | |
2. Install ESLint | |
- ```yarn add eslint -D``` | |
- ```yarn eslint --init``` | |
- *To check syntax, find problems and enforce code style* | |
- *Javascript modules (import/export)* | |
- *None of these* | |
- **Typescript?** *Yes* | |
- *Node/Browser* | |
- *Use a popular style guide* | |
- Airbnb | |
- JSON | |
- ```yarn add eslint-import-resolver-typescript -D``` | |
** In NODE ** | |
Add to .eslintrc.json file: | |
- extends: "plugin:@typescript-eslint/recommended" | |
- ``` | |
"settings": { | |
"import/resolver": { | |
"typescript": {} | |
} | |
} | |
``` | |
- rules: | |
``` | |
"import/extensions": [ | |
"error", | |
"ignorePackages", | |
{ | |
"ts": "never" | |
} | |
] | |
``` | |
- settings: (right below rules) | |
``` | |
"settings": { | |
"import/resolver": { | |
"typescript": {} | |
} | |
} | |
``` | |
** In ReactJS ** | |
Remove from package.json: | |
``` | |
"eslintConfig": { | |
"extends": [ | |
"react-app", | |
"react-app/jest" | |
] | |
}, | |
``` | |
Add to .eslintrc.json file: | |
- extends: "plugin:@typescript-eslint/recommended" | |
- plugins: "react-hooks" | |
- rules: | |
``` | |
"react-hooks/rules-of-hooks": "error", | |
"react-hooks/exhaustive-deps": "warn", | |
"react/jsx-filename-extension": [1, { "extensions": [".tsx"] }], | |
"import/prefer-default-export": "off", | |
"camelcase": "off", | |
"@typescript-eslint/ban-types": "off", | |
"import/extensions": [ | |
"error", | |
"ignorePackages", | |
{ | |
"ts": "never", | |
"tsx": "never" | |
} | |
] | |
``` | |
- settings: (right below rules) | |
``` | |
"settings": { | |
"import/resolver": { | |
"typescript": {} | |
} | |
} | |
``` | |
3. Install Prettier | |
- yarn add prettier eslint-config-prettier eslint-plugin-prettier -D | |
- Add to .eslintrc.json file: | |
- "extends": "plugin:prettier/recommended" | |
- "plugins": "prettier" | |
- "rules": "prettier/prettier": "error" | |
- Create prettier.config.js file in the root folder and add: | |
module.exports = { | |
singleQuote: true, | |
trailingComma: 'all', | |
arrowParens: 'avoid', | |
}; | |
4. Create a .eslintignore file in the root folder and add: | |
/*.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment