|
| 1 | +# Traitify's Javascript Style Guide |
| 2 | + |
| 3 | +**Note**: This guide just outlines the differences from [Airbnb's Guide](https://github.com/airbnb/javascript) |
| 4 | + |
| 5 | +## Rules |
| 6 | + |
| 7 | + - [arrow-parens](https://eslint.org/docs/rules/arrow-parens) |
| 8 | + |
| 9 | + `"arrow-parens": ["error", "always"]` |
| 10 | + |
| 11 | + > Consistency |
| 12 | +
|
| 13 | + - [babel/object-curly-spacing](https://github.com/babel/eslint-plugin-babel) |
| 14 | + |
| 15 | + `"babel/object-curly-spacing": "error"` |
| 16 | + |
| 17 | + > Replace non-babel version |
| 18 | +
|
| 19 | + - [class-methods-use-this](https://eslint.org/docs/rules/class-methods-use-this) |
| 20 | + |
| 21 | + `"class-methods-use-this": "off"` |
| 22 | + |
| 23 | + > Allows methods to be overridden |
| 24 | +
|
| 25 | + - [comma-dangle](https://eslint.org/docs/rules/comma-dangle) |
| 26 | + |
| 27 | + `"comma-dangle": ["error", "never"]` |
| 28 | + |
| 29 | + > Unnecessary |
| 30 | +
|
| 31 | + - [consistent-return](https://eslint.org/docs/rules/consistent-return) |
| 32 | + |
| 33 | + `"consistent-return": "off"` |
| 34 | + |
| 35 | + > Makes it hard to return early for conditionals |
| 36 | +
|
| 37 | + - [func-names](https://eslint.org/docs/rules/func-names) |
| 38 | + |
| 39 | + `"func-names": "off"` |
| 40 | + |
| 41 | + > Unnecessary and unused with arrow functions |
| 42 | +
|
| 43 | + - [jsx-a11y/label-has-for](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/label-has-for.md) |
| 44 | + |
| 45 | + > Deprecated |
| 46 | +
|
| 47 | + ``` |
| 48 | + "jsx-a11y/label-has-for": ["error", { |
| 49 | + components: [], |
| 50 | + required: { |
| 51 | + some: ["nesting", "id"], |
| 52 | + }, |
| 53 | + allowChildren: false, |
| 54 | + }] |
| 55 | + ``` |
| 56 | +
|
| 57 | + > Unnecessary to have nesting for both |
| 58 | +
|
| 59 | + - [keyword-spacing](https://eslint.org/docs/rules/keyword-spacing) |
| 60 | +
|
| 61 | + ``` |
| 62 | + "keyword-spacing": ["error", { |
| 63 | + before: false, |
| 64 | + after: false, |
| 65 | + overrides: { |
| 66 | + as: {before: true, after: true}, |
| 67 | + case: {before: true, after: true}, |
| 68 | + catch: {before: true}, |
| 69 | + const: {before: true, after: true}, |
| 70 | + default: {before: true, after: true}, |
| 71 | + else: {before: true, after: true}, |
| 72 | + export: {before: true, after: true}, |
| 73 | + from: {before: true, after: true}, |
| 74 | + import: {before: true, after: true}, |
| 75 | + let: {before: true, after: true}, |
| 76 | + return: {before: true, after: true}, |
| 77 | + this: {before: true, after: true}, |
| 78 | + try: {before: true, after: true} |
| 79 | + } |
| 80 | + }] |
| 81 | +
|
| 82 | + ``` |
| 83 | +
|
| 84 | + > Whitespace - Preference |
| 85 | +
|
| 86 | + - [lines-between-class-members](https://eslint.org/docs/rules/lines-between-class-members) |
| 87 | +
|
| 88 | + `"lines-between-class-members": ["error", "never"]` |
| 89 | +
|
| 90 | + > Whitespace - Preference |
| 91 | +
|
| 92 | + - [no-else-return](https://eslint.org/docs/rules/no-else-return) |
| 93 | +
|
| 94 | + `"no-else-return": "off"` |
| 95 | +
|
| 96 | + > Allows more functional styles |
| 97 | +
|
| 98 | + - [no-multiple-empty-lines](https://eslint.org/docs/rules/no-multiple-empty-lines) |
| 99 | +
|
| 100 | + `"no-multiple-empty-lines": ["error", {max: 1, maxBOF: 0, maxEOF: 0}]` |
| 101 | +
|
| 102 | + > Little stricter |
| 103 | +
|
| 104 | + - [no-underscore-dangle](https://eslint.org/docs/rules/no-underscore-dangle) |
| 105 | +
|
| 106 | + `"no-underscore-dangle": "off"` |
| 107 | +
|
| 108 | + > Doesn't allow `const key = _key.toLowerCase()` |
| 109 | +
|
| 110 | + - [no-unused-expressions](https://eslint.org/docs/rules/no-unused-expressions) |
| 111 | +
|
| 112 | + `"no-unused-expressions": ["error", {allowShortCircuit: true, allowTernary: true}]` |
| 113 | +
|
| 114 | + > Short circuits and ternaries are efficient |
| 115 | +
|
| 116 | + - [object-curly-newline](https://eslint.org/docs/rules/object-curly-newline) |
| 117 | +
|
| 118 | + `"object-curly-newline": ["error", {multiline: true, consistent: true}]` |
| 119 | +
|
| 120 | + > Too strict |
| 121 | +
|
| 122 | + - [object-curly-spacing](https://eslint.org/docs/rules/object-curly-spacing) |
| 123 | +
|
| 124 | + `"object-curly-spacing": "off"` |
| 125 | +
|
| 126 | + > Incompatible with babel/object-curly-spacing |
| 127 | +
|
| 128 | + - [prefer-destructuring](https://eslint.org/docs/rules/prefer-destructuring) |
| 129 | +
|
| 130 | + ``` |
| 131 | + "prefer-destructuring": ["error", { |
| 132 | + VariableDeclarator: { |
| 133 | + array: false, |
| 134 | + object: true, |
| 135 | + }, |
| 136 | + AssignmentExpression: { |
| 137 | + array: false, |
| 138 | + object: false, |
| 139 | + }, |
| 140 | + }, { |
| 141 | + enforceForRenamedProperties: false, |
| 142 | + }] |
| 143 | + ``` |
| 144 | +
|
| 145 | + > Assignment expression looks funky with parens |
| 146 | +
|
| 147 | + - [quote-props](https://eslint.org/docs/rules/quote-props) |
| 148 | +
|
| 149 | + `"quote-props": ["error", "consistent-as-needed", {keywords: false}]` |
| 150 | +
|
| 151 | + > Consistency |
| 152 | +
|
| 153 | + - [quotes](https://eslint.org/docs/rules/quotes) |
| 154 | +
|
| 155 | + `"quotes": ["error", "double", {allowTemplateLiterals: true}]` |
| 156 | +
|
| 157 | + > Double quotes are life |
| 158 | +
|
| 159 | + - [react/destructuring-assignment](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/destructuring-assignment.md) |
| 160 | +
|
| 161 | + `"react/destructuring-assignment": "off"` |
| 162 | +
|
| 163 | + > Overactive and solved by prefer-destructuring |
| 164 | +
|
| 165 | + - [react/jsx-boolean-value](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md) |
| 166 | +
|
| 167 | + `"react/jsx-boolean-value": ["error", "always"]` |
| 168 | +
|
| 169 | + > Prefer explicit |
| 170 | +
|
| 171 | + - [react/jsx-filename-extension](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-filename-extension.md) |
| 172 | +
|
| 173 | + `"react/jsx-filename-extension": "off"` |
| 174 | +
|
| 175 | + > Unnecessary |
| 176 | +
|
| 177 | + - [react/jsx-one-expression-per-line](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-one-expression-per-line.md) |
| 178 | +
|
| 179 | + `"react/jsx-one-expression-per-line": "off"` |
| 180 | +
|
| 181 | + > Creates unnecessary white space issues |
| 182 | +
|
| 183 | + - [react/no-did-update-set-state](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-update-set-state.md) |
| 184 | +
|
| 185 | + `"react/no-did-update-set-state": "off"` |
| 186 | +
|
| 187 | + > Makes hacks needed for prop change triggers |
| 188 | +
|
| 189 | + - [react/prefer-stateless-function](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-stateless-function.md) |
| 190 | +
|
| 191 | + `"react/prefer-stateless-function": "off"` |
| 192 | +
|
| 193 | + > Prefer React |
| 194 | +
|
| 195 | + - [react/react-in-jsx-scope](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/react-in-jsx-scope.md) |
| 196 | +
|
| 197 | + `"react/react-in-jsx-scope": "off"` |
| 198 | +
|
| 199 | + > Global React |
| 200 | +
|
| 201 | + - [space-before-function-paren](https://eslint.org/docs/rules/space-before-function-paren) |
| 202 | +
|
| 203 | + `"space-before-function-paren": ["error", "never"]` |
| 204 | +
|
| 205 | + > Whitespace - Preference |
| 206 | +
|
| 207 | +## TODO |
| 208 | +
|
| 209 | +These rules are turned off temporarily |
| 210 | +
|
| 211 | + - [react/no-unused-state](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-unused-state.md) |
| 212 | +
|
| 213 | + `"react/no-unused-state": "off"` |
| 214 | +
|
| 215 | + > Remove when rule is fixed for setState function |
| 216 | +
|
| 217 | + - [react/sort-comp](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md) |
| 218 | +
|
| 219 | + `"react/sort-comp": "off"` |
| 220 | +
|
| 221 | + > Remove when airbnb includes componentDidCatch |
0 commit comments