Skip to content

Commit

Permalink
Add reference to responsible rule in RULES.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua P. Colvin committed Jan 10, 2017
1 parent 3b433fc commit 153a3ff
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions RULES.md
Expand Up @@ -12,6 +12,8 @@ your code.

* **Use 2 spaces** for indentation.

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

```js
function hello (name) {
console.log('hi', name)
Expand All @@ -20,13 +22,17 @@ your code.

* **Use single quotes for strings** except to avoid escaping.

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

```js
console.log('hello there')
$("<div class='box'>")
```

* **No unused variables.**

eslint: [`no-unused-vars`](http://eslint.org/docs/rules/no-unused-vars)

```js
function myFunction () {
var result = something() // ✗ avoid
Expand All @@ -35,13 +41,17 @@ your code.

* **Add a space after keywords.**

eslint: [`keyword-spacing`](http://eslint.org/docs/rules/keyword-spacing)

```js
if (condition) { ... } // ✓ ok
if(condition) { ... } // ✗ avoid
```

* **Add a space before a function declaration's parentheses.**

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

```js
function name (arg) { ... } // ✓ ok
function name(arg) { ... } // ✗ avoid
Expand All @@ -53,6 +63,8 @@ your code.
* **Always use** `===` instead of `==`.<br>
Exception: `obj == null` is allowed to check for `null || undefined`.

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

```js
if (name === 'John') // ✓ ok
if (name == 'John') // ✗ avoid
Expand All @@ -65,6 +77,8 @@ your code.

* **Infix operators** must be spaced.

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

```js
// ✓ ok
var x = 2
Expand All @@ -79,6 +93,8 @@ your code.

* **Commas should have a space** after them.

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

```js
// ✓ ok
var list = [1, 2, 3, 4]
Expand All @@ -93,6 +109,8 @@ your code.

* **Keep else statements** on the same line as their curly braces.

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

```js
// ✓ ok
if (condition) {
Expand All @@ -114,6 +132,8 @@ your code.

* **For multi-line if statements,** use curly braces.

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

```js
// ✓ ok
if (options.quiet !== true) console.log('done')
Expand All @@ -134,6 +154,7 @@ your code.

* **Always handle the** `err` function parameter.

eslint: [`handle-callback-err`](http://eslint.org/docs/rules/handle-callback-err)
```js
// ✓ ok
run(function (err) {
Expand All @@ -152,12 +173,16 @@ your code.
* **Always prefix browser globals** with `window.`.<br>
Exceptions are: `document`, `console` and `navigator`.

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

```js
window.alert('hi') // ✓ ok
```

* **Multiple blank lines not allowed.**

eslint: [`no-multiple-empty-lines`](http://eslint.org/docs/rules/no-multiple-empty-lines)

```js
// ✓ ok
var value = 'hello world'
Expand All @@ -174,6 +199,8 @@ your code.

* **For the ternary operator** in a multi-line setting, place `?` and `:` on their own lines.

eslint: [`operator-linebreak`](http://eslint.org/docs/rules/operator-linebreak)

```js
// ✓ ok
var location = env.development ? 'localhost' : 'www.api.com'
Expand All @@ -191,6 +218,8 @@ your code.

* **For var declarations,** write each declaration in its own statement.

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

```js
// ✓ ok
var silent = true
Expand All @@ -206,6 +235,8 @@ your code.

* **Wrap conditional assignments** with additional parentheses. This makes it clear that the expression is intentionally an assignment (`=`) rather than a typo for equality (`===`).

eslint: [`no-cond-assign`](http://eslint.org/docs/rules/no-cond-assign)

```js
// ✓ ok
while ((m = text.match(expr))) {
Expand All @@ -222,13 +253,17 @@ your code.

* No semicolons. (see: [1](http://blog.izs.me/post/2353458699/an-open-letter-to-javascript-leaders-regarding), [2](http://inimino.org/%7Einimino/blog/javascript_semicolons), [3](https://www.youtube.com/watch?v=gsfbh17Ax9I))

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

```js
window.alert('hi') // ✓ ok
window.alert('hi'); // ✗ avoid
```

* Never start a line with `(`, `[`, or `` ` ``. This is the only gotcha with omitting semicolons, and standard protects you from this potential issue.

eslint: [`no-unexpected-multiline`](http://eslint.org/docs/rules/no-unexpected-multiline)

```js
// ✓ ok
;(function () {
Expand Down

0 comments on commit 153a3ff

Please sign in to comment.