Skip to content
This repository was archived by the owner on Nov 8, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 114 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ Other Style Guides (from Airbnb)

> Why? This ensures that you can't reassign your references, which can lead to bugs and difficult to comprehend code.

eslint rules: [`prefer-const`](http://eslint.org/docs/rules/prefer-const.html), [`no-const-assign`](http://eslint.org/docs/rules/no-const-assign.html).

```javascript
// bad
var a = 1;
Expand All @@ -110,6 +112,8 @@ Other Style Guides (from Airbnb)

> Why? `let` is block-scoped rather than function-scoped like `var`.

eslint rules: [`no-var`](http://eslint.org/docs/rules/no-var.html).

```javascript
// bad
var count = 1;
Expand Down Expand Up @@ -142,6 +146,8 @@ Other Style Guides (from Airbnb)

- [3.1](#3.1) <a name='3.1'></a> Use the literal syntax for object creation.

eslint rules: [`no-new-object`](http://eslint.org/docs/rules/no-new-object.html).

```javascript
// bad
const item = new Object();
Expand Down Expand Up @@ -214,6 +220,8 @@ Other Style Guides (from Airbnb)
<a name="es6-object-shorthand"></a>
- [3.5](#3.5) <a name='3.5'></a> Use object method shorthand.

eslint rules: [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html).

```javascript
// bad
const atom = {
Expand All @@ -239,6 +247,8 @@ Other Style Guides (from Airbnb)

> Why? It is shorter to write and descriptive.

eslint rules: [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html).

```javascript
const lukeSkywalker = 'Luke Skywalker';

Expand Down Expand Up @@ -288,6 +298,8 @@ Other Style Guides (from Airbnb)

- [4.1](#4.1) <a name='4.1'></a> Use the literal syntax for array creation.

eslint rules: [`no-array-constructor`](http://eslint.org/docs/rules/no-array-constructor.html).

```javascript
// bad
const items = new Array();
Expand Down Expand Up @@ -404,6 +416,8 @@ Other Style Guides (from Airbnb)

- [6.1](#6.1) <a name='6.1'></a> Use single quotes `''` for strings.

eslint rules: [`quotes`](http://eslint.org/docs/rules/quotes.html).

```javascript
// bad
const name = "Capt. Janeway";
Expand Down Expand Up @@ -436,6 +450,8 @@ Other Style Guides (from Airbnb)

> Why? Template strings give you a readable, concise syntax with proper newlines and string interpolation features.

eslint rules: [`prefer-template`](http://eslint.org/docs/rules/prefer-template.html).

```javascript
// bad
function sayHi(name) {
Expand Down Expand Up @@ -613,6 +629,8 @@ Other Style Guides (from Airbnb)

> Why not? If you have a fairly complicated function, you might move that logic out into its own function declaration.

eslint rules: [`prefer-arrow-callback`](http://eslint.org/docs/rules/prefer-arrow-callback.html), [`arrow-spacing`](http://eslint.org/docs/rules/arrow-spacing.html).

```javascript
// bad
[1, 2, 3].map(function (x) {
Expand All @@ -633,6 +651,8 @@ Other Style Guides (from Airbnb)

> Why not? If you plan on returning an object.

eslint rules: [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens.html), [`arrow-body-style`](http://eslint.org/docs/rules/arrow-body-style.html).

```javascript
// good
[1, 2, 3].map(number => `A string containing the ${number}.`);
Expand Down Expand Up @@ -673,6 +693,8 @@ Other Style Guides (from Airbnb)

> Why? Less visual clutter.

eslint rules: [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens.html).

```js
// good
[1, 2, 3].map(x => x * x);
Expand Down Expand Up @@ -851,6 +873,8 @@ Other Style Guides (from Airbnb)

> Why? This enforces our immutable rule. Dealing with pure functions that return values is easier to reason about than side-effects.

eslint rules: [`no-iterator`](http://eslint.org/docs/rules/no-iterator.html).

```javascript
const numbers = [1, 2, 3, 4, 5];

Expand Down Expand Up @@ -883,6 +907,8 @@ Other Style Guides (from Airbnb)

- [12.1](#12.1) <a name='12.1'></a> Use dot notation when accessing properties.

eslint rules: [`dot-notation`](http://eslint.org/docs/rules/dot-notation.html).

```javascript
const luke = {
jedi: true,
Expand Down Expand Up @@ -930,6 +956,8 @@ Other Style Guides (from Airbnb)

> Why? It's easier to add new variable declarations this way, and you never have to worry about swapping out a `;` for a `,` or introducing punctuation-only diffs.

eslint rules: [`one-var`](http://eslint.org/docs/rules/one-var.html).

```javascript
// bad
const items = getItems(),
Expand Down Expand Up @@ -1124,12 +1152,14 @@ Other Style Guides (from Airbnb)
- [15.1](#15.1) <a name='15.1'></a> Use `===` and `!==` over `==` and `!=`.
- [15.2](#15.2) <a name='15.2'></a> Conditional statements such as the `if` statement evaluate their expression using coercion with the `ToBoolean` abstract method and always follow these simple rules:

+ **Objects** evaluate to **true**
+ **Undefined** evaluates to **false**
+ **Null** evaluates to **false**
+ **Booleans** evaluate to **the value of the boolean**
+ **Numbers** evaluate to **false** if **+0, -0, or NaN**, otherwise **true**
+ **Strings** evaluate to **false** if an empty string `''`, otherwise **true**
eslint rules: [`eqeqeq`](http://eslint.org/docs/rules/eqeqeq.html).

+ **Objects** evaluate to **true**
+ **Undefined** evaluates to **false**
+ **Null** evaluates to **false**
+ **Booleans** evaluate to **the value of the boolean**
+ **Numbers** evaluate to **false** if **+0, -0, or NaN**, otherwise **true**
+ **Strings** evaluate to **false** if an empty string `''`, otherwise **true**

```javascript
if ([0]) {
Expand Down Expand Up @@ -1196,6 +1226,8 @@ Other Style Guides (from Airbnb)
- [16.2](#16.2) <a name='16.2'></a> If you're using multi-line blocks with `if` and `else`, put `else` on the same line as your
`if` block's closing brace.

eslint rules: [`brace-style`](http://eslint.org/docs/rules/brace-style.html).

```javascript
// bad
if (test) {
Expand Down Expand Up @@ -1326,6 +1358,8 @@ Other Style Guides (from Airbnb)

- [18.1](#18.1) <a name='18.1'></a> Use soft tabs set to 2 spaces.

eslint rules: [`indent`](http://eslint.org/docs/rules/indent.html).

```javascript
// bad
function() {
Expand All @@ -1345,6 +1379,8 @@ Other Style Guides (from Airbnb)

- [18.2](#18.2) <a name='18.2'></a> Place 1 space before the leading brace.

eslint rules: [`space-before-blocks`](http://eslint.org/docs/rules/space-before-blocks.html).

```javascript
// bad
function test(){
Expand All @@ -1371,6 +1407,8 @@ Other Style Guides (from Airbnb)

- [18.3](#18.3) <a name='18.3'></a> Place 1 space before the opening parenthesis in control statements (`if`, `while` etc.). Place no space before the argument list in function calls and declarations.

eslint rules: [`space-after-keywords`](http://eslint.org/docs/rules/space-after-keywords.html), [`space-before-keywords`](http://eslint.org/docs/rules/space-before-keywords.html).

```javascript
// bad
if(isJedi) {
Expand All @@ -1395,6 +1433,8 @@ Other Style Guides (from Airbnb)

- [18.4](#18.4) <a name='18.4'></a> Set off operators with spaces.

eslint rules: [`space-infix-ops`](http://eslint.org/docs/rules/space-infix-ops.html).

```javascript
// bad
const x=y+5;
Expand Down Expand Up @@ -1526,6 +1566,8 @@ Other Style Guides (from Airbnb)

- [18.8](#18.8) <a name='18.8'></a> Do not pad your blocks with blank lines.

eslint rules: [`padded-blocks`](http://eslint.org/docs/rules/padded-blocks.html).

```javascript
// bad
function bar() {
Expand Down Expand Up @@ -1556,13 +1598,66 @@ Other Style Guides (from Airbnb)
}
```

- [18.9](#18.9) <a name='18.9'></a> Do not add spaces inside parentheses.

eslint rules: [`space-in-parens`](http://eslint.org/docs/rules/space-in-parens.html).

```javascript
// bad
function bar( foo ) {
return foo;
}

// good
function bar(foo) {
return foo;
}

// bad
if ( foo ) {
console.log(foo);
}

// good
if (foo) {
console.log(foo);
}
```

- [18.10](#18.10) <a name='18.10'></a> Do not add spaces inside brackets.

eslint rules: [`array-bracket-spacing`](http://eslint.org/docs/rules/array-bracket-spacing.html).

```javascript
// bad
const foo = [ 1, 2, 3 ];
console.log(foo[ 0 ]);

// good
const foo = [1, 2, 3];
console.log(foo[0]);
```

- [18.11](#18.11) <a name='18.11'></a> Add spaces inside curly braces.

eslint rules: [`object-curly-spacing`](http://eslint.org/docs/rules/object-curly-spacing.html).

```javascript
// bad
const foo = {clark: 'kent'};

// good
const foo = { clark: 'kent' };
```

**[⬆ back to top](#table-of-contents)**

## Commas

- [19.1](#19.1) <a name='19.1'></a> Leading commas: **Nope.**

eslint rules: [`comma-style`](http://eslint.org/docs/rules/comma-style.html).

```javascript
// bad
const story = [
Expand Down Expand Up @@ -1597,6 +1692,8 @@ Other Style Guides (from Airbnb)

- [19.2](#19.2) <a name='19.2'></a> Additional trailing comma: **Yup.**

eslint rules: [`no-comma-dangle`](http://eslint.org/docs/rules/no-comma-dangle.html).

> Why? This leads to cleaner git diffs. Also, transpilers like Babel will remove the additional trailing comma in the transpiled code which means you don't have to worry about the [trailing comma problem](es5/README.md#commas) in legacy browsers.

```javascript
Expand Down Expand Up @@ -1645,6 +1742,8 @@ Other Style Guides (from Airbnb)

- [20.1](#20.1) <a name='20.1'></a> **Yup.**

eslint rules: [`semi`](http://eslint.org/docs/rules/semi.html).

```javascript
// bad
(function() {
Expand Down Expand Up @@ -1765,6 +1864,8 @@ Other Style Guides (from Airbnb)

- [22.2](#22.2) <a name='22.2'></a> Use camelCase when naming objects, functions, and instances.

eslint rules: [`camelcase`](http://eslint.org/docs/rules/camelcase.html).

```javascript
// bad
const OBJEcttsssss = {};
Expand Down Expand Up @@ -1802,6 +1903,8 @@ Other Style Guides (from Airbnb)

- [22.4](#22.4) <a name='22.4'></a> Use a leading underscore `_` when naming private properties.

eslint rules: [`no-underscore-dangle`](http://eslint.org/docs/rules/no-underscore-dangle.html).

```javascript
// bad
this.__firstName__ = 'Panda';
Expand Down Expand Up @@ -1839,6 +1942,7 @@ Other Style Guides (from Airbnb)
```

- [22.6](#22.6) <a name='22.6'></a> If your file exports a single class, your filename should be exactly the name of the class.

```javascript
// file contents
class CheckBox {
Expand Down Expand Up @@ -2250,6 +2354,7 @@ Other Style Guides (from Airbnb)
- **Apartmint**: [apartmint/javascript](https://github.com/apartmint/javascript)
- **Avalara**: [avalara/javascript](https://github.com/avalara/javascript)
- **Billabong**: [billabong/javascript](https://github.com/billabong/javascript)
- **Bisk**: [bisk/javascript](https://github.com/Bisk/javascript/)
- **Blendle**: [blendle/javascript](https://github.com/blendle/javascript)
- **ComparaOnline**: [comparaonline/javascript](https://github.com/comparaonline/javascript-style-guide)
- **Compass Learning**: [compasslearning/javascript-style-guide](https://github.com/compasslearning/javascript-style-guide)
Expand All @@ -2271,6 +2376,7 @@ Other Style Guides (from Airbnb)
- **InfoJobs**: [InfoJobs/JavaScript-Style-Guide](https://github.com/InfoJobs/JavaScript-Style-Guide)
- **Intent Media**: [intentmedia/javascript](https://github.com/intentmedia/javascript)
- **Jam3**: [Jam3/Javascript-Code-Conventions](https://github.com/Jam3/Javascript-Code-Conventions)
- **JeopardyBot**: [kesne/jeopardy-bot](https://github.com/kesne/jeopardy-bot/blob/master/STYLEGUIDE.md)
- **JSSolutions**: [JSSolutions/javascript](https://github.com/JSSolutions/javascript)
- **Kinetica Solutions**: [kinetica/javascript](https://github.com/kinetica/Javascript-style-guide)
- **Mighty Spring**: [mightyspring/javascript](https://github.com/mightyspring/javascript)
Expand All @@ -2283,9 +2389,11 @@ Other Style Guides (from Airbnb)
- **National Park Service**: [nationalparkservice/javascript](https://github.com/nationalparkservice/javascript)
- **Nimbl3**: [nimbl3/javascript](https://github.com/nimbl3/javascript)
- **Orion Health**: [orionhealth/javascript](https://github.com/orionhealth/javascript)
- **OutBoxSoft**: [OutBoxSoft/javascript](https://github.com/OutBoxSoft/javascript)
- **Peerby**: [Peerby/javascript](https://github.com/Peerby/javascript)
- **Razorfish**: [razorfish/javascript-style-guide](https://github.com/razorfish/javascript-style-guide)
- **reddit**: [reddit/styleguide/javascript](https://github.com/reddit/styleguide/tree/master/javascript)
- **React**: [/facebook/react/blob/master/CONTRIBUTING.md#style-guide](https://github.com/facebook/react/blob/master/CONTRIBUTING.md#style-guide)
- **REI**: [reidev/js-style-guide](https://github.com/reidev/js-style-guide)
- **Ripple**: [ripple/javascript-style-guide](https://github.com/ripple/javascript-style-guide)
- **SeekingAlpha**: [seekingalpha/javascript-style-guide](https://github.com/seekingalpha/javascript-style-guide)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hubspot-style",
"version": "1.0.7",
"version": "2.0.0",
"description": "HubSpot's version of a mostly reasonable approach to JavaScript",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
Expand Down
Loading