diff --git a/RULES.md b/RULES.md index 16291440f..90e85cf48 100644 --- a/RULES.md +++ b/RULES.md @@ -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) @@ -20,6 +22,8 @@ your code. * **Use single quotes for strings** except to avoid escaping. + eslint: [`quotes`](http://eslint.org/docs/rules/quotes) + ```js console.log('hello there') $("
") @@ -27,6 +31,8 @@ your code. * **No unused variables.** + eslint: [`no-unused-vars`](http://eslint.org/docs/rules/no-unused-vars) + ```js function myFunction () { var result = something() // ✗ avoid @@ -35,6 +41,8 @@ your code. * **Add a space after keywords.** + eslint: [`keyword-spacing`](http://eslint.org/docs/rules/keyword-spacing) + ```js if (condition) { ... } // ✓ ok if(condition) { ... } // ✗ avoid @@ -42,6 +50,8 @@ your code. * **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 @@ -53,6 +63,8 @@ your code. * **Always use** `===` instead of `==`.
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 @@ -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 @@ -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] @@ -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) { @@ -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') @@ -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) { @@ -152,12 +173,16 @@ your code. * **Always prefix browser globals** with `window.`.
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' @@ -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' @@ -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 @@ -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))) { @@ -222,6 +253,8 @@ 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 @@ -229,6 +262,8 @@ your code. * 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 () {