From a3d1cc272626eef2806ec856f0a8fee0aea9f8ac Mon Sep 17 00:00:00 2001 From: Eric Weinstein Date: Tue, 28 Apr 2015 13:19:36 -0400 Subject: [PATCH 01/18] Use braces for _all_ blocks --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 02ecc75ee6..99fc68650f 100644 --- a/README.md +++ b/README.md @@ -619,14 +619,14 @@ ## Blocks - - Use braces with all multi-line blocks. + - Use braces with all blocks. ```javascript // bad if (test) return false; - // good + // bad if (test) return false; // good From 5ab400c7f416fec322a1b4f65e39f5e0d7cfd591 Mon Sep 17 00:00:00 2001 From: Eric Weinstein Date: Tue, 28 Apr 2015 13:24:19 -0400 Subject: [PATCH 02/18] Use JSDoc @todo for FIX ME and TODO items --- README.md | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 99fc68650f..bb717f3989 100644 --- a/README.md +++ b/README.md @@ -733,26 +733,20 @@ } ``` - - 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`. - - - Use `// FIXME:` to annotate problems. + - Prefixing your comments with `@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 `@todo -- need to figure this out` or `@todo -- need to implement`. Note the leading `@`— this is a [JSDoc](http://usejsdoc.org/) comment. ```javascript function Calculator() { - // FIXME: shouldn't use a global here + // @todo shouldn't use a global here total = 0; return this; } - ``` - - Use `// TODO:` to annotate solutions to problems. - - ```javascript function Calculator() { - // TODO: total should be configurable by an options param + // @todo total should be configurable by an options param this.total = 0; return this; From 8a9bd6f16da97de517829dbbcbd9ee25dfee2eee Mon Sep 17 00:00:00 2001 From: Eric Weinstein Date: Tue, 28 Apr 2015 13:26:11 -0400 Subject: [PATCH 03/18] Update notes around whitespace (no newline at EOF, trim trailing whitespace) --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bb717f3989..1876778142 100644 --- a/README.md +++ b/README.md @@ -837,10 +837,10 @@ var x = y + 5; ``` - - End files with a single newline character. + - End files _without_ additional whitespace (that is, do not include a trailing newline). ```javascript - // bad + // good (function(global) { // ...stuff... })(this); @@ -855,7 +855,7 @@ ``` ```javascript - // good + // bad (function(global) { // ...stuff... })(this);↵ @@ -938,6 +938,7 @@ return obj; ``` + - Trailing whitespace is an error. **Please set your editor or IDE to strip trailing whitespace on save**, or at least set it to make trailing whitespace visible so you can remove it yourself. **[⬆ back to top](#table-of-contents)** From 27222c92ce0c03a97895048eb74e33b6cc7cd36a Mon Sep 17 00:00:00 2001 From: Eric Weinstein Date: Tue, 28 Apr 2015 13:31:11 -0400 Subject: [PATCH 04/18] Update language (Airbnb -> Autopilot) --- README.md | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 1876778142..eef5b9268b 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,6 @@ -[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/airbnb/javascript?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) - -# Airbnb JavaScript Style Guide() { - -*A mostly reasonable approach to JavaScript* +# AutoPilot JavaScript Style Guide() { +*A mostly reasonable approach to JavaScript—forked from the original by [Airbnb](https://github.com/Airbnb/javascript).* ## Table of Contents @@ -35,7 +32,7 @@ 1. [In the Wild](#in-the-wild) 1. [Translation](#translation) 1. [The JavaScript Style Guide Guide](#the-javascript-style-guide-guide) - 1. [Chat With Us About Javascript](#chat-with-us-about-javascript) + 1. [Chat With Airbnb About Javascript](#chat-with-airbnb-about-javascript) 1. [Contributors](#contributors) 1. [License](#license) @@ -1542,7 +1539,6 @@ - [jQuery Find vs Context, Selector](http://jsperf.com/jquery-find-vs-context-sel/13) - [innerHTML vs textContent for script text](http://jsperf.com/innerhtml-vs-textcontent-for-script-text) - [Long String Concatenation](http://jsperf.com/ya-string-concat) - - Loading... **[⬆ back to top](#table-of-contents)** @@ -1624,7 +1620,7 @@ ## In the Wild - This is a list of organizations that are using this style guide. Send us a pull request or open an issue and we'll add you to the list. + This is a list of organizations that are using this style guide. Send Airbnb a pull request or open an issue and they'll add you to the list. - **Aan Zee**: [AanZee/javascript](https://github.com/AanZee/javascript) - **Adult Swim**: [adult-swim/javascript](https://github.com/adult-swim/javascript) @@ -1698,9 +1694,9 @@ - [Reference](https://github.com/airbnb/javascript/wiki/The-JavaScript-Style-Guide-Guide) -## Chat With Us About JavaScript +## Chat With Airbnb About JavaScript - - Find us on [gitter](https://gitter.im/airbnb/javascript). + - Find Airbnb on [gitter](https://gitter.im/airbnb/javascript). ## Contributors From d3820b59e0d1eca4ef72760705373f7b2fcdbb21 Mon Sep 17 00:00:00 2001 From: Eric Weinstein Date: Tue, 28 Apr 2015 16:19:26 -0400 Subject: [PATCH 05/18] Update @TODO section --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index eef5b9268b..51cc208c4e 100644 --- a/README.md +++ b/README.md @@ -730,12 +730,12 @@ } ``` - - Prefixing your comments with `@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 `@todo -- need to figure this out` or `@todo -- need to implement`. Note the leading `@`— this is a [JSDoc](http://usejsdoc.org/) comment. + - Prefixing your comments with `@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 `@TODO -- need to figure this out` or `@TODO -- need to implement`. Note the leading `@`— this is a [JSDoc](http://usejsdoc.org/) comment. ```javascript function Calculator() { - // @todo shouldn't use a global here + // @TODO shouldn't use a global here (pg) total = 0; return this; @@ -743,7 +743,7 @@ function Calculator() { - // @todo total should be configurable by an options param + // @TODO total should be configurable by an options param (eqw) this.total = 0; return this; From 26006ec9b0a4c28cb13c8e265b0604505b777671 Mon Sep 17 00:00:00 2001 From: Eric Weinstein Date: Tue, 28 Apr 2015 16:22:50 -0400 Subject: [PATCH 06/18] Update IIFE syntax and EOF newline --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 51cc208c4e..41b8bbe8e1 100644 --- a/README.md +++ b/README.md @@ -276,7 +276,7 @@ // immediately-invoked function expression (IIFE) (function() { console.log('Welcome to the Internet. Please follow me.'); - })(); + }()); ``` - Never declare a function in a non-function block (if, while, etc). Assign the function to a variable instead. Browsers will allow you to do it, but they all interpret it differently, which is bad news bears. @@ -834,28 +834,28 @@ var x = y + 5; ``` - - End files _without_ additional whitespace (that is, do not include a trailing newline). + - End files with a single newline character. ```javascript // good (function(global) { // ...stuff... - })(this); + }(this));↵ ``` ```javascript // bad (function(global) { // ...stuff... - })(this);↵ - ↵ + }(this)); ``` ```javascript // bad (function(global) { // ...stuff... - })(this);↵ + }(this));↵ + ↵ ``` - Use indentation when making long method chains. Use a leading dot, which @@ -1015,19 +1015,19 @@ (function() { var name = 'Skywalker' return name - })() + }()) // good (function() { var name = 'Skywalker'; return name; - })(); + }()); // good (guards against the function becoming an argument when two files with IIFEs are concatenated) ;(function() { var name = 'Skywalker'; return name; - })(); + }()); ``` [Read more](http://stackoverflow.com/a/7365214/1712802). @@ -1620,7 +1620,7 @@ ## In the Wild - This is a list of organizations that are using this style guide. Send Airbnb a pull request or open an issue and they'll add you to the list. + This is a list of organizations that are using this style guide. - **Aan Zee**: [AanZee/javascript](https://github.com/AanZee/javascript) - **Adult Swim**: [adult-swim/javascript](https://github.com/adult-swim/javascript) From 7139ddd12a54eac192487548781f20ff77654964 Mon Sep 17 00:00:00 2001 From: Eric Weinstein Date: Tue, 28 Apr 2015 16:56:56 -0400 Subject: [PATCH 07/18] Include note to sign & date comments --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 41b8bbe8e1..557cb5573c 100644 --- a/README.md +++ b/README.md @@ -730,12 +730,12 @@ } ``` - - Prefixing your comments with `@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 `@TODO -- need to figure this out` or `@TODO -- need to implement`. Note the leading `@`— this is a [JSDoc](http://usejsdoc.org/) comment. + - Prefixing your comments with `@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 `@TODO -- need to figure this out` or `@TODO -- need to implement`. Note the leading `@`— this is a [JSDoc](http://usejsdoc.org/) comment. Make sure you initial and date your comment; future developers (including future you) will thank you. ```javascript function Calculator() { - // @TODO shouldn't use a global here (pg) + // @TODO shouldn't use a global here (pg 28 Apr 2015) total = 0; return this; @@ -743,7 +743,7 @@ function Calculator() { - // @TODO total should be configurable by an options param (eqw) + // @TODO total should be configurable by an options param (eqw 28 Apr 2015) this.total = 0; return this; From cfbf7bc69dd2cb0f25d045d8cb208c65e8c6f3c4 Mon Sep 17 00:00:00 2001 From: Eric Weinstein Date: Wed, 29 Apr 2015 12:27:55 -0400 Subject: [PATCH 08/18] Configure .eslintrc for Autopilot --- linters/.eslintrc | 231 ++++++++++++++-------------------------------- 1 file changed, 70 insertions(+), 161 deletions(-) diff --git a/linters/.eslintrc b/linters/.eslintrc index 357f9d9b75..e503ca9ae3 100644 --- a/linters/.eslintrc +++ b/linters/.eslintrc @@ -1,169 +1,78 @@ { - "parser": "babel-eslint", - "env": { - "browser": true, - "node": true - }, + // ECMAScript 6 features to enable. "ecmaFeatures": { - "arrowFunctions": true, - "blockBindings": true, - "classes": true, - "defaultParams": true, - "destructuring": true, - "forOf": true, - "generators": false, - "modules": true, - "objectLiteralComputedProperties": true, - "objectLiteralDuplicateProperties": false, - "objectLiteralShorthandMethods": true, - "objectLiteralShorthandProperties": true, - "spread": true, - "superInFunctions": true, - "templateStrings": true, "jsx": true }, - "rules": { -/** - * Strict mode - */ - // babel inserts "use strict"; for us - // http://eslint.org/docs/rules/strict - "strict": [2, "never"], - -/** - * ES6 - */ - "no-var": 2, // http://eslint.org/docs/rules/no-var - -/** - * Variables - */ - "no-shadow": 2, // http://eslint.org/docs/rules/no-shadow - "no-shadow-restricted-names": 2, // http://eslint.org/docs/rules/no-shadow-restricted-names - "no-unused-vars": [2, { // http://eslint.org/docs/rules/no-unused-vars - "vars": "local", - "args": "after-used" - }], - "no-use-before-define": 2, // http://eslint.org/docs/rules/no-use-before-define -/** - * Possible errors - */ - "comma-dangle": [2, "never"], // http://eslint.org/docs/rules/comma-dangle - "no-cond-assign": [2, "always"], // http://eslint.org/docs/rules/no-cond-assign - "no-console": 1, // http://eslint.org/docs/rules/no-console - "no-debugger": 1, // http://eslint.org/docs/rules/no-debugger - "no-alert": 1, // http://eslint.org/docs/rules/no-alert - "no-constant-condition": 1, // http://eslint.org/docs/rules/no-constant-condition - "no-dupe-keys": 2, // http://eslint.org/docs/rules/no-dupe-keys - "no-duplicate-case": 2, // http://eslint.org/docs/rules/no-duplicate-case - "no-empty": 2, // http://eslint.org/docs/rules/no-empty - "no-ex-assign": 2, // http://eslint.org/docs/rules/no-ex-assign - "no-extra-boolean-cast": 0, // http://eslint.org/docs/rules/no-extra-boolean-cast - "no-extra-semi": 2, // http://eslint.org/docs/rules/no-extra-semi - "no-func-assign": 2, // http://eslint.org/docs/rules/no-func-assign - "no-inner-declarations": 2, // http://eslint.org/docs/rules/no-inner-declarations - "no-invalid-regexp": 2, // http://eslint.org/docs/rules/no-invalid-regexp - "no-irregular-whitespace": 2, // http://eslint.org/docs/rules/no-irregular-whitespace - "no-obj-calls": 2, // http://eslint.org/docs/rules/no-obj-calls - "no-reserved-keys": 2, // http://eslint.org/docs/rules/no-reserved-keys - "no-sparse-arrays": 2, // http://eslint.org/docs/rules/no-sparse-arrays - "no-unreachable": 2, // http://eslint.org/docs/rules/no-unreachable - "use-isnan": 2, // http://eslint.org/docs/rules/use-isnan - "block-scoped-var": 2, // http://eslint.org/docs/rules/block-scoped-var + // Global variables to recognize. + "env": { + "browser": true, + "jasmine": true, + "node": true + }, -/** - * Best practices - */ - "consistent-return": 2, // http://eslint.org/docs/rules/consistent-return - "curly": [2, "multi-line"], // http://eslint.org/docs/rules/curly - "default-case": 2, // http://eslint.org/docs/rules/default-case - "dot-notation": [2, { // http://eslint.org/docs/rules/dot-notation - "allowKeywords": false - }], - "eqeqeq": 2, // http://eslint.org/docs/rules/eqeqeq - "guard-for-in": 2, // http://eslint.org/docs/rules/guard-for-in - "no-caller": 2, // http://eslint.org/docs/rules/no-caller - "no-else-return": 2, // http://eslint.org/docs/rules/no-else-return - "no-eq-null": 2, // http://eslint.org/docs/rules/no-eq-null - "no-eval": 2, // http://eslint.org/docs/rules/no-eval - "no-extend-native": 2, // http://eslint.org/docs/rules/no-extend-native - "no-extra-bind": 2, // http://eslint.org/docs/rules/no-extra-bind - "no-fallthrough": 2, // http://eslint.org/docs/rules/no-fallthrough - "no-floating-decimal": 2, // http://eslint.org/docs/rules/no-floating-decimal - "no-implied-eval": 2, // http://eslint.org/docs/rules/no-implied-eval - "no-lone-blocks": 2, // http://eslint.org/docs/rules/no-lone-blocks - "no-loop-func": 2, // http://eslint.org/docs/rules/no-loop-func - "no-multi-str": 2, // http://eslint.org/docs/rules/no-multi-str - "no-native-reassign": 2, // http://eslint.org/docs/rules/no-native-reassign - "no-new": 2, // http://eslint.org/docs/rules/no-new - "no-new-func": 2, // http://eslint.org/docs/rules/no-new-func - "no-new-wrappers": 2, // http://eslint.org/docs/rules/no-new-wrappers - "no-octal": 2, // http://eslint.org/docs/rules/no-octal - "no-octal-escape": 2, // http://eslint.org/docs/rules/no-octal-escape - "no-param-reassign": 2, // http://eslint.org/docs/rules/no-param-reassign - "no-proto": 2, // http://eslint.org/docs/rules/no-proto - "no-redeclare": 2, // http://eslint.org/docs/rules/no-redeclare - "no-return-assign": 2, // http://eslint.org/docs/rules/no-return-assign - "no-script-url": 2, // http://eslint.org/docs/rules/no-script-url - "no-self-compare": 2, // http://eslint.org/docs/rules/no-self-compare - "no-sequences": 2, // http://eslint.org/docs/rules/no-sequences - "no-throw-literal": 2, // http://eslint.org/docs/rules/no-throw-literal - "no-with": 2, // http://eslint.org/docs/rules/no-with - "radix": 2, // http://eslint.org/docs/rules/radix - "vars-on-top": 2, // http://eslint.org/docs/rules/vars-on-top - "wrap-iife": [2, "any"], // http://eslint.org/docs/rules/wrap-iife - "yoda": 2, // http://eslint.org/docs/rules/yoda + // Style and correctness rules to enforce. + "rules": { + "brace-style": 2, // Enforce the One True Brace style (http://eslint.org/docs/rules/brace-style) (error). + "camelcase": 2, // Requires camelCase for variable names (error). + "comma-dangle": [2, "never"], // No dangling commas (error). + "comma-spacing": [2, { "before": false, "after": true }], // Enforce comma spacing (e.g. { foo: 1, bar: 2 }) (error). + "comma-style": [2, "last"], // Disallows leading comma (error). + "complexity": [1, 4], // Cyclomatic complexity cannot exceed 4 (warning). + "consistent-this": [2, "_this"], // Requires that aliases to `this` be named `_this` (and not, e.g., `that` or `self) (error). + "curly": 2, // Curly braces required for all blocks (error). + "default-case": 2, // All case statements must have a `default` (error). + "dot-notation": 2, // Dot notation (`object.foo`) should be used wherever possible (error). + "eol-last": 2, // Requires one newline at EOF (to make GitHub happy) (error). + "eqeqeq": 2, // Strict (`===`) equality unless checking for `null` and `undefined` (error). + "guard-for-in": 1, // Requires an `if` statement within a `for...in` (warning). + "indent": [2, 2], // Two spaces per indentation level (error). + "key-spacing": [2, { "beforeColon: false, + "afterColon: true }], // Enforces key spacing (e.g. { foo: 1, bar: 2 }) (error). + "new-cap": 2, // Requires variables following `new` to be capitalized (error). + "new-parens": 2, // Disallows omitting parentheses when invoking constructors with no arguments (error). + "no-caller": 2, // Disallows use of `arguments.caller` and `arguments.callee` (error). + "no-debugger": 1, // Disallows use of `debugger;` (warning). + "no-dupe-args": 2, // Disallows duplicate argument names (error). + "no-dupe-keys": 2, // Disallows duplicate object keys (error). + "no-duplicate-case": 2, // Disallows duplicate case labels (error). + "no-eq-null": 0, // Explicitly permits `==` to check for `undefined || null`. + "no-eval": 2, // Disallows use of `eval()` (error). + "no-implied-eval": 2, // Disallow functions that call `eval()` (error). + "no-invalid-regexp": 2, // Disallow invalid regular expressions (error). + "no-mixed-spaces-and-tabs": 2, // Disallow mixed spaces and tabs (error). + "no-multiple-empty-lines": 1, // Disallow multiple empty lines (warning). + "no-redeclare": 2, // Disallow redeclaration of variables (error). + "no-reserved-keys": 2, // Disallow use of reserved words as object keys (can cause minification to blow up) (error). + "no-self-compare": 1, // Disallow comparison to oneself (usually a typo) (warning). + "no-shadow-restricted-names": 2, // Disallow shadowing of restricted names like `arguments` (error). + "no-spaced-func": 2, // Disallows space between `function` and identifier (e.g. disallows `function foo ()`) (error). + "no-trailing-spaces": 2, // Disallows trailing whitespace (error). + "no-undef": 2, // Disallow undeclared variables unless they've already been explicitly listed as global (error). + "no-undef-init": 2, // Disallow initializing a variable to `undefined` (error). + "no-unreachable": 2, // Disallow unreachable code (error). + "no-unused-vars": 1, // Disallow declaration of variables that are never used (warning). + "no-use-before-define": 2, // Disallow use of variables before they are defined (error). + "no-with": 2, // Disallow use of `with` (error). + "one-var": [2, "always"], // Enforces one `var` per declaration (http://eslint.org/docs/rules/one-var) (error). + "operator-assignment": [2, "always"], // Enforces operator assignment where possible (e.g. `foo *= 2` instead of `foo = foo * 2`) (error). + "quotes": [2, "single"], // Always requires single quotes for strings (error). + "radix": 2, // Requires use of radix parameter in `parseInt()` (error). + "semi": [2, "always"], // Always requires semicolons (instead of depending on ASI) (error). + "semi-spacing": [2, { "before": false, "after": true }], // Enforces no spaces before semicolons and spacing after (http://eslint.org/docs/rules/semi-spacing) (error). + "sort-vars": [1, { "ignoreCase": true }], // Requires var declarations be sorted alphabetically, case-insensitive (warning). + "space-after-keywords": [2, "always"], // Requires spaces after `if`, `while`, &c (error). + "space-in-parens": [2, "never"], // No spaces inside () (e.g. function(a, b)) (error). + "space-infix-ops": 2, // Requires space around infix operators (e.g. `1 + 2` instead of `1+2`) (error). + "space-unary-ops": [2, { "words": true, "nonwords": false }] // Requires space "outside" unary ops and disallows it "inside" (http://eslint.org/docs/rules/space-unary-ops) (error). + "strict": [2, "global"], // Requires global strict mode (error). + "use-isnan": 2, // Requires `isNaN()` instead of comparison to `NaN` (error). + "valid-jsdoc": 1, // Requires valid JSDoc comments (warning). + "yoda", [2, "never"] // Disallow Yoda conditionals (http://en.wikipedia.org/wiki/Yoda_conditions) (error). + }, -/** - * Style - */ - "indent": [2, 2], // http://eslint.org/docs/rules/ - "brace-style": [2, // http://eslint.org/docs/rules/brace-style - "1tbs", { - "allowSingleLine": true - }], - "quotes": [ - 2, "single", "avoid-escape" // http://eslint.org/docs/rules/quotes - ], - "camelcase": [2, { // http://eslint.org/docs/rules/camelcase - "properties": "never" - }], - "comma-spacing": [2, { // http://eslint.org/docs/rules/comma-spacing - "before": false, - "after": true - }], - "comma-style": [2, "last"], // http://eslint.org/docs/rules/comma-style - "eol-last": 2, // http://eslint.org/docs/rules/eol-last - "func-names": 1, // http://eslint.org/docs/rules/func-names - "key-spacing": [2, { // http://eslint.org/docs/rules/key-spacing - "beforeColon": false, - "afterColon": true - }], - "new-cap": [2, { // http://eslint.org/docs/rules/new-cap - "newIsCap": true - }], - "no-multiple-empty-lines": [2, { // http://eslint.org/docs/rules/no-multiple-empty-lines - "max": 2 - }], - "no-nested-ternary": 2, // http://eslint.org/docs/rules/no-nested-ternary - "no-new-object": 2, // http://eslint.org/docs/rules/no-new-object - "no-spaced-func": 2, // http://eslint.org/docs/rules/no-spaced-func - "no-trailing-spaces": 2, // http://eslint.org/docs/rules/no-trailing-spaces - "no-wrap-func": 2, // http://eslint.org/docs/rules/no-wrap-func - "no-underscore-dangle": 0, // http://eslint.org/docs/rules/no-underscore-dangle - "one-var": [2, "never"], // http://eslint.org/docs/rules/one-var - "padded-blocks": [2, "never"], // http://eslint.org/docs/rules/padded-blocks - "semi": [2, "always"], // http://eslint.org/docs/rules/semi - "semi-spacing": [2, { // http://eslint.org/docs/rules/semi-spacing - "before": false, - "after": true - }], - "space-after-keywords": 2, // http://eslint.org/docs/rules/space-after-keywords - "space-before-blocks": 2, // http://eslint.org/docs/rules/space-before-blocks - "space-before-function-paren": [2, "never"], // http://eslint.org/docs/rules/space-before-function-paren - "space-infix-ops": 2, // http://eslint.org/docs/rules/space-infix-ops - "space-return-throw-case": 2, // http://eslint.org/docs/rules/space-return-throw-case - "spaced-line-comment": 2 // http://eslint.org/docs/rules/spaced-line-comment - } + // Plugins to include. + "plugins": [ + "react" + ] } From ea50b4b3047626add7b7ab49bf3210df65dd1551 Mon Sep 17 00:00:00 2001 From: Eric Weinstein Date: Wed, 29 Apr 2015 12:28:07 -0400 Subject: [PATCH 09/18] Remove JSHint files, since we use ESLint --- .../SublimeLinter.sublime-settings | 73 ------------------- linters/jshintrc | 59 --------------- 2 files changed, 132 deletions(-) delete mode 100644 linters/SublimeLinter/SublimeLinter.sublime-settings delete mode 100644 linters/jshintrc diff --git a/linters/SublimeLinter/SublimeLinter.sublime-settings b/linters/SublimeLinter/SublimeLinter.sublime-settings deleted file mode 100644 index 12360f3f1c..0000000000 --- a/linters/SublimeLinter/SublimeLinter.sublime-settings +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Airbnb JSHint settings for use with SublimeLinter and Sublime Text 2. - * - * 1. Install SublimeLinter at https://github.com/SublimeLinter/SublimeLinter - * 2. Open user preferences for the SublimeLinter package in Sublime Text 2 - * * For Mac OS X go to _Sublime Text 2_ > _Preferences_ > _Package Settings_ > _SublimeLinter_ > _Settings - User_ - * 3. Paste the contents of this file into your settings file - * 4. Save the settings file - * - * @version 0.3.0 - * @see https://github.com/SublimeLinter/SublimeLinter - * @see http://www.jshint.com/docs/ - */ -{ - "jshint_options": - { - /* - * ENVIRONMENTS - * ================= - */ - - // Define globals exposed by modern browsers. - "browser": true, - - // Define globals exposed by jQuery. - "jquery": true, - - // Define globals exposed by Node.js. - "node": true, - - /* - * ENFORCING OPTIONS - * ================= - */ - - // Force all variable names to use either camelCase style or UPPER_CASE - // with underscores. - "camelcase": true, - - // Prohibit use of == and != in favor of === and !==. - "eqeqeq": true, - - // Suppress warnings about == null comparisons. - "eqnull": true, - - // Enforce tab width of 2 spaces. - "indent": 2, - - // Prohibit use of a variable before it is defined. - "latedef": true, - - // Require capitalized names for constructor functions. - "newcap": true, - - // Enforce use of single quotation marks for strings. - "quotmark": "single", - - // Prohibit trailing whitespace. - "trailing": true, - - // Prohibit use of explicitly undeclared variables. - "undef": true, - - // Warn when variables are defined but never used. - "unused": true, - - // Enforce line length to 80 characters - "maxlen": 80, - - // Enforce placing 'use strict' at the top function scope - "strict": true - } -} diff --git a/linters/jshintrc b/linters/jshintrc deleted file mode 100644 index cc6e398b40..0000000000 --- a/linters/jshintrc +++ /dev/null @@ -1,59 +0,0 @@ -{ - /* - * ENVIRONMENTS - * ================= - */ - - // Define globals exposed by modern browsers. - "browser": true, - - // Define globals exposed by jQuery. - "jquery": true, - - // Define globals exposed by Node.js. - "node": true, - - /* - * ENFORCING OPTIONS - * ================= - */ - - // Force all variable names to use either camelCase style or UPPER_CASE - // with underscores. - "camelcase": true, - - // Prohibit use of == and != in favor of === and !==. - "eqeqeq": true, - - // Enforce tab width of 2 spaces. - "indent": 2, - - // Prohibit use of a variable before it is defined. - "latedef": true, - - // Enforce line length to 80 characters - "maxlen": 80, - - // Require capitalized names for constructor functions. - "newcap": true, - - // Enforce use of single quotation marks for strings. - "quotmark": "single", - - // Enforce placing 'use strict' at the top function scope - "strict": true, - - // Prohibit use of explicitly undeclared variables. - "undef": true, - - // Warn when variables are defined but never used. - "unused": true, - - /* - * RELAXING OPTIONS - * ================= - */ - - // Suppress warnings about == null comparisons. - "eqnull": true -} From 214c4a584a80f88f86c134431f108357e19e6e65 Mon Sep 17 00:00:00 2001 From: Eric Weinstein Date: Thu, 30 Apr 2015 10:08:54 -0400 Subject: [PATCH 10/18] Update .eslintrc as per discussion with Phil --- linters/.eslintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linters/.eslintrc b/linters/.eslintrc index e503ca9ae3..f607eb11da 100644 --- a/linters/.eslintrc +++ b/linters/.eslintrc @@ -46,7 +46,6 @@ "no-reserved-keys": 2, // Disallow use of reserved words as object keys (can cause minification to blow up) (error). "no-self-compare": 1, // Disallow comparison to oneself (usually a typo) (warning). "no-shadow-restricted-names": 2, // Disallow shadowing of restricted names like `arguments` (error). - "no-spaced-func": 2, // Disallows space between `function` and identifier (e.g. disallows `function foo ()`) (error). "no-trailing-spaces": 2, // Disallows trailing whitespace (error). "no-undef": 2, // Disallow undeclared variables unless they've already been explicitly listed as global (error). "no-undef-init": 2, // Disallow initializing a variable to `undefined` (error). @@ -62,6 +61,7 @@ "semi-spacing": [2, { "before": false, "after": true }], // Enforces no spaces before semicolons and spacing after (http://eslint.org/docs/rules/semi-spacing) (error). "sort-vars": [1, { "ignoreCase": true }], // Requires var declarations be sorted alphabetically, case-insensitive (warning). "space-after-keywords": [2, "always"], // Requires spaces after `if`, `while`, &c (error). + "space-before-function-paren": [2, "always"], // Requires a space between `function` and the following `()` (error). "space-in-parens": [2, "never"], // No spaces inside () (e.g. function(a, b)) (error). "space-infix-ops": 2, // Requires space around infix operators (e.g. `1 + 2` instead of `1+2`) (error). "space-unary-ops": [2, { "words": true, "nonwords": false }] // Requires space "outside" unary ops and disallows it "inside" (http://eslint.org/docs/rules/space-unary-ops) (error). From d7cb7d2fc60ee765a4102c1696f245e96949557f Mon Sep 17 00:00:00 2001 From: Eric Weinstein Date: Thu, 30 Apr 2015 10:44:28 -0400 Subject: [PATCH 11/18] Add guide for editor/IDE integration --- linters.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 linters.md diff --git a/linters.md b/linters.md new file mode 100644 index 0000000000..a51423615c --- /dev/null +++ b/linters.md @@ -0,0 +1,46 @@ +Using ESLint with Your Editor +============================= + +Linting works best when automated; below are instructions for integrating ESLint with your editor/IDE of choice. If yours isn't listed, please make a PR to add it! You can also check out ESLint's guide to editor integration [here](http://eslint.org/docs/user-guide/integrations.html). + +## Contents +* [Atom](#atom) +* [Emacs](#emacs) +* [Sublime](#sublime) +* [Vim](#vim) + +## Atom +[linter-eslint](https://atom.io/packages/linter-eslint) can be installed via `$ npm install linter-eslint`. + +[⬆ back to top](#contents) + +## Emacs +[Flycheck](https://github.com/flycheck/flycheck) is probably your best bet. [This tutorial](http://codewinds.com/blog/2015-04-02-emacs-flycheck-eslint-jsx.html) walks you through installation and configuration for ESLint, including great information on Babel.io and React/JSX integration. + +[⬆ back to top](#contents) + +## SublimeText +[SublimeLinter-eslint](https://github.com/roadhump/SublimeLinter-eslint) is maintained and seems to work well (requires [SublimeLinter 3](http://sublimelinter.readthedocs.org/en/latest/)). + +[⬆ back to top](#contents) + +## Vim +[Syntastic](https://github.com/scrooloose/syntastic) is your best bet. Install it via [Pathogen](https://github.com/tpope/vim-pathogen) and ensure the following are in your `.vimrc`: + +```vimscript +" Use Pathogen +execute pathogen#infect() + +" Settings for Syntastic (https://github.com/scrooloose/syntastic) +set statusline+=%#warningmsg# +set statusline+=%{SyntasticStatuslineFlag()} +set statusline+=%* + +let g:syntastic_always_populate_loc_list = 1 +let g:syntastic_auto_loc_list = 1 +let g:syntastic_check_on_open = 1 +let g:syntastic_check_on_wq = 0 +let g:syntastic_javascript_checkers = ['eslint'] +``` + +[⬆ back to top](#contents) From 9d1aacf0e8e2163157df4ded5b8cce9a1c24d7ee Mon Sep 17 00:00:00 2001 From: Eric Weinstein Date: Fri, 1 May 2015 16:37:25 -0400 Subject: [PATCH 12/18] Allow multiple empty lines --- linters/.eslintrc | 1 - 1 file changed, 1 deletion(-) diff --git a/linters/.eslintrc b/linters/.eslintrc index f607eb11da..153ccf4f28 100644 --- a/linters/.eslintrc +++ b/linters/.eslintrc @@ -41,7 +41,6 @@ "no-implied-eval": 2, // Disallow functions that call `eval()` (error). "no-invalid-regexp": 2, // Disallow invalid regular expressions (error). "no-mixed-spaces-and-tabs": 2, // Disallow mixed spaces and tabs (error). - "no-multiple-empty-lines": 1, // Disallow multiple empty lines (warning). "no-redeclare": 2, // Disallow redeclaration of variables (error). "no-reserved-keys": 2, // Disallow use of reserved words as object keys (can cause minification to blow up) (error). "no-self-compare": 1, // Disallow comparison to oneself (usually a typo) (warning). From 98a7759458e7069fd975773d141e8b5c2ad1a516 Mon Sep 17 00:00:00 2001 From: Eric Weinstein Date: Fri, 1 May 2015 16:42:05 -0400 Subject: [PATCH 13/18] Fix one-var error --- linters/.eslintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linters/.eslintrc b/linters/.eslintrc index 153ccf4f28..4956031445 100644 --- a/linters/.eslintrc +++ b/linters/.eslintrc @@ -52,7 +52,7 @@ "no-unused-vars": 1, // Disallow declaration of variables that are never used (warning). "no-use-before-define": 2, // Disallow use of variables before they are defined (error). "no-with": 2, // Disallow use of `with` (error). - "one-var": [2, "always"], // Enforces one `var` per declaration (http://eslint.org/docs/rules/one-var) (error). + "one-var": [2, "never"], // Enforces separate `var` for each declaration (http://eslint.org/docs/rules/one-var) (error). "operator-assignment": [2, "always"], // Enforces operator assignment where possible (e.g. `foo *= 2` instead of `foo = foo * 2`) (error). "quotes": [2, "single"], // Always requires single quotes for strings (error). "radix": 2, // Requires use of radix parameter in `parseInt()` (error). From 7e3c0912e43a92b2748d83c2d76d67ef407a3ee7 Mon Sep 17 00:00:00 2001 From: Phil Gold Date: Tue, 5 May 2015 18:27:11 -0400 Subject: [PATCH 14/18] Fixing json syntax errors; allowing dangling underscore; fine-tuning function space rule --- linters/.eslintrc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/linters/.eslintrc b/linters/.eslintrc index 4956031445..3037a1598b 100644 --- a/linters/.eslintrc +++ b/linters/.eslintrc @@ -27,8 +27,8 @@ "eqeqeq": 2, // Strict (`===`) equality unless checking for `null` and `undefined` (error). "guard-for-in": 1, // Requires an `if` statement within a `for...in` (warning). "indent": [2, 2], // Two spaces per indentation level (error). - "key-spacing": [2, { "beforeColon: false, - "afterColon: true }], // Enforces key spacing (e.g. { foo: 1, bar: 2 }) (error). + "key-spacing": [2, { "beforeColon": false, + "afterColon": true }], // Enforces key spacing (e.g. { foo: 1, bar: 2 }) (error). "new-cap": 2, // Requires variables following `new` to be capitalized (error). "new-parens": 2, // Disallows omitting parentheses when invoking constructors with no arguments (error). "no-caller": 2, // Disallows use of `arguments.caller` and `arguments.callee` (error). @@ -48,6 +48,7 @@ "no-trailing-spaces": 2, // Disallows trailing whitespace (error). "no-undef": 2, // Disallow undeclared variables unless they've already been explicitly listed as global (error). "no-undef-init": 2, // Disallow initializing a variable to `undefined` (error). + "no-underscore-dangle": 0, "no-unreachable": 2, // Disallow unreachable code (error). "no-unused-vars": 1, // Disallow declaration of variables that are never used (warning). "no-use-before-define": 2, // Disallow use of variables before they are defined (error). @@ -60,14 +61,14 @@ "semi-spacing": [2, { "before": false, "after": true }], // Enforces no spaces before semicolons and spacing after (http://eslint.org/docs/rules/semi-spacing) (error). "sort-vars": [1, { "ignoreCase": true }], // Requires var declarations be sorted alphabetically, case-insensitive (warning). "space-after-keywords": [2, "always"], // Requires spaces after `if`, `while`, &c (error). - "space-before-function-paren": [2, "always"], // Requires a space between `function` and the following `()` (error). - "space-in-parens": [2, "never"], // No spaces inside () (e.g. function(a, b)) (error). + "space-before-function-paren": [2, {"anonymous": "always", "named": "never"}], // Requires a space between `function` and the following `()` (error). + "space-in-parens": [2, "never"], // No spaces inside () (e.g. function (a, b)) (error). "space-infix-ops": 2, // Requires space around infix operators (e.g. `1 + 2` instead of `1+2`) (error). - "space-unary-ops": [2, { "words": true, "nonwords": false }] // Requires space "outside" unary ops and disallows it "inside" (http://eslint.org/docs/rules/space-unary-ops) (error). + "space-unary-ops": [2, { "words": true, "nonwords": false }],// Requires space "outside" unary ops and disallows it "inside" (http://eslint.org/docs/rules/space-unary-ops) (error). "strict": [2, "global"], // Requires global strict mode (error). "use-isnan": 2, // Requires `isNaN()` instead of comparison to `NaN` (error). "valid-jsdoc": 1, // Requires valid JSDoc comments (warning). - "yoda", [2, "never"] // Disallow Yoda conditionals (http://en.wikipedia.org/wiki/Yoda_conditions) (error). + "yoda": [2, "never", { "exceptRange": false }] // Disallow Yoda conditionals (http://en.wikipedia.org/wiki/Yoda_conditions) (error). }, // Plugins to include. From 19704686b5efa9de5ced845f5605973193f5ad96 Mon Sep 17 00:00:00 2001 From: Eric Weinstein Date: Wed, 6 May 2015 13:54:10 -0400 Subject: [PATCH 15/18] Update alignment in .eslintrc --- linters/.eslintrc | 107 +++++++++++++++++++++++----------------------- 1 file changed, 54 insertions(+), 53 deletions(-) diff --git a/linters/.eslintrc b/linters/.eslintrc index 3037a1598b..9fb434c536 100644 --- a/linters/.eslintrc +++ b/linters/.eslintrc @@ -13,62 +13,63 @@ // Style and correctness rules to enforce. "rules": { - "brace-style": 2, // Enforce the One True Brace style (http://eslint.org/docs/rules/brace-style) (error). - "camelcase": 2, // Requires camelCase for variable names (error). - "comma-dangle": [2, "never"], // No dangling commas (error). - "comma-spacing": [2, { "before": false, "after": true }], // Enforce comma spacing (e.g. { foo: 1, bar: 2 }) (error). - "comma-style": [2, "last"], // Disallows leading comma (error). - "complexity": [1, 4], // Cyclomatic complexity cannot exceed 4 (warning). - "consistent-this": [2, "_this"], // Requires that aliases to `this` be named `_this` (and not, e.g., `that` or `self) (error). - "curly": 2, // Curly braces required for all blocks (error). - "default-case": 2, // All case statements must have a `default` (error). - "dot-notation": 2, // Dot notation (`object.foo`) should be used wherever possible (error). - "eol-last": 2, // Requires one newline at EOF (to make GitHub happy) (error). - "eqeqeq": 2, // Strict (`===`) equality unless checking for `null` and `undefined` (error). - "guard-for-in": 1, // Requires an `if` statement within a `for...in` (warning). - "indent": [2, 2], // Two spaces per indentation level (error). + "brace-style": 2, // Enforce the One True Brace style (http://eslint.org/docs/rules/brace-style) (error). + "camelcase": 2, // Requires camelCase for variable names (error). + "comma-dangle": [2, "never"], // No dangling commas (error). + "comma-spacing": [2, { "before": false, "after": true }], // Enforce comma spacing (e.g. { foo: 1, bar: 2 }) (error). + "comma-style": [2, "last"], // Disallows leading comma (error). + "complexity": [1, 4], // Cyclomatic complexity cannot exceed 4 (warning). + "consistent-this": [2, "_this"], // Requires that aliases to `this` be named `_this` (and not, e.g., `that` or `self) (error). + "curly": 2, // Curly braces required for all blocks (error). + "default-case": 2, // All case statements must have a `default` (error). + "dot-notation": 2, // Dot notation (`object.foo`) should be used wherever possible (error). + "eol-last": 2, // Requires one newline at EOF (to make GitHub happy) (error). + "eqeqeq": 2, // Strict (`===`) equality unless checking for `null` and `undefined` (error). + "guard-for-in": 1, // Requires an `if` statement within a `for...in` (warning). + "indent": [2, 2], // Two spaces per indentation level (error). "key-spacing": [2, { "beforeColon": false, "afterColon": true }], // Enforces key spacing (e.g. { foo: 1, bar: 2 }) (error). - "new-cap": 2, // Requires variables following `new` to be capitalized (error). - "new-parens": 2, // Disallows omitting parentheses when invoking constructors with no arguments (error). - "no-caller": 2, // Disallows use of `arguments.caller` and `arguments.callee` (error). - "no-debugger": 1, // Disallows use of `debugger;` (warning). - "no-dupe-args": 2, // Disallows duplicate argument names (error). - "no-dupe-keys": 2, // Disallows duplicate object keys (error). - "no-duplicate-case": 2, // Disallows duplicate case labels (error). - "no-eq-null": 0, // Explicitly permits `==` to check for `undefined || null`. - "no-eval": 2, // Disallows use of `eval()` (error). - "no-implied-eval": 2, // Disallow functions that call `eval()` (error). - "no-invalid-regexp": 2, // Disallow invalid regular expressions (error). - "no-mixed-spaces-and-tabs": 2, // Disallow mixed spaces and tabs (error). - "no-redeclare": 2, // Disallow redeclaration of variables (error). - "no-reserved-keys": 2, // Disallow use of reserved words as object keys (can cause minification to blow up) (error). - "no-self-compare": 1, // Disallow comparison to oneself (usually a typo) (warning). - "no-shadow-restricted-names": 2, // Disallow shadowing of restricted names like `arguments` (error). - "no-trailing-spaces": 2, // Disallows trailing whitespace (error). - "no-undef": 2, // Disallow undeclared variables unless they've already been explicitly listed as global (error). - "no-undef-init": 2, // Disallow initializing a variable to `undefined` (error). + "new-cap": 2, // Requires variables following `new` to be capitalized (error). + "new-parens": 2, // Disallows omitting parentheses when invoking constructors with no arguments (error). + "no-caller": 2, // Disallows use of `arguments.caller` and `arguments.callee` (error). + "no-debugger": 1, // Disallows use of `debugger;` (warning). + "no-dupe-args": 2, // Disallows duplicate argument names (error). + "no-dupe-keys": 2, // Disallows duplicate object keys (error). + "no-duplicate-case": 2, // Disallows duplicate case labels (error). + "no-eq-null": 0, // Explicitly permits `==` to check for `undefined || null`. + "no-eval": 2, // Disallows use of `eval()` (error). + "no-implied-eval": 2, // Disallow functions that call `eval()` (error). + "no-invalid-regexp": 2, // Disallow invalid regular expressions (error). + "no-mixed-spaces-and-tabs": 2, // Disallow mixed spaces and tabs (error). + "no-redeclare": 2, // Disallow redeclaration of variables (error). + "no-reserved-keys": 2, // Disallow use of reserved words as object keys (can cause minification to blow up) (error). + "no-self-compare": 1, // Disallow comparison to oneself (usually a typo) (warning). + "no-shadow-restricted-names": 2, // Disallow shadowing of restricted names like `arguments` (error). + "no-trailing-spaces": 2, // Disallows trailing whitespace (error). + "no-undef": 2, // Disallow undeclared variables unless they've already been explicitly listed as global (error). + "no-undef-init": 2, // Disallow initializing a variable to `undefined` (error). "no-underscore-dangle": 0, - "no-unreachable": 2, // Disallow unreachable code (error). - "no-unused-vars": 1, // Disallow declaration of variables that are never used (warning). - "no-use-before-define": 2, // Disallow use of variables before they are defined (error). - "no-with": 2, // Disallow use of `with` (error). - "one-var": [2, "never"], // Enforces separate `var` for each declaration (http://eslint.org/docs/rules/one-var) (error). - "operator-assignment": [2, "always"], // Enforces operator assignment where possible (e.g. `foo *= 2` instead of `foo = foo * 2`) (error). - "quotes": [2, "single"], // Always requires single quotes for strings (error). - "radix": 2, // Requires use of radix parameter in `parseInt()` (error). - "semi": [2, "always"], // Always requires semicolons (instead of depending on ASI) (error). - "semi-spacing": [2, { "before": false, "after": true }], // Enforces no spaces before semicolons and spacing after (http://eslint.org/docs/rules/semi-spacing) (error). - "sort-vars": [1, { "ignoreCase": true }], // Requires var declarations be sorted alphabetically, case-insensitive (warning). - "space-after-keywords": [2, "always"], // Requires spaces after `if`, `while`, &c (error). - "space-before-function-paren": [2, {"anonymous": "always", "named": "never"}], // Requires a space between `function` and the following `()` (error). - "space-in-parens": [2, "never"], // No spaces inside () (e.g. function (a, b)) (error). - "space-infix-ops": 2, // Requires space around infix operators (e.g. `1 + 2` instead of `1+2`) (error). - "space-unary-ops": [2, { "words": true, "nonwords": false }],// Requires space "outside" unary ops and disallows it "inside" (http://eslint.org/docs/rules/space-unary-ops) (error). - "strict": [2, "global"], // Requires global strict mode (error). - "use-isnan": 2, // Requires `isNaN()` instead of comparison to `NaN` (error). - "valid-jsdoc": 1, // Requires valid JSDoc comments (warning). - "yoda": [2, "never", { "exceptRange": false }] // Disallow Yoda conditionals (http://en.wikipedia.org/wiki/Yoda_conditions) (error). + "no-unreachable": 2, // Disallow unreachable code (error). + "no-unused-vars": 1, // Disallow declaration of variables that are never used (warning). + "no-use-before-define": 2, // Disallow use of variables before they are defined (error). + "no-with": 2, // Disallow use of `with` (error). + "one-var": [2, "never"], // Enforces separate `var` for each declaration (http://eslint.org/docs/rules/one-var) (error). + "operator-assignment": [2, "always"], // Enforces operator assignment where possible (e.g. `foo *= 2` instead of `foo = foo * 2`) (error). + "quotes": [2, "single"], // Always requires single quotes for strings (error). + "radix": 2, // Requires use of radix parameter in `parseInt()` (error). + "semi": [2, "always"], // Always requires semicolons (instead of depending on ASI) (error). + "semi-spacing": [2, { "before": false, "after": true }], // Enforces no spaces before semicolons and spacing after (http://eslint.org/docs/rules/semi-spacing) (error). + "sort-vars": [1, { "ignoreCase": true }], // Requires var declarations be sorted alphabetically, case-insensitive (warning). + "space-after-keywords": [2, "always"], // Requires spaces after `if`, `while`, &c (error). + "space-before-function-paren": [2, { "anonymous": "always", + "named": "never" }], // Requires a space between `function` and the following `()` (error). + "space-in-parens": [2, "never"], // No spaces inside () (e.g. function (a, b)) (error). + "space-infix-ops": 2, // Requires space around infix operators (e.g. `1 + 2` instead of `1+2`) (error). + "space-unary-ops": [2, { "words": true, "nonwords": false }], // Requires space "outside" unary ops and disallows it "inside" (http://eslint.org/docs/rules/space-unary-ops) (error). + "strict": [2, "global"], // Requires global strict mode (error). + "use-isnan": 2, // Requires `isNaN()` instead of comparison to `NaN` (error). + "valid-jsdoc": 1, // Requires valid JSDoc comments (warning). + "yoda": [2, "never", { "exceptRange": false }] // Disallow Yoda conditionals (http://en.wikipedia.org/wiki/Yoda_conditions) (error). }, // Plugins to include. From 38dc7e18d8fe19f34383a83b9ce4a186a34e1c71 Mon Sep 17 00:00:00 2001 From: Eric Weinstein Date: Thu, 7 May 2015 12:46:55 -0400 Subject: [PATCH 16/18] Add React section to the README --- README.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/README.md b/README.md index 557cb5573c..d6077a7b4d 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ 1. [Constructors](#constructors) 1. [Events](#events) 1. [Modules](#modules) + 1. [React](#react) 1. [jQuery](#jquery) 1. [ECMAScript 5 Compatibility](#ecmascript-5-compatibility) 1. [Testing](#testing) @@ -1448,6 +1449,52 @@ **[⬆ back to top](#table-of-contents)** +## React +Our React style is mostly influenced by [David Chang's style guide](https://reactjsnews.com/react-style-guide-patterns-i-like/). Exceptions are enumerated below. + + - Since `displayName` is automatically set by React when calling `React.createClass()`, there's no need to explicitly include one: + + ```javascript + // Preferred + React.createClass({ + propTypes: {}, + mixins: [], + getInitialState: function () {}, + componentWillMount: function () {}, + componentWillUnmount: function () {}, + render: function() {} + }); + + // Not preferred + React.createClass({ + displayName: '', + propTypes: {}, + mixins: [], + getInitialState: function () {}, + componentWillMount: function () {}, + componentWillUnmount: function () {}, + render: function () {} + }); + ``` + + - When it comes to conditionals, we tend to prefer `&&` to ternaries and will often use `&&` rather than breaking logic out into separate methods: + + ```javascript + renderContent: function () { + var content = +
+ {this.props.rubric && } + {this.props.hed &&
} + {this.props.dek &&
} + {this.props.date &&
{this.props.date}
} +
; + + return this.buildContent(content); + }, + ``` + +**[⬆ back to top](#table-of-contents)** + ## jQuery - Prefix jQuery object variables with a `$`. From b5f1a985f411cb9d11c49ec14ecdb3a1a9190fcf Mon Sep 17 00:00:00 2001 From: Eric Weinstein Date: Thu, 7 May 2015 17:14:03 -0400 Subject: [PATCH 17/18] Clarify displayName language and add conditional examples --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d6077a7b4d..9f8f4e3108 100644 --- a/README.md +++ b/README.md @@ -1452,7 +1452,7 @@ ## React Our React style is mostly influenced by [David Chang's style guide](https://reactjsnews.com/react-style-guide-patterns-i-like/). Exceptions are enumerated below. - - Since `displayName` is automatically set by React when calling `React.createClass()`, there's no need to explicitly include one: + - Since `displayName` is automatically set by React after calling `React.createClass()` and transpiling from JSX to JavaScript, there's no need to explicitly include one: ```javascript // Preferred @@ -1483,10 +1483,9 @@ Our React style is mostly influenced by [David Chang's style guide](https://reac renderContent: function () { var content =
- {this.props.rubric && } - {this.props.hed &&
} - {this.props.dek &&
} - {this.props.date &&
{this.props.date}
} + {this.props.foo &&
} + {this.props.isTruthy && } + {this.props.isTruthy && this.renderMyComponent()}
; return this.buildContent(content); From ed3a4bff2bd5ce2f2674a6936050b873b0bdb2b9 Mon Sep 17 00:00:00 2001 From: Court Simas Date: Tue, 5 Jan 2016 16:37:39 -0600 Subject: [PATCH 18/18] update readme to reflect original attribution --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9f8f4e3108..32ce06075d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# AutoPilot JavaScript Style Guide() { +# Conde Nast JavaScript Style Guide() { -*A mostly reasonable approach to JavaScript—forked from the original by [Airbnb](https://github.com/Airbnb/javascript).* +*A mostly reasonable approach to JavaScript—forked from Conde Nast, originally written by [Airbnb](https://github.com/Airbnb/javascript).* ## Table of Contents