Created
March 15, 2021 16:43
-
-
Save tiagobnobrega/368c1902c7e35b84d1d7239a1cbeee16 to your computer and use it in GitHub Desktop.
React Typescript eslintrc configuration
This file contains hidden or 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
module.exports = { | |
plugins: [ | |
"@typescript-eslint", | |
"eslint-comments", | |
"jest", | |
"promise", | |
"unicorn", | |
], | |
extends: [ | |
"plugin:@typescript-eslint/recommended", | |
"plugin:eslint-comments/recommended", | |
"plugin:jest/recommended", | |
"plugin:promise/recommended", | |
"plugin:unicorn/recommended", | |
"prettier", | |
"prettier/@typescript-eslint", | |
"airbnb-typescript", | |
], | |
parserOptions: { | |
ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features | |
project: './tsconfig.json', | |
}, | |
env: { | |
node: false, | |
browser: true, | |
jest: true, | |
}, | |
rules: { | |
"max-len": ["error", { "code": 150 }], | |
"unicorn/filename-case": [ | |
"error", | |
{ | |
"cases": { | |
"camelCase": true, // use for other files | |
"pascalCase": true // use for components | |
} | |
} | |
], | |
'unicorn/no-null': 'warn',// some third party code might rely on nulls | |
// Too restrictive, writing ugly code to defend against a very unlikely scenario: https://eslint.org/docs/rules/no-prototype-builtins | |
"no-prototype-builtins": "off", | |
// https://basarat.gitbooks.io/typescript/docs/tips/defaultIsBad.html | |
"import/prefer-default-export": "warn", | |
"import/no-default-export": "off", | |
// Too restrictive: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/destructuring-assignment.md | |
"react/destructuring-assignment": "off", | |
// No jsx extension: https://github.com/facebook/create-react-app/issues/87#issuecomment-234627904 | |
"react/jsx-filename-extension": "off", | |
// allow props spreading | |
"react/jsx-props-no-spreading": "off", | |
//disable prop types validation | |
"react/prop-types": "off", | |
// note you must disable the base rule as it can report incorrect errors | |
"no-use-before-define": "off", | |
// allow the use of for...of loops | |
'no-restricted-syntax': [ | |
'error', | |
{ | |
selector: 'ForInStatement', | |
message: 'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.', | |
}, | |
// { | |
// selector: 'ForOfStatement', | |
// message: 'iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations.', | |
// }, | |
{ | |
selector: 'LabeledStatement', | |
message: 'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.', | |
}, | |
{ | |
selector: 'WithStatement', | |
message: '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.', | |
}, | |
], | |
// Use function hoisting to improve code readability | |
"@typescript-eslint/no-use-before-define": [ | |
"error", | |
{ functions: false, classes: true, variables: true }, | |
], | |
// Makes no sense to allow type inferrence for expression parameters, but require typing the response | |
"@typescript-eslint/explicit-function-return-type": [ | |
"error", | |
{ allowExpressions: true, allowTypedFunctionExpressions: true }, | |
], | |
// Common abbreviations are known and readable | |
"unicorn/prevent-abbreviations": "off", | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment