|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const airbnbBase = require('eslint-config-airbnb-base'); |
| 4 | + |
| 5 | +// eslint-disable-next-line import/no-dynamic-require |
| 6 | +const bestPractices = require(airbnbBase.extends[0]); |
| 7 | + |
| 8 | +const ignoredProps = bestPractices.rules[ |
| 9 | + 'no-param-reassign' |
| 10 | +][1].ignorePropertyModificationsFor.concat( |
| 11 | + 'err', |
| 12 | + 'x', |
| 13 | + '_', |
| 14 | + 'opts', |
| 15 | + 'options', |
| 16 | + 'settings', |
| 17 | + 'config', |
| 18 | + 'cfg', |
| 19 | +); |
| 20 | + |
| 21 | +// Additional rules that are specific and overiding previous |
| 22 | +const additionalChanges = { |
| 23 | + strict: 'off', |
| 24 | + |
| 25 | + // Enforce using named functions when regular function is used, |
| 26 | + // otherwise use arrow functions |
| 27 | + 'func-names': ['error', 'always'], |
| 28 | + // Always use parens (for consistency). |
| 29 | + // https://eslint.org/docs/rules/arrow-parens |
| 30 | + 'arrow-parens': ['error', 'always', { requireForBlockBody: true }], |
| 31 | + 'prefer-arrow-callback': [ |
| 32 | + 'error', |
| 33 | + { allowNamedFunctions: true, allowUnboundThis: true }, |
| 34 | + ], |
| 35 | + // http://eslint.org/docs/rules/max-params |
| 36 | + 'max-params': ['error', { max: 3 }], |
| 37 | + // http://eslint.org/docs/rules/max-statements |
| 38 | + 'max-statements': ['error', { max: 20 }], |
| 39 | + // http://eslint.org/docs/rules/max-statements-per-line |
| 40 | + 'max-statements-per-line': ['error', { max: 1 }], |
| 41 | + // http://eslint.org/docs/rules/max-nested-callbacks |
| 42 | + 'max-nested-callbacks': ['error', { max: 4 }], |
| 43 | + // http://eslint.org/docs/rules/max-depth |
| 44 | + 'max-depth': ['error', { max: 4 }], |
| 45 | + // enforces no braces where they can be omitted |
| 46 | + // https://eslint.org/docs/rules/arrow-body-style |
| 47 | + // Never enable for object literal. |
| 48 | + 'arrow-body-style': [ |
| 49 | + 'error', |
| 50 | + 'as-needed', |
| 51 | + { requireReturnForObjectLiteral: false }, |
| 52 | + ], |
| 53 | + // Allow functions to be use before define because: |
| 54 | + // 1) they are hoisted, |
| 55 | + // 2) because ensure read flow is from top to bottom |
| 56 | + // 3) logically order of the code. |
| 57 | + // 4) the only addition is 'typedefs' option, see overrides for TS files |
| 58 | + 'no-use-before-define': [ |
| 59 | + 'error', |
| 60 | + { |
| 61 | + functions: false, |
| 62 | + classes: true, |
| 63 | + variables: true, |
| 64 | + }, |
| 65 | + ], |
| 66 | + // Same as AirBnB, but adds `opts`, `options`, `x` and `err` to exclusions! |
| 67 | + // disallow reassignment of function parameters |
| 68 | + // disallow parameter object manipulation except for specific exclusions |
| 69 | + // rule: https://eslint.org/docs/rules/no-param-reassign.html |
| 70 | + 'no-param-reassign': [ |
| 71 | + 'error', |
| 72 | + { |
| 73 | + props: true, |
| 74 | + ignorePropertyModificationsFor: ignoredProps, |
| 75 | + }, |
| 76 | + ], |
| 77 | + |
| 78 | + // disallow declaration of variables that are not used in the code |
| 79 | + 'no-unused-vars': [ |
| 80 | + 'error', |
| 81 | + { |
| 82 | + ignoreRestSiblings: true, // airbnb's default |
| 83 | + vars: 'all', // airbnb's default |
| 84 | + varsIgnorePattern: '^(?:$$|xx|_|__|[iI]gnor(?:e|ing|ed))', |
| 85 | + args: 'after-used', // airbnb's default |
| 86 | + argsIgnorePattern: '^(?:$$|xx|_|__|[iI]gnor(?:e|ing|ed))', |
| 87 | + |
| 88 | + // catch blocks are handled by Unicorns |
| 89 | + caughtErrors: 'none', |
| 90 | + // caughtErrorsIgnorePattern: '^(?:$$|xx|_|__|[iI]gnor(?:e|ing|ed))', |
| 91 | + }, |
| 92 | + ], |
| 93 | +}; |
| 94 | + |
| 95 | +const importRules = { |
| 96 | + 'import/namespace': ['error', { allowComputed: true }], |
| 97 | + 'import/no-absolute-path': 'error', |
| 98 | + 'import/no-webpack-loader-syntax': 'error', |
| 99 | + 'import/no-self-import': 'error', |
| 100 | + |
| 101 | + // Enable this sometime in the future when Node.js has ES2015 module support |
| 102 | + // 'import/no-cycle': 'error', |
| 103 | + |
| 104 | + // Disabled as it doesn't work with TypeScript |
| 105 | + // 'import/newline-after-import': 'error', |
| 106 | + |
| 107 | + 'import/no-amd': 'error', |
| 108 | + 'import/no-duplicates': 'error', |
| 109 | + |
| 110 | + // Enable this sometime in the future when Node.js has ES2015 module support |
| 111 | + // 'import/unambiguous': 'error', |
| 112 | + |
| 113 | + // Enable this sometime in the future when Node.js has ES2015 module support |
| 114 | + // 'import/no-commonjs': 'error', |
| 115 | + |
| 116 | + // Looks useful, but too unstable at the moment |
| 117 | + // 'import/no-deprecated': 'error', |
| 118 | + |
| 119 | + 'import/no-extraneous-dependencies': 'off', |
| 120 | + 'import/no-mutable-exports': 'error', |
| 121 | + 'import/no-named-as-default-member': 'error', |
| 122 | + 'import/no-named-as-default': 'error', |
| 123 | + |
| 124 | + // Disabled because it's buggy and it also doesn't work with TypeScript |
| 125 | + // 'import/no-unresolved': [ |
| 126 | + // 'error', |
| 127 | + // { |
| 128 | + // commonjs: true |
| 129 | + // } |
| 130 | + // ], |
| 131 | + |
| 132 | + 'import/order': 'error', |
| 133 | + 'import/no-unassigned-import': [ |
| 134 | + 'error', |
| 135 | + { allow: ['@babel/polyfill', '@babel/register'] }, |
| 136 | + ], |
| 137 | + |
| 138 | + 'import/prefer-default-export': 'off', |
| 139 | + |
| 140 | + // Ensure more web-compat |
| 141 | + // ! note that it doesn't work in CommonJS |
| 142 | + // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/extensions.md |
| 143 | + 'import/extensions': 'off', |
| 144 | + |
| 145 | + // ? Always use named exports. Enable? |
| 146 | + // 'import/no-default-export': 'error', |
| 147 | + |
| 148 | + // ? enable? |
| 149 | + 'import/exports-last': 'off', |
| 150 | + |
| 151 | + // todo: Enable in future. |
| 152 | + // Ensures everything is tested (all exports should be used). |
| 153 | + // For cases when you don't want or can't test, add eslint-ignore comment! |
| 154 | + // see: https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-unused-modules.md |
| 155 | + 'import/no-unused-modules': 'off', |
| 156 | + |
| 157 | + 'import/no-useless-path-segments': ['error', { noUselessIndex: false }], |
| 158 | +}; |
| 159 | + |
| 160 | +module.exports = { |
| 161 | + env: { |
| 162 | + es6: true, |
| 163 | + es2020: true, |
| 164 | + jest: true, |
| 165 | + node: true, |
| 166 | + commonjs: true, |
| 167 | + }, |
| 168 | + extends: ['eslint:recommended', 'airbnb-base', 'plugin:prettier/recommended'], |
| 169 | + plugins: ['prettier'], |
| 170 | + rules: { |
| 171 | + 'prettier/prettier': 'error', |
| 172 | + |
| 173 | + ...additionalChanges, |
| 174 | + ...importRules, |
| 175 | + }, |
| 176 | +}; |
0 commit comments