Skip to content

Comments, whitespace, properties, commas, variables #2028

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
77 changes: 1 addition & 76 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1552,16 +1552,6 @@ Other Style Guides

const isJedi = getProp('jedi');
```
<a name="es2016-properties--exponentiation-operator"></a>
- [12.3](#es2016-properties--exponentiation-operator) Use exponentiation operator `**` when calculating exponentiations. eslint: [`no-restricted-properties`](https://eslint.org/docs/rules/no-restricted-properties).

```javascript
// bad
const binary = Math.pow(2, 10);

// good
const binary = 2 ** 10;
```

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

Expand Down Expand Up @@ -1698,40 +1688,6 @@ Other Style Guides
// the same applies for `const`
```

<a name="variables--unary-increment-decrement"></a><a name="13.6"></a>
- [13.6](#variables--unary-increment-decrement) Avoid using unary increments and decrements (`++`, `--`). eslint [`no-plusplus`](https://eslint.org/docs/rules/no-plusplus)

> Why? Per the eslint documentation, unary increment and decrement statements are subject to automatic semicolon insertion and can cause silent errors with incrementing or decrementing values within an application. It is also more expressive to mutate your values with statements like `num += 1` instead of `num++` or `num ++`. Disallowing unary increment and decrement statements also prevents you from pre-incrementing/pre-decrementing values unintentionally which can also cause unexpected behavior in your programs.

```javascript
// bad

const array = [1, 2, 3];
let num = 1;
num++;
--num;

let sum = 0;
let truthyCount = 0;
for (let i = 0; i < array.length; i++) {
let value = array[i];
sum += value;
if (value) {
truthyCount++;
}
}

// good

const array = [1, 2, 3];
let num = 1;
num += 1;
num -= 1;

const sum = array.reduce((a, b) => a + b, 0);
const truthyCount = array.filter(Boolean).length;
```

<a name="variables--linebreak"></a>
- [13.7](#variables--linebreak) Avoid linebreaks before or after `=` in an assignment. If your assignment violates [`max-len`](https://eslint.org/docs/rules/max-len.html), surround the value in parens. eslint [`operator-linebreak`](https://eslint.org/docs/rules/operator-linebreak.html).

Expand Down Expand Up @@ -2370,37 +2326,6 @@ Other Style Guides
}
```

<a name="comments--actionitems"></a><a name="17.3"></a>
- [18.4](#comments--actionitems) 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`.

<a name="comments--fixme"></a><a name="17.4"></a>
- [18.5](#comments--fixme) Use `// FIXME:` to annotate problems.

```javascript
class Calculator extends Abacus {
constructor() {
super();

// FIXME: shouldn’t use a global here
total = 0;
}
}
```

<a name="comments--todo"></a><a name="17.5"></a>
- [18.6](#comments--todo) Use `// TODO:` to annotate solutions to problems.

```javascript
class Calculator extends Abacus {
constructor() {
super();

// TODO: total should be configurable by an options param
this.total = 0;
}
}
```

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

## Whitespace
Expand Down Expand Up @@ -2761,7 +2686,7 @@ Other Style Guides
```

<a name="whitespace--max-len"></a><a name="18.12"></a>
- [19.13](#whitespace--max-len) Avoid having lines of code that are longer than 100 characters (including whitespace). Note: per [above](#strings--line-length), long strings are exempt from this rule, and should not be broken up. eslint: [`max-len`](https://eslint.org/docs/rules/max-len.html)
- [19.13](#whitespace--max-len) Avoid having lines of code that are longer than 120 characters (including whitespace) and comments that are longer than 80 characters. Note: per [above](#strings--line-length), long strings are exempt from this rule, and should not be broken up. eslint: [`max-len`](https://eslint.org/docs/rules/max-len.html)

> Why? This ensures readability and maintainability.

Expand Down