Skip to content

Instantly share code, notes, and snippets.

@RodrigoNovais
Last active May 18, 2023 03:46
Show Gist options
  • Save RodrigoNovais/f6d762ee1e163d103338684fc526f205 to your computer and use it in GitHub Desktop.
Save RodrigoNovais/f6d762ee1e163d103338684fc526f205 to your computer and use it in GitHub Desktop.
Configuração de ESLint para NodeJS
{
"env": {
"node": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"import",
"unicorn",
"@typescript-eslint"
],
"rules": {
"array-bracket-newline": ["error", { "multiline": true }],
"array-bracket-spacing": ["error", "never"],
"array-element-newline": ["error", "consistent"],
"array-callback-return": ["error", {
"allowImplicit": true,
"checkForEach": true
}],
"camelcase": ["off"],
"arrow-spacing": ["error", { "before": true, "after": true }],
"block-spacing": ["error"],
"comma-spacing": ["error", { "before": false, "after": true }],
"func-call-spacing": ["error", "never"],
"space-before-blocks": ["error"],
"keyword-spacing": ["error", { "before": true, "after": true }],
"key-spacing": ["error", {
"beforeColon": false,
"afterColon": true,
"align": "value"
}],
"default-case": ["warn"],
"default-case-last": ["error"],
"default-param-last": ["error"],
"logical-assignment-operators": ["error", "always", {
"enforceForIfStatements": true
}],
"no-await-in-loop": ["error"],
"no-caller": ["error"],
"no-constant-binary-expression": ["error"],
"no-constructor-return": ["error"],
"no-div-regex": ["error"],
"import/no-duplicates": ["error"],
"no-else-return": ["error", { "allowElseIf": false }],
"no-empty": ["error", { "allowEmptyCatch": true }],
"no-eval": ["error", { "allowIndirect": true }],
"no-extra-bind": ["error"],
"no-floating-decimal": ["error"],
"no-implicit-coercion": ["error", { "disallowTemplateShorthand": true }],
"no-implied-eval": ["error"],
"no-iterator": ["error"],
"no-loop-func": ["error"],
"no-lone-blocks": ["error"],
"no-negated-condition": ["error"],
"no-mixed-operators": ["error", { "allowSamePrecedence": true }],
"no-multi-assign": ["error"],
"no-multi-spaces": ["error"],
"no-multi-str": ["error"],
"no-multiple-empty-lines": ["error", { "max": 1 }],
"no-new": ["error"],
"no-new-func": ["error"],
"no-new-native-nonconstructor": ["error"],
"no-new-wrappers": ["error"],
"no-octal-escape": ["error"],
"no-proto": ["error"],
"no-promise-executor-return": ["error"],
"no-self-compare": ["error"],
"no-template-curly-in-string": ["error"],
"no-unreachable-loop": ["error"],
"no-unused-private-class-members": ["error"],
"no-param-reassign": ["error"],
"no-return-assign": ["error", "always"],
"no-return-await": ["error"],
"no-throw-literal": ["error"],
"no-undef-init": ["error"],
"no-underscore-dangle": ["error"],
"no-unneeded-ternary": ["error", { "defaultAssignment": false }],
"no-useless-call": ["error"],
"no-useless-computed-key": ["error", { "enforceForClassMembers": true }],
"no-useless-concat": ["error"],
"no-useless-constructor": ["error"],
"no-useless-return": ["error"],
"no-useless-rename": ["error"],
"no-var": ["error"],
"no-void": ["error", { "allowAsStatement": true }],
"no-regex-spaces": ["error"],
"no-trailing-spaces": ["error"],
"no-whitespace-before-property": ["error"],
"no-use-before-define": ["off"],
"@typescript-eslint/no-use-before-define": ["warn"],
"@typescript-eslint/consistent-type-imports": ["error", { "prefer": "type-imports" }],
"@typescript-eslint/ban-ts-comment": ["off"],
"operator-assignment": ["error", "always"],
"require-atomic-updates": ["error", { "allowProperties": true }],
"new-cap": ["error", { "newIsCap": true, "capIsNew": true, "properties": true }],
"new-parens": ["error", "never"],
"max-classes-per-file": [
"error",
{ "ignoreExpressions": true, "max": 2 }
],
"max-depth": ["error", 4],
"max-params": ["error", 3],
"max-statements-per-line": ["error", { "max": 2 }],
"require-await": ["error"],
"symbol-description": ["error"],
"lines-around-comment": ["error", {
"beforeBlockComment": true,
"beforeLineComment": true,
"allowBlockStart": true,
"allowClassStart": false,
"allowObjectStart": true
}],
"template-curly-spacing": ["error"],
"wrap-iife": ["error", "outside"],
"space-before-function-paren": ["error", {
"anonymous": "never",
"named": "never",
"asyncArrow": "always"
}],
"space-in-parens": ["error", "never"],
"space-infix-ops": ["error"],
"space-unary-ops": ["error"],
"object-curly-newline": ["warn", { "multiline": true }],
"object-curly-spacing": ["error", "always", { "objectsInObjects": false }],
"operator-linebreak": ["error", "before"],
"padded-blocks": ["error", "never"],
"rest-spread-spacing": ["error", "never"],
"switch-colon-spacing": ["error"],
"template-tag-spacing": ["error"],
"computed-property-spacing": ["error", "never"],
"dot-location": ["error", "property"],
"eol-last": ["error", "always"],
"function-paren-newline": ["error", "consistent"],
"generator-star-spacing": ["error", { "before": false, "after": true }],
"indent": ["error", 4, {
"ignoredNodes": ["TemplateLiteral *"],
"FunctionDeclaration": { "parameters": "first" },
"VariableDeclarator": "first",
"SwitchCase": 1
}],
"line-comment-position": ["error", { "position": "above" }],
"linebreak-style": [ "error", "unix"],
"quotes": ["error", "single"],
"semi": ["error", "always"],
"no-extra-semi": ["error"],
"semi-style": ["error", "last"],
"semi-spacing": ["error"],
"prefer-arrow-callback": ["error"],
"prefer-const": ["error"],
"prefer-named-capture-group": ["error"],
"prefer-numeric-literals": ["error"],
"prefer-object-spread": ["error"],
"prefer-regex-literals": ["error", { "disallowRedundantWrapping": true }],
"prefer-rest-params": ["error"],
"prefer-spread": ["error"],
"prefer-template": ["error"],
"import/no-deprecated": ["error"],
"import/no-mutable-exports": ["error"],
"import/no-self-import": ["error"],
"import/no-useless-path-segments": ["error", {
"noUselessIndex": true
}],
"import/exports-last": ["error"],
"import/first": ["error"],
"import/newline-after-import": ["error"],
"import/prefer-default-export": ["off"],
"import/extensions": [
"error",
"ignorePackages",
{
"ts": "never",
"js": "never"
}
],
"import/order": [
"warn",
{
"groups": ["builtin", "external", "internal", "parent", "sibling", "index", "object", "type"],
"pathGroups": [
{
"pattern": "~/**",
"group": "external",
"position": "before"
}
],
"newlines-between": "always",
"alphabetize": {
"order": "asc",
"caseInsensitive": true
}
}
],
"unicorn/consistent-destructuring": ["error"],
"unicorn/consistent-function-scoping": ["error"],
"unicorn/custom-error-definition": ["error"],
"unicorn/error-message": ["error"],
"unicorn/escape-case": ["error"],
"unicorn/new-for-builtins": ["error"],
"unicorn/no-array-push-push": ["error"],
"unicorn/no-for-loop": ["error"],
"unicorn/no-instanceof-array": ["error"],
"unicorn/no-keyword-prefix": ["warn"],
"unicorn/no-lonely-if": ["error"],
"no-nested-ternary": ["off"],
"unicorn/no-nested-ternary": ["error"],
"unicorn/no-new-array": ["error"],
"unicorn/no-new-buffer": ["error"],
"unicorn/no-null": ["warn"],
"unicorn/no-static-only-class": ["error"],
"unicorn/no-this-assignment": ["error"],
"unicorn/no-unreadable-array-destructuring": ["error"],
"prefer-destructuring": ["error", {
"object": true,
"array": false
}],
"unicorn/no-useless-undefined": ["error", { "checkArguments": false }],
"unicorn/no-zero-fractions": ["error"],
"unicorn/number-literal-case": ["error"],
"unicorn/prefer-array-find": ["error"],
"unicorn/prefer-array-flat": ["error"],
"unicorn/prefer-array-flat-map": ["error"],
"unicorn/prefer-array-index-of": ["error"],
"unicorn/prefer-array-some": ["error"],
"unicorn/prefer-includes": ["error"],
"unicorn/prefer-date-now": ["error"],
"unicorn/prefer-default-parameters": ["error"],
"unicorn/prefer-number-properties": ["error"],
"unicorn/prefer-optional-catch-binding": ["error"],
"unicorn/prefer-reflect-apply": ["error"],
"unicorn/prefer-regexp-test": ["error"],
"unicorn/prefer-set-has": ["error"],
"unicorn/prefer-spread": ["error"],
"unicorn/prefer-string-slice": ["error"],
"unicorn/prefer-string-starts-ends-with": ["error"],
"unicorn/prefer-string-trim-start-end": ["error"],
"unicorn/prefer-ternary": ["error", "only-single-line"],
"unicorn/prefer-type-error": ["error"],
"unicorn/throw-new-error": ["error"]
}
}
{
"env": {
"browser": true,
"es2021": true
},
"settings": {
"react": { "version": "detect" }
},
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:react/jsx-runtime",
"plugin:@typescript-eslint/recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"import",
"jsx-a11y",
"react",
"react-hooks",
"unicorn",
"@typescript-eslint"
],
"rules": {
"array-bracket-newline": ["error", { "multiline": true }],
"array-bracket-spacing": ["error", "never"],
"array-element-newline": ["error", "consistent"],
"array-callback-return": ["error", {
"allowImplicit": true,
"checkForEach": true
}],
"camelcase": ["off"],
"arrow-spacing": ["error", { "before": true, "after": true }],
"block-spacing": ["error"],
"comma-spacing": ["error", { "before": false, "after": true }],
"func-call-spacing": ["error", "never"],
"space-before-blocks": ["error"],
"keyword-spacing": ["error", { "before": true, "after": true }],
"key-spacing": ["error", {
"beforeColon": false,
"afterColon": true,
"align": "value"
}],
"default-case-last": ["error"],
"default-param-last": ["error"],
"logical-assignment-operators": ["error", "always", {
"enforceForIfStatements": true
}],
"no-alert": ["warn"],
"no-await-in-loop": ["error"],
"no-caller": ["error"],
"no-constant-binary-expression": ["error"],
"no-constructor-return": ["error"],
"no-div-regex": ["error"],
"import/no-duplicates": ["error"],
"no-else-return": ["error", { "allowElseIf": false }],
"no-empty": ["error", { "allowEmptyCatch": true }],
"no-eval": ["error", { "allowIndirect": true }],
"no-extra-bind": ["error"],
"no-floating-decimal": ["error"],
"no-implicit-coercion": ["error", { "disallowTemplateShorthand": true }],
"no-implied-eval": ["error"],
"no-iterator": ["error"],
"no-loop-func": ["error"],
"no-lone-blocks": ["error"],
"no-negated-condition": ["error"],
"no-mixed-operators": ["error", { "allowSamePrecedence": true }],
"no-multi-assign": ["error"],
"no-multi-spaces": ["error"],
"no-multi-str": ["error"],
"no-multiple-empty-lines": ["error", { "max": 1 }],
"no-new": ["error"],
"no-new-func": ["error"],
"no-new-native-nonconstructor": ["error"],
"no-new-wrappers": ["error"],
"no-octal-escape": ["error"],
"no-proto": ["error"],
"no-promise-executor-return": ["error"],
"no-self-compare": ["error"],
"no-template-curly-in-string": ["error"],
"no-unreachable-loop": ["error"],
"no-unused-private-class-members": ["error"],
"no-param-reassign": ["error"],
"no-return-assign": ["error", "always"],
"no-return-await": ["error"],
"no-throw-literal": ["error"],
"no-undef-init": ["error"],
"no-underscore-dangle": ["error"],
"no-unneeded-ternary": ["error", { "defaultAssignment": false }],
"no-useless-call": ["error"],
"no-useless-computed-key": ["error", { "enforceForClassMembers": true }],
"no-useless-concat": ["error"],
"no-useless-constructor": ["error"],
"no-useless-return": ["error"],
"no-useless-rename": ["error"],
"no-var": ["error"],
"no-void": ["error", { "allowAsStatement": true }],
"no-regex-spaces": ["error"],
"no-trailing-spaces": ["error"],
"no-whitespace-before-property": ["error"],
"no-use-before-define": ["off"],
"@typescript-eslint/no-use-before-define": ["warn"],
"@typescript-eslint/consistent-type-imports": ["error", { "prefer": "type-imports" }],
"@typescript-eslint/ban-ts-comment": ["off"],
"operator-assignment": ["error", "always"],
"require-atomic-updates": ["error", { "allowProperties": true }],
"new-cap": ["error", { "newIsCap": true, "capIsNew": true, "properties": true }],
"new-parens": ["error", "never"],
"max-classes-per-file": [
"error",
{ "ignoreExpressions": true, "max": 2 }
],
"max-depth": ["error", 4],
"max-params": ["error", 3],
"max-statements-per-line": ["error", { "max": 2 }],
"require-await": ["error"],
"symbol-description": ["error"],
"lines-around-comment": ["error", {
"beforeBlockComment": true,
"beforeLineComment": true,
"allowBlockStart": true,
"allowClassStart": false,
"allowObjectStart": true
}],
"template-curly-spacing": ["error"],
"wrap-iife": ["error", "outside"],
"space-before-function-paren": ["error", {
"anonymous": "never",
"named": "never",
"asyncArrow": "always"
}],
"space-in-parens": ["error", "never"],
"space-infix-ops": ["error"],
"space-unary-ops": ["error"],
"object-curly-newline": ["warn", { "multiline": true }],
"object-curly-spacing": ["error", "always", { "objectsInObjects": false }],
"operator-linebreak": ["error", "before"],
"padded-blocks": ["error", "never"],
"rest-spread-spacing": ["error", "never"],
"switch-colon-spacing": ["error"],
"template-tag-spacing": ["error"],
"computed-property-spacing": ["error", "never"],
"dot-location": ["error", "property"],
"eol-last": ["error", "always"],
"function-paren-newline": ["error", "consistent"],
"generator-star-spacing": ["error", { "before": false, "after": true }],
"indent": ["error", 4, {
"ignoredNodes": ["TemplateLiteral *"],
"FunctionDeclaration": { "parameters": "first" },
"VariableDeclarator": "first",
"SwitchCase": 1
}],
"line-comment-position": ["error", { "position": "above" }],
"linebreak-style": [ "error", "unix"],
"quotes": ["error", "single"],
"semi": ["error", "always"],
"no-extra-semi": ["error"],
"semi-style": ["error", "last"],
"semi-spacing": ["error"],
"prefer-arrow-callback": ["error"],
"prefer-const": ["error"],
"prefer-named-capture-group": ["error"],
"prefer-numeric-literals": ["error"],
"prefer-object-spread": ["error"],
"prefer-regex-literals": ["error", { "disallowRedundantWrapping": true }],
"prefer-rest-params": ["error"],
"prefer-spread": ["error"],
"prefer-template": ["error"],
"import/no-deprecated": ["error"],
"import/no-mutable-exports": ["error"],
"import/no-self-import": ["error"],
"import/no-useless-path-segments": ["error", {
"noUselessIndex": true
}],
"import/exports-last": ["error"],
"import/first": ["error"],
"import/newline-after-import": ["error"],
"import/prefer-default-export": ["off"],
"import/extensions": [
"error",
"ignorePackages",
{
"ts": "never",
"tsx": "never",
"js": "never",
"jsx": "never"
}
],
"import/order": [
"warn",
{
"groups": ["builtin", "external", "internal", "parent", "sibling", "index", "object", "type"],
"pathGroups": [
{
"pattern": "react",
"group": "external",
"position": "before"
}
],
"pathGroupsExcludedImportTypes": ["react"],
"newlines-between": "always",
"alphabetize": {
"order": "asc",
"caseInsensitive": true
}
}
],
"unicorn/consistent-destructuring": ["error"],
"unicorn/consistent-function-scoping": ["error"],
"unicorn/custom-error-definition": ["error"],
"unicorn/error-message": ["error"],
"unicorn/escape-case": ["error"],
"unicorn/new-for-builtins": ["error"],
"unicorn/no-array-push-push": ["error"],
"unicorn/no-for-loop": ["error"],
"unicorn/no-instanceof-array": ["error"],
"unicorn/no-keyword-prefix": ["warn"],
"unicorn/no-lonely-if": ["error"],
"no-nested-ternary": ["off"],
"unicorn/no-nested-ternary": ["error"],
"unicorn/no-new-array": ["error"],
"unicorn/no-new-buffer": ["error"],
"unicorn/no-null": ["warn"],
"unicorn/no-static-only-class": ["error"],
"unicorn/no-this-assignment": ["error"],
"unicorn/no-unreadable-array-destructuring": ["error"],
"prefer-destructuring": ["error", {
"object": true,
"array": false
}],
"unicorn/no-useless-undefined": ["error", { "checkArguments": false }],
"unicorn/no-zero-fractions": ["error"],
"unicorn/number-literal-case": ["error"],
"unicorn/prefer-array-find": ["error"],
"unicorn/prefer-array-flat": ["error"],
"unicorn/prefer-array-flat-map": ["error"],
"unicorn/prefer-array-index-of": ["error"],
"unicorn/prefer-array-some": ["error"],
"unicorn/prefer-includes": ["error"],
"unicorn/prefer-date-now": ["error"],
"unicorn/prefer-default-parameters": ["error"],
"unicorn/prefer-dom-node-append": ["error"],
"unicorn/prefer-dom-node-dataset": ["error"],
"unicorn/prefer-dom-node-remove": ["error"],
"unicorn/prefer-dom-node-text-content": ["error"],
"unicorn/prefer-keyboard-event-key": ["error"],
"unicorn/prefer-modern-dom-apis": ["error"],
"unicorn/prefer-query-selector": ["error"],
"unicorn/prefer-number-properties": ["error"],
"unicorn/prefer-optional-catch-binding": ["error"],
"unicorn/prefer-reflect-apply": ["error"],
"unicorn/prefer-regexp-test": ["error"],
"unicorn/prefer-set-has": ["error"],
"unicorn/prefer-spread": ["error"],
"unicorn/prefer-string-slice": ["error"],
"unicorn/prefer-string-starts-ends-with": ["error"],
"unicorn/prefer-string-trim-start-end": ["error"],
"unicorn/prefer-ternary": ["error", "only-single-line"],
"unicorn/prefer-type-error": ["error"],
"unicorn/throw-new-error": ["error"],
"react-hooks/rules-of-hooks": ["error"],
"react-hooks/exhaustive-deps": ["warn"],
"react/jsx-filename-extension": ["off"],
"react/jsx-props-no-spreading": ["off"],
"react/no-unused-prop-types": ["off"],
"react/prop-types": ["off"],
"react/require-default-props": ["off"],
"jsx-a11y/alt-text": [
"error",
{
"elements": ["img", "object", "area", "input[type=image]"],
"img": ["Image"]
}
],
"jsx-a11y/anchor-has-content": ["error"],
"jsx-a11y/anchor-is-valid": ["error"],
"jsx-a11y/aria-activedescendant-has-tabindex": ["error"],
"jsx-a11y/tabindex-no-positive": ["error"],
"jsx-a11y/aria-props": ["error"],
"jsx-a11y/aria-proptypes": ["error"],
"jsx-a11y/aria-role": [
"error",
{
"allowedInvalidRoles": ["text"]
}
],
"jsx-a11y/aria-unsupported-elements": ["error"],
"jsx-a11y/autocomplete-valid": ["error"],
"jsx-a11y/label-has-associated-control": [
"error",
{
"required": { "some": ["nesting", "id"] }
}
],
"jsx-a11y/click-events-have-key-events": ["error"],
"jsx-a11y/heading-has-content": ["error"],
"jsx-a11y/iframe-has-title": ["error"],
"jsx-a11y/html-has-lang": ["error"],
"jsx-a11y/lang": ["error"],
"jsx-a11y/img-redundant-alt": ["error"],
"jsx-a11y/interactive-supports-focus": ["error"],
"jsx-a11y/media-has-caption": ["error"],
"jsx-a11y/mouse-events-have-key-events": ["error"],
"jsx-a11y/no-access-key": ["error"],
"jsx-a11y/no-autofocus": ["error"],
"jsx-a11y/no-distracting-elements": ["error"],
"jsx-a11y/no-interactive-element-to-noninteractive-role": [
"error",
{
"tr": ["none", "presentation"]
}
],
"jsx-a11y/no-noninteractive-element-interactions": ["error"],
"jsx-a11y/no-noninteractive-element-to-interactive-role": ["error"],
"jsx-a11y/no-noninteractive-tabindex": ["error",
{
"tags": [],
"roles": ["tabpanel"],
"allowExpressionValues": true
}
],
"jsx-a11y/no-static-element-interactions": ["error"],
"jsx-a11y/no-redundant-roles": ["error"],
"jsx-a11y/role-has-required-aria-props": ["error"],
"jsx-a11y/role-supports-aria-props": ["error"],
"jsx-a11y/scope": ["error"]
}
}

Packages for the node version.

npm install -D eslint eslint-import-resolver-typescript eslint-plugin-import eslint-plugin-unicorn @typescript-eslint/eslint-plugin @typescript-eslint/parser

Packages for the react version (it does not includes nextjs specific rules)

npm install -D eslint eslint-import-resolver-typescript eslint-plugin-import eslint-plugin-unicorn @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-jsx-a11y

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