Created
March 22, 2021 13:18
-
-
Save tiagobnobrega/08c556b724a9cee19efd87dfc065f5dc to your computer and use it in GitHub Desktop.
Nodejs eslint config
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", | |
"airbnb-typescript/base", | |
], | |
parserOptions: { | |
ecmaVersion: 2021, // Allows for the parsing of modern ECMAScript features | |
project: './tsconfig.json', | |
}, | |
env: { | |
node: false, | |
browser: true, | |
jest: true, | |
es2021: true, | |
}, | |
parser: '@typescript-eslint/parser', | |
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", | |
// Alow default exports | |
"import/no-default-export": "off", | |
// Too restrictive: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/destructuring-assignment.md | |
"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", | |
// too restrictive, might be able to return intended/explicit undefinded | |
"unicorn/no-useless-undefined": "off" | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment