Skip to content

Commit ebdba10

Browse files
author
Huy Nguyen
committed
change set up so that airBnB is a dep
vs fork
1 parent bed0272 commit ebdba10

File tree

9 files changed

+368
-5
lines changed

9 files changed

+368
-5
lines changed

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2012 Airbnb
3+
Copyright (c) 2019 Cloudability
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

configs/base.js

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
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+
};

configs/disable/react-a11y.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const a11yRules = require('eslint-config-airbnb/packages/eslint-config-airbnb/rules/react-a11y');
2+
3+
module.exports = {
4+
rules: Object.keys(a11yRules.rules).reduce((acc, key) => {
5+
if (key.startsWith('jsx-a11y')) {
6+
acc[key] = 'off';
7+
}
8+
9+
return acc;
10+
}, {}),
11+
};

configs/disable/react.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const reactRules = require('eslint-config-airbnb/packages/eslint-config-airbnb/rules/react');
2+
3+
module.exports = {
4+
parserOptions: {
5+
ecmaFeatures: {
6+
jsx: false,
7+
},
8+
},
9+
rules: Object.keys(reactRules.rules).reduce((acc, key) => {
10+
if (key.startsWith('react')) {
11+
acc[key] = 'off';
12+
}
13+
14+
return acc;
15+
}, {}),
16+
};

configs/gui.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
module.exports = {
2+
plugins: ['cloudability'],
3+
extends: [
4+
'./base',
5+
'./disable/react-a11y',
6+
].map(require.resolve),
7+
parserOptions: {
8+
ecmaFeatures: {
9+
jsx: true,
10+
11+
// Temporarily allow "@dec() export {{default}} class A {}"
12+
// TODO - take off band aid and change codebase to "export {{default}} @dec class A{}" as per JS spec
13+
legacyDecorators: true,
14+
},
15+
},
16+
settings: {
17+
'import/resolver': 'webpack',
18+
},
19+
env: {
20+
browser: true,
21+
node : true,
22+
},
23+
globals: {
24+
$ : false,
25+
_ : false,
26+
Backbone: false,
27+
jQuery : false,
28+
29+
DEBUG : false,
30+
cui : false,
31+
cuiLodash: false,
32+
},
33+
34+
rules: {
35+
36+
/*
37+
*
38+
* Custom Cloudability created rules
39+
*
40+
*/
41+
42+
// 'cloudability/foo': 'error',
43+
44+
/*
45+
*
46+
* Extra ES6-related restrictions and misc AirBnB overrides
47+
*
48+
*/
49+
50+
// GUI team has decided against dangling commas
51+
'comma-dangle': ['error', 'never'],
52+
53+
// With modules, `use-strict` is superfluous but we have a mixed building system
54+
strict: 'off',
55+
56+
},
57+
};

configs/guiTests.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module.exports = {
2+
3+
plugins: [
4+
'cypress',
5+
],
6+
7+
globals: {
8+
renderTools: false,
9+
10+
describe: false,
11+
it : false,
12+
},
13+
14+
extends: [
15+
'./gui',
16+
].map(require.resolve),
17+
18+
env: {
19+
browser: false,
20+
21+
mocha: true,
22+
jest : true,
23+
24+
'cypress/globals': true,
25+
},
26+
27+
rules: {
28+
'import/no-extraneous-dependencies': 'off',
29+
30+
'react/jsx-filename-extension': 'off',
31+
32+
'global-require': 'off',
33+
},
34+
};

configs/service.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
extends: [
3+
'./base',
4+
].map(require.resolve),
5+
env: {
6+
browser: false,
7+
node : true,
8+
},
9+
rules: {
10+
11+
// Some libraries use callbacks with a common callback structure. Do not vary this structure
12+
'no-unused-vars': ['error', {
13+
ignoreRestSiblings: true,
14+
argsIgnorePattern : '^done$',
15+
varsIgnorePattern : '^_|CloudyError|config|qlog$',
16+
}],
17+
},
18+
};

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* eslint-disable global-require */
22

3-
const guiConfig = require('./linters/cloudability/gui');
4-
const guiTestsConfig = require('./linters/cloudability/guiTests');
5-
const serviceConfig = require('./linters/cloudability/service');
3+
const guiConfig = require('./configs/gui');
4+
const guiTestsConfig = require('./configs/guiTests');
5+
const serviceConfig = require('./configs/service');
66

77
const customCloudyRules = {
88
/* foo: require('./foo') */

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
"homepage": "https://github.com/cloudability/javascript-style-guide",
4040
"dependencies": {
4141
"babel-eslint": "10.0.1",
42-
"confusing-browser-globals": "1.0.5",
4342
"eslint": "5.12.1",
43+
"eslint-config-airbnb": "17.1.0",
4444
"eslint-import-resolver-webpack": "0.11.0",
4545
"eslint-plugin-cypress": "2.2.0",
4646
"eslint-plugin-import": "2.15.0",

0 commit comments

Comments
 (0)