From f15410515bf53bf976d74389d55083974a744068 Mon Sep 17 00:00:00 2001 From: Jason Baker Date: Wed, 18 May 2016 16:53:10 -0700 Subject: [PATCH 1/7] Sets indent/whitespace to 4 spaces --- .gitignore | 1 + README.md | 10 +++++++--- linters/.eslintrc | 5 ++++- linters/.jshintrc | 4 ++-- linters/SublimeLinter/SublimeLinter.sublime-settings | 4 ++-- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 3c3629e647..7a1537ba06 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +.idea node_modules diff --git a/README.md b/README.md index fb43bc9e25..2befa44482 100644 --- a/README.md +++ b/README.md @@ -1811,12 +1811,12 @@ Other Style Guides ## Whitespace - - [18.1](#whitespace--spaces) Use soft tabs set to 2 spaces. eslint: [`indent`](http://eslint.org/docs/rules/indent.html) jscs: [`validateIndentation`](http://jscs.info/rule/validateIndentation) + - [18.1](#whitespace--spaces) Use soft tabs set to 4 spaces. eslint: [`indent`](http://eslint.org/docs/rules/indent.html) jscs: [`validateIndentation`](http://jscs.info/rule/validateIndentation) ```javascript // bad function foo() { - ∙∙∙∙const name; + ∙∙const name; } // bad @@ -1826,7 +1826,7 @@ Other Style Guides // good function baz() { - ∙∙const name; + ∙∙∙∙const name; } ``` @@ -2940,6 +2940,10 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ## Amendments +**OpenDNS Amendments** + + - We have decided for our whitespace to be 4 spaces, but in an effort to keep this guide easily mergeable with AirBNB's guide, we have not updated the example code other than the Whitespace section. + We encourage you to fork this guide and change the rules to fit your team's style guide. Below, you may list some amendments to the style guide. This allows you to periodically update your style guide without having to deal with merge conflicts. # }; diff --git a/linters/.eslintrc b/linters/.eslintrc index 9e203a5473..f9afb14e85 100644 --- a/linters/.eslintrc +++ b/linters/.eslintrc @@ -1,5 +1,8 @@ // Use this file as a starting point for your project's .eslintrc. // Copy this file, and add rule overrides as needed. { - "extends": "airbnb" + "extends": "airbnb", + "rules": { + "indent": [2, 4] + } } diff --git a/linters/.jshintrc b/linters/.jshintrc index a7a08a349e..5f034bf534 100644 --- a/linters/.jshintrc +++ b/linters/.jshintrc @@ -28,8 +28,8 @@ // Prohibit use of == and != in favor of === and !==. "eqeqeq": true, - // Enforce tab width of 2 spaces. - "indent": 2, + // Enforce tab width of 4 spaces. + "indent": 4, // Prohibit use of a variable before it is defined. "latedef": true, diff --git a/linters/SublimeLinter/SublimeLinter.sublime-settings b/linters/SublimeLinter/SublimeLinter.sublime-settings index 259dbaff6a..0c826c3c71 100644 --- a/linters/SublimeLinter/SublimeLinter.sublime-settings +++ b/linters/SublimeLinter/SublimeLinter.sublime-settings @@ -43,8 +43,8 @@ // Suppress warnings about == null comparisons. "eqnull": true, - // Enforce tab width of 2 spaces. - "indent": 2, + // Enforce tab width of 4 spaces. + "indent": 4, // Prohibit use of a variable before it is defined. "latedef": true, From 497688653fc4b31ec4da47206bb643500890ace2 Mon Sep 17 00:00:00 2001 From: Jason Baker Date: Wed, 18 May 2016 18:12:20 -0700 Subject: [PATCH 2/7] adds some jsx rules --- linters/.eslintrc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/linters/.eslintrc b/linters/.eslintrc index f9afb14e85..4b43cc25ff 100644 --- a/linters/.eslintrc +++ b/linters/.eslintrc @@ -2,7 +2,14 @@ // Copy this file, and add rule overrides as needed. { "extends": "airbnb", + "parserOptions": { + "ecmaFeatures": { + "experimentalObjectRestSpread": true + } + }, "rules": { - "indent": [2, 4] + "indent": [2, 4], + "react/jsx-indent": [2, 4], + "react/jsx-indent-props": [2, 2] } -} +} \ No newline at end of file From 6333740419cbbef4c5932593ee39dc4203c38f4f Mon Sep 17 00:00:00 2001 From: Jason Baker Date: Wed, 18 May 2016 19:53:54 -0700 Subject: [PATCH 3/7] yes, 4 spaces --- linters/.eslintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linters/.eslintrc b/linters/.eslintrc index 4b43cc25ff..c3a50fb1bf 100644 --- a/linters/.eslintrc +++ b/linters/.eslintrc @@ -10,6 +10,6 @@ "rules": { "indent": [2, 4], "react/jsx-indent": [2, 4], - "react/jsx-indent-props": [2, 2] + "react/jsx-indent-props": [2, 4] } } \ No newline at end of file From 1639906224cddd676948407556a07a34c99b516a Mon Sep 17 00:00:00 2001 From: therippa Date: Thu, 2 Jun 2016 12:46:39 -0700 Subject: [PATCH 4/7] Set correct indenting of switch/case --- linters/.eslintrc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/linters/.eslintrc b/linters/.eslintrc index c3a50fb1bf..b281f8e967 100644 --- a/linters/.eslintrc +++ b/linters/.eslintrc @@ -8,8 +8,8 @@ } }, "rules": { - "indent": [2, 4], + "indent": [2, 4, {"SwitchCase": 1}], "react/jsx-indent": [2, 4], "react/jsx-indent-props": [2, 4] } -} \ No newline at end of file +} From 0cc8e57678642600a65749ebe4b209d70afa5945 Mon Sep 17 00:00:00 2001 From: therippa Date: Thu, 7 Jul 2016 13:23:22 -0700 Subject: [PATCH 5/7] Adjusts max-len --- linters/.eslintrc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/linters/.eslintrc b/linters/.eslintrc index b281f8e967..ffe0eb32d2 100644 --- a/linters/.eslintrc +++ b/linters/.eslintrc @@ -8,8 +8,9 @@ } }, "rules": { - "indent": [2, 4, {"SwitchCase": 1}], - "react/jsx-indent": [2, 4], - "react/jsx-indent-props": [2, 4] + "indent": ["error", 4, {"SwitchCase": 1}], + "react/jsx-indent": ["error", 4], + "react/jsx-indent-props": ["error", 4], + "max-len": ["error", 120] } } From abe673dd870aed7467bc1265335e2471d86e6aac Mon Sep 17 00:00:00 2001 From: therippa Date: Thu, 7 Jul 2016 13:25:03 -0700 Subject: [PATCH 6/7] Updates README for max-len --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2befa44482..2c1abf0af6 100644 --- a/README.md +++ b/README.md @@ -497,7 +497,7 @@ Other Style Guides ``` - - [6.2](#strings--line-length) Strings that cause the line to go over 100 characters should be written across multiple lines using string concatenation. + - [6.2](#strings--line-length) Strings that cause the line to go over 120 characters should be written across multiple lines using string concatenation. - [6.3](#strings--concat-perf) Note: If overused, long strings with concatenation could impact performance. [jsPerf](http://jsperf.com/ya-string-concat) & [Discussion](https://github.com/airbnb/javascript/issues/40). From 8f3da832e88048089f64e795fdb8bf379785fa14 Mon Sep 17 00:00:00 2001 From: Jason Baker Date: Thu, 27 Oct 2016 21:00:51 -0700 Subject: [PATCH 7/7] git pre-commit hooks and build scripts to ensure linting happens on new/staged files --- hooks/build-eslint | 34 ++++++++++++++++++++++++++++++++++ hooks/dev-eslint | 34 ++++++++++++++++++++++++++++++++++ hooks/pre-commit-eslint | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100755 hooks/build-eslint create mode 100755 hooks/dev-eslint create mode 100755 hooks/pre-commit-eslint diff --git a/hooks/build-eslint b/hooks/build-eslint new file mode 100755 index 0000000000..a231cd24ea --- /dev/null +++ b/hooks/build-eslint @@ -0,0 +1,34 @@ +#!/bin/bash +STAGED_FILES=$(git diff --name-only --diff-filter=ACM HEAD^..HEAD | grep -E ".*js\/modules.*\.jsx?") + +if [[ "$STAGED_FILES" = "" ]]; then + echo -e "\n[No Javascript to validate]\n" + exit 0 +fi + +PASS=true + +echo -e "\nValidating Javascript:\n" + +for FILE in $STAGED_FILES +do + node ./node_modules/eslint/bin/eslint.js "$FILE" + + if [[ "$?" == 0 ]]; then + echo -e "\t\033[32mESLint Passed: $FILE\033[0m" + else + echo -e "\t\033[41mESLint Failed: $FILE\033[0m" + PASS=false + fi +done + +echo -e "\nJavascript validation completed!\n" + +if ! $PASS; then + echo -e "\033[41mFAILED:\033[0m Your commit contains files that should pass ESLint but do not. Please fix the ESLint errors and try again.\n" + exit 1 +else + echo -e "\033[42mSUCCEEDED\033[0m\n" +fi + +exit $? diff --git a/hooks/dev-eslint b/hooks/dev-eslint new file mode 100755 index 0000000000..c2cbbee338 --- /dev/null +++ b/hooks/dev-eslint @@ -0,0 +1,34 @@ +#!/bin/sh +STAGED_FILES=$(git diff --name-only --diff-filter=ACM | grep -E ".*js\/modules.*\.jsx?") + +if [[ "$STAGED_FILES" = "" ]]; then + echo "\n[No Javascript to validate]\n" + exit 0 +fi + +PASS=true + +echo "\nValidating Javascript:\n" + +for FILE in $STAGED_FILES +do + node ./node_modules/eslint/bin/eslint.js "$FILE" + + if [[ "$?" == 0 ]]; then + echo "\t\033[32mESLint Passed: $FILE\033[0m" + else + echo "\t\033[41mESLint Failed: $FILE\033[0m" + PASS=false + fi +done + +echo "\nJavascript validation completed!\n" + +if ! $PASS; then + echo "\033[41mFAILED:\033[0m Your commit contains files that should pass ESLint but do not. Please fix the ESLint errors and try again.\n" + exit 1 +else + echo "\033[42mSUCCEEDED\033[0m\n" +fi + +exit $? diff --git a/hooks/pre-commit-eslint b/hooks/pre-commit-eslint new file mode 100755 index 0000000000..571a73fc3a --- /dev/null +++ b/hooks/pre-commit-eslint @@ -0,0 +1,34 @@ +#!/bin/sh +STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E ".*js\/modules.*\.jsx?") + +if [[ "$STAGED_FILES" = "" ]]; then + echo "\n[No Javascript to validate]\n" + exit 0 +fi + +PASS=true + +echo "\nValidating Javascript:\n" + +for FILE in $STAGED_FILES +do + node ./node_modules/eslint/bin/eslint.js "$FILE" + + if [[ "$?" == 0 ]]; then + echo "\t\033[32mESLint Passed: $FILE\033[0m" + else + echo "\t\033[41mESLint Failed: $FILE\033[0m" + PASS=false + fi +done + +echo "\nJavascript validation completed!\n" + +if ! $PASS; then + echo "\033[41mFAILED:\033[0m Your commit contains files that should pass ESLint but do not. Please fix the ESLint errors and try again.\n" + exit 1 +else + echo "\033[42mSUCCEEDED\033[0m\n" +fi + +exit $?