Skip to content

Commit 1a98adb

Browse files
committed
Merge pull request HubSpot#9 from HubSpot/airbnb-rebase
Rebase with airbnb/master
2 parents 76c240b + d944222 commit 1a98adb

File tree

10 files changed

+152
-119
lines changed

10 files changed

+152
-119
lines changed

README.md

Lines changed: 69 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Other Style Guides (from Airbnb)
9494

9595
- [2.1](#2.1) <a name='2.1'></a> Use `const` for all of your references; avoid using `var`.
9696

97-
> Why? This ensures that you can't reassign your references (mutation), which can lead to bugs and difficult to comprehend code.
97+
> Why? This ensures that you can't reassign your references, which can lead to bugs and difficult to comprehend code.
9898
9999
```javascript
100100
// bad
@@ -106,7 +106,7 @@ Other Style Guides (from Airbnb)
106106
const b = 2;
107107
```
108108
109-
- [2.2](#2.2) <a name='2.2'></a> If you must mutate references, use `let` instead of `var`.
109+
- [2.2](#2.2) <a name='2.2'></a> If you must reassign references, use `let` instead of `var`.
110110
111111
> Why? `let` is block-scoped rather than function-scoped like `var`.
112112
@@ -452,7 +452,7 @@ Other Style Guides (from Airbnb)
452452
return `How are you, ${name}?`;
453453
}
454454
```
455-
- [6.5](#6.5) <a name='6.5'></a> Never use eval() on a string, it opens too many vulnerabilities.
455+
- [6.5](#6.5) <a name='6.5'></a> Never use `eval()` on a string, it opens too many vulnerabilities.
456456
457457
**[⬆ back to top](#table-of-contents)**
458458
@@ -1114,7 +1114,7 @@ Other Style Guides (from Airbnb)
11141114
}
11151115
```
11161116
1117-
- For more information refer to [JavaScript Scoping & Hoisting](http://www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting) by [Ben Cherry](http://www.adequatelygood.com/).
1117+
- For more information refer to [JavaScript Scoping & Hoisting](http://www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting/) by [Ben Cherry](http://www.adequatelygood.com/).
11181118
11191119
**[⬆ back to top](#table-of-contents)**
11201120
@@ -1253,7 +1253,7 @@ Other Style Guides (from Airbnb)
12531253
}
12541254
```
12551255
1256-
- [17.2](#17.2) <a name='17.2'></a> Use `//` for single line comments. Place single line comments on a newline above the subject of the comment. Put an empty line before the comment.
1256+
- [17.2](#17.2) <a name='17.2'></a> Use `//` for single line comments. Place single line comments on a newline above the subject of the comment. Put an empty line before the comment unless it's on the first line of a block.
12571257

12581258
```javascript
12591259
// bad
@@ -1281,6 +1281,14 @@ Other Style Guides (from Airbnb)
12811281
12821282
return type;
12831283
}
1284+
1285+
// also good
1286+
function getType() {
1287+
// set the default type to 'no type'
1288+
const type = this._type || 'no type';
1289+
1290+
return type;
1291+
}
12841292
```
12851293

12861294
- [17.3](#17.3) <a name='17.3'></a> Prefixing your comments with `FIXME` or `TODO` helps other developers quickly understand if you're pointing out a problem that needs to be revisited, or if you're suggesting a solution to the problem that needs to be implemented. These are different than regular comments because they are actionable. The actions are `FIXME -- need to figure this out` or `TODO -- need to implement`.
@@ -1516,6 +1524,38 @@ Other Style Guides (from Airbnb)
15161524
return arr;
15171525
```
15181526
1527+
- [18.8](#18.8) <a name='18.8'></a> Do not pad your blocks with blank lines.
1528+
1529+
```javascript
1530+
// bad
1531+
function bar() {
1532+
1533+
console.log(foo);
1534+
1535+
}
1536+
1537+
// also bad
1538+
if (baz) {
1539+
1540+
console.log(qux);
1541+
} else {
1542+
console.log(foo);
1543+
1544+
}
1545+
1546+
// good
1547+
function bar() {
1548+
console.log(foo);
1549+
}
1550+
1551+
// good
1552+
if (baz) {
1553+
console.log(qux);
1554+
} else {
1555+
console.log(foo);
1556+
}
1557+
```
1558+
15191559
15201560
**[⬆ back to top](#table-of-contents)**
15211561
@@ -1625,7 +1665,7 @@ Other Style Guides (from Airbnb)
16251665
})();
16261666
```
16271667
1628-
[Read more](http://stackoverflow.com/a/7365214/1712802).
1668+
[Read more](http://stackoverflow.com/questions/7365172/semicolon-before-self-invoking-function/7365214%237365214).
16291669
16301670
**[⬆ back to top](#table-of-contents)**
16311671
@@ -1994,7 +2034,7 @@ Other Style Guides (from Airbnb)
19942034
19952035
## ECMAScript 5 Compatibility
19962036
1997-
- [26.1](#26.1) <a name='26.1'></a> Refer to [Kangax](https://twitter.com/kangax/)'s ES5 [compatibility table](http://kangax.github.com/es5-compat-table/).
2037+
- [26.1](#26.1) <a name='26.1'></a> Refer to [Kangax](https://twitter.com/kangax/)'s ES5 [compatibility table](http://kangax.github.io/es5-compat-table/).
19982038
19992039
**[⬆ back to top](#table-of-contents)**
20002040
@@ -2028,6 +2068,14 @@ Other Style Guides (from Airbnb)
20282068
}
20292069
```
20302070
2071+
- [28.2](#28.2) <a name="28.2"></a> **No, but seriously**:
2072+
- Whichever testing framework you use, you should be writing tests!
2073+
- Strive to write many small pure functions, and minimize where mutations occur.
2074+
- Be cautious about stubs and mocks - they can make your tests more brittle.
2075+
- We primarily use [`mocha`](https://www.npmjs.com/package/mocha) at Airbnb. [`tape`](https://www.npmjs.com/package/tape) is also used occasionally for small, separate modules.
2076+
- 100% test coverage is a good goal to strive for, even if it's not always practical to reach it.
2077+
- Whenever you fix a bug, _write a regression test_. A bug fixed without a regression test is almost certainly going to break again in the future.
2078+
20312079
**[⬆ back to top](#table-of-contents)**
20322080
20332081
@@ -2098,7 +2146,7 @@ Other Style Guides (from Airbnb)
20982146
20992147
## Performance
21002148
2101-
- [On Layout & Web Performance](http://kellegous.com/j/2013/01/26/layout-performance/)
2149+
- [On Layout & Web Performance](http://www.kellegous.com/j/2013/01/26/layout-performance/)
21022150
- [String vs Array Concat](http://jsperf.com/string-vs-array-concat/2)
21032151
- [Try/Catch Cost In a Loop](http://jsperf.com/try-catch-in-loop-cost)
21042152
- [Bang Function](http://jsperf.com/bang-function)
@@ -2128,18 +2176,18 @@ Other Style Guides (from Airbnb)
21282176
- Code Style Linters
21292177
+ [ESlint](http://eslint.org/) - [HubSpot Style .eslintrc](https://github.com/HubSpot/javascript/blob/master/linters/.eslintrc)
21302178
+ [ESlint](http://eslint.org/) - [Airbnb Style .eslintrc](https://github.com/airbnb/javascript/blob/master/linters/.eslintrc)
2131-
+ [JSHint](http://www.jshint.com/) - [Airbnb Style .jshintrc](https://github.com/airbnb/javascript/blob/master/linters/jshintrc)
2179+
+ [JSHint](http://jshint.com/) - [Airbnb Style .jshintrc](https://github.com/airbnb/javascript/blob/master/linters/jshintrc)
21322180
+ [JSCS](https://github.com/jscs-dev/node-jscs) - [Airbnb Style Preset](https://github.com/jscs-dev/node-jscs/blob/master/presets/airbnb.json)
21332181
21342182
**Other Style Guides**
21352183
21362184
- [Google JavaScript Style Guide](http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml)
2137-
- [jQuery Core Style Guidelines](http://docs.jquery.com/JQuery_Core_Style_Guidelines)
2138-
- [Principles of Writing Consistent, Idiomatic JavaScript](https://github.com/rwldrn/idiomatic.js/)
2185+
- [jQuery Core Style Guidelines](http://contribute.jquery.org/style-guide/js/)
2186+
- [Principles of Writing Consistent, Idiomatic JavaScript](https://github.com/rwaldron/idiomatic.js)
21392187
21402188
**Other Styles**
21412189
2142-
- [Naming this in nested functions](https://gist.github.com/4135065) - Christian Johansen
2190+
- [Naming this in nested functions](https://gist.github.com/cjohansen/4135065) - Christian Johansen
21432191
- [Conditional Callbacks](https://github.com/airbnb/javascript/issues/52) - Ross Allen
21442192
- [Popular JavaScript Coding Conventions on Github](http://sideeffect.kr/popularconvention/#javascript) - JeongHoon Byun
21452193
- [Multiple var statements in JavaScript, not superfluous](http://benalman.com/news/2012/05/multiple-var-statements-javascript/) - Ben Alman
@@ -2166,7 +2214,7 @@ Other Style Guides (from Airbnb)
21662214
- [Human JavaScript](http://humanjavascript.com/) - Henrik Joreteg
21672215
- [Superhero.js](http://superherojs.com/) - Kim Joar Bekkelund, Mads Mobæk, & Olav Bjorkoy
21682216
- [JSBooks](http://jsbooks.revolunet.com/) - Julien Bouquillon
2169-
- [Third Party JavaScript](http://manning.com/vinegar/) - Ben Vinegar and Anton Kovalyov
2217+
- [Third Party JavaScript](https://www.manning.com/books/third-party-javascript) - Ben Vinegar and Anton Kovalyov
21702218
- [Effective JavaScript: 68 Specific Ways to Harness the Power of JavaScript](http://amzn.com/0321812182) - David Herman
21712219
- [Eloquent JavaScript](http://eloquentjavascript.net/) - Marijn Haverbeke
21722220
- [You Don't Know JS: ES6 & Beyond](http://shop.oreilly.com/product/0636920033769.do) - Kyle Simpson
@@ -2176,18 +2224,18 @@ Other Style Guides (from Airbnb)
21762224
- [DailyJS](http://dailyjs.com/)
21772225
- [JavaScript Weekly](http://javascriptweekly.com/)
21782226
- [JavaScript, JavaScript...](http://javascriptweblog.wordpress.com/)
2179-
- [Bocoup Weblog](http://weblog.bocoup.com/)
2227+
- [Bocoup Weblog](https://bocoup.com/weblog)
21802228
- [Adequately Good](http://www.adequatelygood.com/)
2181-
- [NCZOnline](http://www.nczonline.net/)
2229+
- [NCZOnline](https://www.nczonline.net/)
21822230
- [Perfection Kills](http://perfectionkills.com/)
21832231
- [Ben Alman](http://benalman.com/)
21842232
- [Dmitry Baranovskiy](http://dmitry.baranovskiy.com/)
21852233
- [Dustin Diaz](http://dustindiaz.com/)
2186-
- [nettuts](http://net.tutsplus.com/?s=javascript)
2234+
- [nettuts](http://code.tutsplus.com/?s=javascript)
21872235
21882236
**Podcasts**
21892237
2190-
- [JavaScript Jabber](http://devchat.tv/js-jabber/)
2238+
- [JavaScript Jabber](https://devchat.tv/js-jabber/)
21912239
21922240
21932241
**[⬆ back to top](#table-of-contents)**
@@ -2203,7 +2251,7 @@ Other Style Guides (from Airbnb)
22032251
- **Avalara**: [avalara/javascript](https://github.com/avalara/javascript)
22042252
- **Billabong**: [billabong/javascript](https://github.com/billabong/javascript)
22052253
- **Blendle**: [blendle/javascript](https://github.com/blendle/javascript)
2206-
- **ComparaOnline**: [comparaonline/javascript](https://github.com/comparaonline/javascript)
2254+
- **ComparaOnline**: [comparaonline/javascript](https://github.com/comparaonline/javascript-style-guide)
22072255
- **Compass Learning**: [compasslearning/javascript-style-guide](https://github.com/compasslearning/javascript-style-guide)
22082256
- **DailyMotion**: [dailymotion/javascript](https://github.com/dailymotion/javascript)
22092257
- **Digitpaint** [digitpaint/javascript](https://github.com/digitpaint/javascript)
@@ -2216,15 +2264,15 @@ Other Style Guides (from Airbnb)
22162264
- **General Electric**: [GeneralElectric/javascript](https://github.com/GeneralElectric/javascript)
22172265
- **GoodData**: [gooddata/gdc-js-style](https://github.com/gooddata/gdc-js-style)
22182266
- **Grooveshark**: [grooveshark/javascript](https://github.com/grooveshark/javascript)
2219-
- **How About We**: [howaboutwe/javascript](https://github.com/howaboutwe/javascript)
2267+
- **How About We**: [howaboutwe/javascript](https://github.com/howaboutwe/javascript-style-guide)
22202268
- **Huballin**: [huballin/javascript](https://github.com/huballin/javascript)
22212269
- **HubSpot**: [HubSpot/javascript](https://github.com/HubSpot/javascript)
22222270
- **Hyper**: [hyperoslo/javascript-playbook](https://github.com/hyperoslo/javascript-playbook/blob/master/style.md)
22232271
- **InfoJobs**: [InfoJobs/JavaScript-Style-Guide](https://github.com/InfoJobs/JavaScript-Style-Guide)
22242272
- **Intent Media**: [intentmedia/javascript](https://github.com/intentmedia/javascript)
22252273
- **Jam3**: [Jam3/Javascript-Code-Conventions](https://github.com/Jam3/Javascript-Code-Conventions)
22262274
- **JSSolutions**: [JSSolutions/javascript](https://github.com/JSSolutions/javascript)
2227-
- **Kinetica Solutions**: [kinetica/javascript](https://github.com/kinetica/javascript)
2275+
- **Kinetica Solutions**: [kinetica/javascript](https://github.com/kinetica/Javascript-style-guide)
22282276
- **Mighty Spring**: [mightyspring/javascript](https://github.com/mightyspring/javascript)
22292277
- **MinnPost**: [MinnPost/javascript](https://github.com/MinnPost/javascript)
22302278
- **MitocGroup**: [MitocGroup/javascript](https://github.com/MitocGroup/javascript)
@@ -2243,7 +2291,7 @@ Other Style Guides (from Airbnb)
22432291
- **SeekingAlpha**: [seekingalpha/javascript-style-guide](https://github.com/seekingalpha/javascript-style-guide)
22442292
- **Shutterfly**: [shutterfly/javascript](https://github.com/shutterfly/javascript)
22452293
- **Springload**: [springload/javascript](https://github.com/springload/javascript)
2246-
- **StudentSphere**: [studentsphere/javascript](https://github.com/studentsphere/javascript)
2294+
- **StudentSphere**: [studentsphere/javascript](https://github.com/studentsphere/guide-javascript)
22472295
- **Target**: [target/javascript](https://github.com/target/javascript)
22482296
- **TheLadders**: [TheLadders/javascript](https://github.com/TheLadders/javascript)
22492297
- **T4R Technology**: [T4R-Technology/javascript](https://github.com/T4R-Technology/javascript)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hubspot-style",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"description": "HubSpot's version of a mostly reasonable approach to JavaScript",
55
"scripts": {
66
"test": "echo \"Error: no test specified\" && exit 1",

packages/eslint-config-hubspot/README.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ We export three ESLint configurations for your usage.
1414
### eslint-config-hubspot
1515

1616
Our default export contains all of our ESLint rules, including EcmaScript 6+
17-
and React. It requires `eslint`, `babel-eslint`, and `eslint-plugin-react`.
17+
and React. It requires `eslint` and `eslint-plugin-react`.
1818

1919
1. `npm install --save-dev eslint-config-hubspot babel-eslint eslint-plugin-react eslint`
2020
2. add `"extends": "hubspot"` to your .eslintrc
2121

2222
### eslint-config-hubspot/base
2323

24-
Lints ES6+ but does not lint React. Requires `eslint` and `babel-eslint`.
24+
Lints ES6+ but does not lint React. Requires `eslint`.
2525

26-
1. `npm install --save-dev eslint-config-hubspot babel-eslint eslint`
26+
1. `npm install --save-dev eslint-config-hubspot eslint`
2727
2. add `"extends": "hubspot/base"` to your .eslintrc
2828

2929
### eslint-config-hubspot/legacy
@@ -49,6 +49,24 @@ You can make sure this module lints with itself using `npm run lint`.
4949

5050
## Changelog
5151

52+
### 1.0.2
53+
- enable rest params in linter, derp. (#592)
54+
- enforce rule 18.5, ensuring files end with a single newline character. (#578)
55+
56+
### 1.0.1
57+
58+
oops
59+
60+
### 1.0.0
61+
- require `eslint` `v1.0.0` or higher
62+
- removes `babel-eslint` dependency
63+
64+
### 0.1.1
65+
- remove id-length rule (#569)
66+
- enable `no-mixed-spaces-and-tabs` (#539)
67+
- enable `no-const-assign` (#560)
68+
- enable `space-before-keywords` (#554)
69+
5270
### 0.1.0
5371

5472
- switch to modular rules files courtesy the [eslint-config-default][ecd]

packages/eslint-config-hubspot/base.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ module.exports = {
33
'eslint-config-hubspot/legacy',
44
'eslint-config-hubspot/rules/es6',
55
],
6-
parser: 'babel-eslint',
76
rules: {}
87
};

packages/eslint-config-hubspot/package.json

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "eslint-config-hubspot",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"description": "HubSpot's ESLint config, following our styleguide",
55
"main": "index.js",
66
"scripts": {
77
"lint": "eslint .",
8-
"test": "babel-tape-runner ./test/test-*.js"
8+
"test": "babel-tape-runner ./test/test-*.js | faucet"
99
},
1010
"repository": {
1111
"type": "git",
@@ -31,11 +31,14 @@
3131
},
3232
"homepage": "https://github.com/HubSpot/javascript",
3333
"devDependencies": {
34-
"babel-eslint": "4.1.3",
3534
"babel-tape-runner": "1.2.0",
36-
"eslint": "1.6.0",
37-
"eslint-plugin-react": "3.5.1",
38-
"react": "0.14.0",
39-
"tape": "4.2.1"
35+
"eslint": "^1.10.2",
36+
"eslint-plugin-react": "^3.11.1",
37+
"faucet": "0.0.1",
38+
"react": "^0.13.3",
39+
"tape": "^4.2.2"
40+
},
41+
"peerDependencies": {
42+
"eslint": ">=1.0.0"
4043
}
4144
}

packages/eslint-config-hubspot/rules/es6.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ module.exports = {
1515
'objectLiteralDuplicateProperties': false,
1616
'objectLiteralShorthandMethods': true,
1717
'objectLiteralShorthandProperties': true,
18+
'restParams': true,
1819
'spread': true,
1920
'superInFunctions': true,
2021
'templateStrings': true,
21-
'jsx': true
22+
'jsx': true,
23+
'experimentalObjectRestSpread': true
2224
},
2325
'rules': {
2426
// require parens in arrow function arguments
@@ -32,7 +34,7 @@ module.exports = {
3234
// disallow modifying variables of class declarations
3335
'no-class-assign': 0,
3436
// disallow modifying variables that are declared using const
35-
'no-const-assign': 0,
37+
'no-const-assign': 2,
3638
// disallow to use this/super before super() calling in constructors.
3739
'no-this-before-super': 0,
3840
// require let or const instead of var

packages/eslint-config-hubspot/rules/react.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
module.exports = {
2-
'parser': 'babel-eslint',
32
'plugins': [
43
'react'
54
],
@@ -10,17 +9,19 @@ module.exports = {
109
// Prevent missing displayName in a React component definition
1110
'react/display-name': 0,
1211
// Enforce boolean attributes notation in JSX
13-
'react/jsx-boolean-value': 0,
12+
'react/jsx-boolean-value': 2,
1413
// Enforce or disallow spaces inside of curly braces in JSX attributes
1514
'react/jsx-curly-spacing': 0,
1615
// Prevent duplicate props in JSX
1716
'react/jsx-no-duplicate-props': 0,
1817
// Disallow undeclared variables in JSX
1918
'react/jsx-no-undef': 2,
19+
// Enforce quote style for JSX attributes
20+
'react/jsx-quotes': 0,
2021
// Enforce propTypes declarations alphabetical sorting
21-
'react/jsx-sort-prop-types': 2,
22+
'react/jsx-sort-prop-types': 0,
2223
// Enforce props alphabetical sorting
23-
'react/jsx-sort-props': 2,
24+
'react/jsx-sort-props': 0,
2425
// Prevent React to be incorrectly marked as unused
2526
'react/jsx-uses-react': 2,
2627
// Prevent variables used in JSX to be incorrectly marked as unused

0 commit comments

Comments
 (0)