|
| 1 | +module.exports = { |
| 2 | + parser : 'babel-eslint', |
| 3 | + extends: [ |
| 4 | + 'eslint-config-airbnb/packages/eslint-config-airbnb', |
| 5 | + ].map(require.resolve), |
| 6 | + parserOptions: { |
| 7 | + ecmaVersion: 2018, |
| 8 | + }, |
| 9 | + |
| 10 | + rules: { |
| 11 | + |
| 12 | + /* |
| 13 | + * |
| 14 | + * Rules related to react and other modules |
| 15 | + * |
| 16 | + */ |
| 17 | + |
| 18 | + // Not worth the effort of refactoring all `this.props` usage |
| 19 | + 'react/destructuring-assignment': 'off', |
| 20 | + |
| 21 | + // Forcing spacing with braces in jsx |
| 22 | + 'react/jsx-curly-spacing': ['error', 'always'], |
| 23 | + |
| 24 | + // We want to explicitly define boolean values within jsx |
| 25 | + 'react/jsx-boolean-value': ['error', 'always'], |
| 26 | + |
| 27 | + // AirBnB defaults to useless warnings. Devs should just disable this rule line-by-line as needed |
| 28 | + 'react/no-danger': 'error', |
| 29 | + |
| 30 | + // We heavily use array keys as index throught our code. Benefits are too theoretical to be worth the effort |
| 31 | + 'react/no-array-index-key': 'error', |
| 32 | + |
| 33 | + // AirBnB disabled this for server-rendering scenario, which does not apply to us |
| 34 | + 'react/no-did-mount-set-state': 'error', |
| 35 | + |
| 36 | + // Too many false errors when passing around `props` as fn arg |
| 37 | + 'react/no-unused-prop-types': 'off', |
| 38 | + |
| 39 | + // Check stateless functional components for 'this' in case it was refactored incorrectly |
| 40 | + 'react/no-this-in-sfc': 'error', |
| 41 | + |
| 42 | + // TODO revisit. Does not work well with our custom `propsValidators` usage |
| 43 | + 'react/no-typos': 'off', |
| 44 | + |
| 45 | + // Allow devs to prefer PureComponents when appropriate |
| 46 | + 'react/prefer-stateless-function': ['error', { ignorePureComponents: true }], |
| 47 | + |
| 48 | + // AirBnB overrides default set of options, but those overrides are outdated. Default good enough for us. |
| 49 | + 'react/sort-comp': ['error', {}], |
| 50 | + |
| 51 | + // Theoretically, we should turn this on so we remind ourselves not to depend on webpack too much, but oh well |
| 52 | + 'import/no-webpack-loader-syntax': 'off', |
| 53 | + |
| 54 | + // Ideally should be active to further cement dev-intention in Components props, but not currently worth effort |
| 55 | + 'react/require-default-props': 'off', |
| 56 | + |
| 57 | + |
| 58 | + /* |
| 59 | + * |
| 60 | + * Extra ES6-related restrictions and misc AirBnB overrides |
| 61 | + * |
| 62 | + */ |
| 63 | + |
| 64 | + 'callback-return': 'error', |
| 65 | + |
| 66 | + // Force trailing commas when code is spread over multiple line for cleaner git changes |
| 67 | + 'comma-dangle': ['error', { |
| 68 | + arrays : 'always-multiline', |
| 69 | + objects : 'always-multiline', |
| 70 | + imports : 'always-multiline', |
| 71 | + exports : 'always-multiline', |
| 72 | + functions: 'always-multiline', |
| 73 | + }], |
| 74 | + |
| 75 | + // The consistency checks do not match our early-returns + normal callback coding style |
| 76 | + 'consistent-return': 'off', |
| 77 | + |
| 78 | + // Relaxed but consistent usage of braces |
| 79 | + curly: ['error', 'multi-line', 'consistent'], |
| 80 | + |
| 81 | + // Ensures that debug traces will give readable function names |
| 82 | + 'func-names': ['error', 'as-needed'], |
| 83 | + |
| 84 | + // Devs can choose most readable style as long as consistent for every arg |
| 85 | + 'function-paren-newline': ['error', 'consistent'], |
| 86 | + |
| 87 | + // Enforces styling similar to how MDN writes their generators |
| 88 | + 'generator-star-spacing': ['error', { before: false, after: true }], |
| 89 | + |
| 90 | + 'handle-callback-err': ['error', '^(err|.*(e|E)rror)'], |
| 91 | + |
| 92 | + // Rule should be identical to AirBnB except for VariableDeclarator & MemberExpression |
| 93 | + indent: ['error', 2, { |
| 94 | + SwitchCase : 1, |
| 95 | + VariableDeclarator : { var: 2, let: 2, const: 3 }, |
| 96 | + outerIIFEBody : 1, |
| 97 | + MemberExpression : 'off', |
| 98 | + FunctionDeclaration : { parameters: 1, body: 1 }, |
| 99 | + FunctionExpression : { parameters: 1, body: 1 }, |
| 100 | + CallExpression : { arguments: 1 }, |
| 101 | + ArrayExpression : 1, |
| 102 | + ObjectExpression : 1, |
| 103 | + ImportDeclaration : 1, |
| 104 | + flatTernaryExpressions: false, |
| 105 | + ignoredNodes : ['JSXElement', 'JSXElement > *', 'JSXAttribute', 'JSXIdentifier', 'JSXNamespacedName', 'JSXMemberExpression', 'JSXSpreadAttribute', 'JSXExpressionContainer', 'JSXOpeningElement', 'JSXClosingElement', 'JSXText', 'JSXEmptyExpression', 'JSXSpreadChild'], |
| 106 | + ignoreComments : false, |
| 107 | + }], |
| 108 | + |
| 109 | + // Align on colon to use auto-fix to prettify large objects |
| 110 | + 'key-spacing': [ |
| 111 | + 2, { |
| 112 | + singleLine: { beforeColon: false, afterColon: true }, |
| 113 | + multiLine : { beforeColon: false, afterColon: true, align: 'colon' }, |
| 114 | + }, |
| 115 | + ], |
| 116 | + |
| 117 | + 'lines-around-comment': ['error', { |
| 118 | + beforeBlockComment: true, |
| 119 | + beforeLineComment : true, |
| 120 | + allowBlockStart : true, |
| 121 | + allowObjectStart : true, |
| 122 | + }], |
| 123 | + |
| 124 | + // Devs can choose best style here |
| 125 | + 'multiline-ternary': 'off', |
| 126 | + |
| 127 | + // Should not leak stuff to clientside |
| 128 | + 'no-console': 'error', |
| 129 | + |
| 130 | + // Allow multiple spaces only in certain situations involving aligned white spaces |
| 131 | + 'no-multi-spaces': ['error', { |
| 132 | + exceptions: { |
| 133 | + ImportDeclaration : true, |
| 134 | + Property : true, |
| 135 | + LogicalExpression : true, |
| 136 | + VariableDeclarator: true, |
| 137 | + }, |
| 138 | + }], |
| 139 | + |
| 140 | + // Do not allow shadowed functions except in cases of extremely common parameter names |
| 141 | + 'no-shadow': ['error', { allow: ['callback', 'cb', 'done', 'err', 'error', 'next', 'req', 'res'] }], |
| 142 | + |
| 143 | + // Currently a standard usage in GUI js |
| 144 | + 'no-underscore-dangle': 'off', |
| 145 | + |
| 146 | + // Only start enforcing rule when there are 5 or more props |
| 147 | + 'object-curly-newline': [ |
| 148 | + 'error', |
| 149 | + { |
| 150 | + ObjectExpression: { |
| 151 | + minProperties: 5, |
| 152 | + multiline : true, |
| 153 | + consistent : true, |
| 154 | + }, |
| 155 | + ObjectPattern: { |
| 156 | + minProperties: 5, |
| 157 | + multiline : true, |
| 158 | + consistent : true, |
| 159 | + }, |
| 160 | + ImportDeclaration: { minProperties: 5, multiline: true, consistent: true }, |
| 161 | + ExportDeclaration: { minProperties: 5, multiline: true, consistent: true }, |
| 162 | + }, |
| 163 | + ], |
| 164 | + |
| 165 | + // Only enforce shorthand on properties because doing so on methods produces weird behavior with anonymous fn |
| 166 | + 'object-shorthand': ['error', 'properties'], |
| 167 | + |
| 168 | + // Aggregate uninitialized declarations into one line. Otherwise, use multiple |
| 169 | + 'one-var': ['error', { uninitialized: 'always', initialized: 'never' }], |
| 170 | + |
| 171 | + // We allow developers to add padded blocks if they aid readability |
| 172 | + 'padded-blocks': 'off', |
| 173 | + |
| 174 | + // Override default by allowing named functions, which makes stack traces more readable |
| 175 | + 'prefer-arrow-callback': ['error', { |
| 176 | + allowNamedFunctions: true, |
| 177 | + allowUnboundThis : true, |
| 178 | + }], |
| 179 | + |
| 180 | + // Interferes with other rules when trying to destructure off of `this`. Also, too heavy handed a rule |
| 181 | + 'prefer-destructuring': 'off', |
| 182 | + |
| 183 | + // Benefit of string templates is not worth all the white noise of current GUI infractions |
| 184 | + 'prefer-template': 'off', |
| 185 | + |
| 186 | + // We do not like space before the first parenthesis in function decl |
| 187 | + 'space-before-function-paren': ['error', 'never'], |
| 188 | + 'spaced-comment' : ['error', 'always', { |
| 189 | + line: { |
| 190 | + markers: ['/', 'global'], |
| 191 | + }, |
| 192 | + block: { |
| 193 | + exceptions: ['*'], |
| 194 | + balanced : true, |
| 195 | + }, |
| 196 | + }], |
| 197 | + |
| 198 | + // Always specify `use-strict` at top-level |
| 199 | + strict: ['error', 'global'], |
| 200 | + |
| 201 | + /* |
| 202 | + * |
| 203 | + * Taken & adapted from Cloudability GUI's eslint |
| 204 | + * |
| 205 | + */ |
| 206 | + 'func-style': ['error', 'declaration', { allowArrowFunctions: true }], |
| 207 | + |
| 208 | + // A very large chunk of our code base puts operator at end |
| 209 | + 'operator-linebreak': ['error', 'after'], |
| 210 | + |
| 211 | + // Stuff taken & adapted from Datahero's unfinished eslint |
| 212 | + 'no-alert' : 'error', |
| 213 | + 'no-constant-condition': 'error', |
| 214 | + 'no-use-before-define' : ['error', 'nofunc'], |
| 215 | + 'max-len' : ['error', { |
| 216 | + code : 120, |
| 217 | + tabWidth: 2, |
| 218 | + |
| 219 | + ignoreComments: true, |
| 220 | + |
| 221 | + ignoreRegExpLiterals: true, |
| 222 | + |
| 223 | + // require / import statements can be as long as they need to be |
| 224 | + ignorePattern: ".*(\\(|\\s)+(require|import)\\(\\'", |
| 225 | + }], |
| 226 | + }, |
| 227 | +}; |
0 commit comments