From 8a00e5bc869dc844cd8080a66ad71297a4e649ad Mon Sep 17 00:00:00 2001 From: Philipp Hinrichsen Date: Mon, 18 Jan 2016 13:58:06 +0100 Subject: [PATCH 01/17] Add coding guidelines with some complex examples --- coding-guidelines/coding-guidelines.md | 243 +++++++++++++++++++++++++ coding-guidelines/eslint-example.js | 55 ++++++ 2 files changed, 298 insertions(+) create mode 100644 coding-guidelines/coding-guidelines.md create mode 100644 coding-guidelines/eslint-example.js diff --git a/coding-guidelines/coding-guidelines.md b/coding-guidelines/coding-guidelines.md new file mode 100644 index 000000000..157b588cf --- /dev/null +++ b/coding-guidelines/coding-guidelines.md @@ -0,0 +1,243 @@ +# Coding Guidelines + +## Line length +One Line in JavaScript should have a maximal length of 80 characters. + +## Indentation and Line-Breaks +Rules: +- Indentation is done with 2 spaces in most cases. +- Line breaks are only done if needed, try to use the 80 character limit. +- Strings are splitted at the latest possible position. + - At the latest whitespace character. + - The second line is indented with 2 spaces. +- Object Literals are kept on one line if possible. + - If the line gets to long put each attribute on a single line. + - Multi level object literals should be splitted in to multiple lines. Each level in the object should have 2 spaces as indentation. + +Examples: +```JS +switch (a) { + case "a": + break; + case "b": + break; +} + +var a, + b, + c; + +function test() { + var a, + b, + c; +} + +test( + "A Very long string which is longer then one line, which is 80 characters " + + "in this case. This demonstrates how the second line is indented", + "Another string parameter.", + {and: "a Literal Object", as: "a parameter", type: "short"}, + { + yet: "another long parameter Object", + which: "needs to be split in multiple", + lines: 3 + } +); + +test({ + a: { + b: 10 + }, + c: 20, + d: 30, + e: 40, + f: 50, + g: 60, + h: { + i: 70 + } +}); +``` + +## Whitespace +Rules: +- No Trailing spaces should be used at the end of a line. +- No multiple Blank lines. + +## Functions +Rules: + - Function blocks should have a space before the definition. + - Function should have a space before the opening parentheses. + - Named Functions should not have a space before the opening function parentheses. + - Functions can be on a single line. + - Anonymous Functions need to have a space before the opening function parentheses. + - Arrow functions do have the same constraints + +Examples: +```JS +function test() { + return; +} + +function test() { var a = 10; return a; } + +var test = function () {var b = 10; return b;} + +var es6 = parameter => parameter(); + +var es6 = parameter => { + parameter(); + return false; +} + +var es6 = (parameter, index) => parameter(index); + +var es6 = (parameter, index) => { + parameter(index); + return false; +} +``` + +## Comments +Rules: + - Comments should be prefixed with a space sign. + - The `*` sign is a exception to the rule. + +Examples: +```JS +// Single line Comment + +//* A Exception to the space rule + +/* + Comment Block with no space +*/ + +/** + * Block Comment + */ +``` + +## If, loops, switch blocks +Rules: + - Space after the keyword + - Space before opening parentheses + - Strict equal (`===` or `!==`) + +Examples: +```JS +if (a === b) { + a(); +} + +if (true !== false) { + // Statements +} + +switch (a) { + case 1: + break; + case 2: + break; + default: + break; +} + +for (var a = 10; a !== 0; a--) { + // Statements +} +``` + +## Strings +Strings are defined with double quotes. + +## Variables and Attribute names +Variables always use camelCase names. +May have a underscore dangle. +Examples: +```JS +var camelCase = "{value}", + _camelCase = "{value}", + CamelCase = "{test}", + camelCase_ = "{test}"; +``` + +## Object Literals +Object literals should have no space after the '{' or before the '}' signs. + +Valid Example +```JS +var objectLiteral = {"key": "value", "key2": "value2"}; + +var objectLiteral = { + "key": "value", + "key2": "value2" +}; +``` + +## JSDoc +If there is a return there should be a type and description. +If there is one or multiple parameter/s there should be a name, type and description for each one. + +Example: +```JS +/** + * Description of what the function does + * + * @param {Function} a A function containing a callback. + */ +function b(a) { + a(); +} + +/** + * Description of what the function does. + * + * @param {Function} a A function containing a callback. + * @return {String} Returns a String containing "done". + */ +function test(a) { + a(); + return "done"; +} + +/** + * Description of what the function does. + * + * @param {Number} a A Number on how often the b should be called. + * @param {Function} callback A function containing a callback function. + * @return {String} Returns a String containing "done". + */ +function test(number, callback) { + var counter; + for (counter = 0; counter <= number; counter++) { + a(); + } + return "done"; +} +``` + +## JSX + +### Self contained elements +On self contained elements attributes should be indented with 2 spaces. + +Example: +```JS + +``` + +### Non self contained elements +On elements which are not self contained the indentation of attributes should be 4 spaces. And the childNodes should have a indentation of 2 spaces to the element and -2 spaces to the attributes. + +Example: +```JS + + + +``` diff --git a/coding-guidelines/eslint-example.js b/coding-guidelines/eslint-example.js new file mode 100644 index 000000000..39cc99a82 --- /dev/null +++ b/coding-guidelines/eslint-example.js @@ -0,0 +1,55 @@ +var React = require("react"); +//* test +const dialogId = + DialogActions.prompt("Please provide a scaling factor for all " + + "applications in this group.", + "1.0", { + type: "number", + min: "0" + } + ); + +const dialogId = DialogActions.prompt( + "Please provide a scaling factor for all applications in this group.", + "1.0", { + type: "number", + min: "0" + } +); + +const dialogId = DialogActions.prompt( + "Please provide a scaling factor for all applications in this group.Please " + + "provide a scaling factor for all applications in this group.Please " + + "provide a scaling factor for all applications in this group.", + "1.0", + { + type: "number", + min: "0" + } +); + +const dialogId = DialogActions.prompt("Please provide a scaling factor for " + + "all applications in this group.", "1.0", {type: "number", min: "0"}); + +function test() { + + return ( +
  • + Hello World! +
  • + ); +} + +test( + "A Very long string which is longer then one line, which is 80 characters " + + "in this case. This demonstrates how the second line is indented", + "Another string parameter", + {and: "a Literal Object", as: "a parameter", type: "short"}, + { + yet: "another long parameter Object", + which: "needs to be split in multiple", + lines: 3 + } +); + +test({a: {b: 10}, c: 20, d: 30, e: 40, f:50, g: 60, h: {i: 70}}); From 9629aad917190175599bc2ea5fa3fe6be389e919 Mon Sep 17 00:00:00 2001 From: Philipp Hinrichsen Date: Tue, 19 Jan 2016 13:20:23 +0100 Subject: [PATCH 02/17] Add `one-var` enforce rule to eslint config file --- .eslintrc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.eslintrc b/.eslintrc index 5e9491d3f..02bfbeded 100644 --- a/.eslintrc +++ b/.eslintrc @@ -30,9 +30,10 @@ "strict": [2, "never"], // <-- fix "no-mixed-spaces-and-tabs": [2], "no-trailing-spaces": [2, { "skipBlankLines": false }], - "no-underscore-dangle": 0, + "no-underscore-dangle": 2, "no-multiple-empty-lines": [2, {"max": 1}], "no-empty": [2], + "one-var": [2, "never"], "object-curly-spacing": [2, "never"], "space-after-keywords": [2, "always"], "space-before-blocks": [2, "always"], From e5e10fb1704f0a95a9e8c824237dfa5b455102ef Mon Sep 17 00:00:00 2001 From: Philipp Hinrichsen Date: Tue, 19 Jan 2016 13:38:40 +0100 Subject: [PATCH 03/17] Add the `block-spacing` rule to the eslint config --- .eslintrc | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc b/.eslintrc index 02bfbeded..4ba35de3b 100644 --- a/.eslintrc +++ b/.eslintrc @@ -28,6 +28,7 @@ "indent": [2, 2, {"SwitchCase": 1, "VariableDeclarator": 1}], "camelcase": [2, {"properties": "always"}], "strict": [2, "never"], // <-- fix + "block-spacing": [2, "always"], "no-mixed-spaces-and-tabs": [2], "no-trailing-spaces": [2, { "skipBlankLines": false }], "no-underscore-dangle": 2, From 7ef2467c90b445637da3dee8c9f18d7ec153fdec Mon Sep 17 00:00:00 2001 From: Philipp Hinrichsen Date: Tue, 19 Jan 2016 13:53:39 +0100 Subject: [PATCH 04/17] Add suggestions to the document Remove typos Remove uneccessary examples add new examples --- coding-guidelines/coding-guidelines.md | 121 +++++++++++++------------ 1 file changed, 65 insertions(+), 56 deletions(-) diff --git a/coding-guidelines/coding-guidelines.md b/coding-guidelines/coding-guidelines.md index 157b588cf..b97e61a13 100644 --- a/coding-guidelines/coding-guidelines.md +++ b/coding-guidelines/coding-guidelines.md @@ -1,38 +1,36 @@ # Coding Guidelines +# General +We prefer a functional approach and try to use the abstractions over +normal control statements. Functions and code must be +self-descriptive, use JSDoc blocks only if necessary. -## Line length -One Line in JavaScript should have a maximal length of 80 characters. + +## Strings + - Strings are defined with double quotes. + - Use template strings if variables are used. + +Example: +```JS +var string = `Hello ${world}!`; +``` ## Indentation and Line-Breaks Rules: -- Indentation is done with 2 spaces in most cases. -- Line breaks are only done if needed, try to use the 80 character limit. -- Strings are splitted at the latest possible position. +- Line breaks are only done if needed. +- Strings are split at the latest possible position. - At the latest whitespace character. - The second line is indented with 2 spaces. -- Object Literals are kept on one line if possible. + ```JS + var longString = "A Very long string which is longer then one line, which is 80 characters " + + "in this case. This demonstrates how the second line is indented"; + ``` +- Object literals are kept on one line if possible. - If the line gets to long put each attribute on a single line. - - Multi level object literals should be splitted in to multiple lines. Each level in the object should have 2 spaces as indentation. + - Multi level object literals must be split in to multiple lines. + - Each level in the object must have 2 spaces as indentation. Examples: ```JS -switch (a) { - case "a": - break; - case "b": - break; -} - -var a, - b, - c; - -function test() { - var a, - b, - c; -} - test( "A Very long string which is longer then one line, which is 80 characters " + "in this case. This demonstrates how the second line is indented", @@ -60,19 +58,19 @@ test({ }); ``` -## Whitespace -Rules: -- No Trailing spaces should be used at the end of a line. -- No multiple Blank lines. - ## Functions Rules: - - Function blocks should have a space before the definition. - - Function should have a space before the opening parentheses. - - Named Functions should not have a space before the opening function parentheses. + - Function blocks must have a space before the definition. + - Function must have a space before the opening parenthesis. + - Named functions must not have a space before the opening function brackets. - Functions can be on a single line. - - Anonymous Functions need to have a space before the opening function parentheses. - - Arrow functions do have the same constraints + - If they are there must be a whitespace inside the curly brackets. + - Anonymous functions need to have a space before the opening function bracket. + - Arrow functions + - can be on a single line. + - must omit the parameter brackets if only one parameter is present. + - must omit curly brackets if only one statement is given. + - must have whitespace around the parameter definition Examples: ```JS @@ -82,7 +80,7 @@ function test() { function test() { var a = 10; return a; } -var test = function () {var b = 10; return b;} +var test = function () { var b = 10; return b; } var es6 = parameter => parameter(); @@ -101,8 +99,8 @@ var es6 = (parameter, index) => { ## Comments Rules: - - Comments should be prefixed with a space sign. - - The `*` sign is a exception to the rule. + - Comments must be prefixed with a space sign. + - The `*` sign is a exception to the rule. Examples: ```JS @@ -110,10 +108,6 @@ Examples: //* A Exception to the space rule -/* - Comment Block with no space -*/ - /** * Block Comment */ @@ -124,6 +118,7 @@ Rules: - Space after the keyword - Space before opening parentheses - Strict equal (`===` or `!==`) + - exception to this rule is null checking Examples: ```JS @@ -135,6 +130,20 @@ if (true !== false) { // Statements } +if (a == null) { + // Statements +} else { + // Statements +} + +if (true !== false) { + // Statements +} else if(false === true) { + // Statements +} else { + // Statements +} + switch (a) { case 1: break; @@ -149,22 +158,19 @@ for (var a = 10; a !== 0; a--) { } ``` -## Strings -Strings are defined with double quotes. - ## Variables and Attribute names -Variables always use camelCase names. -May have a underscore dangle. +Variable names always use camelCase names, except Constants which use UPPER_CASE. +One var, let or const per variable and line. + Examples: ```JS -var camelCase = "{value}", - _camelCase = "{value}", - CamelCase = "{test}", - camelCase_ = "{test}"; +var camelCase = "{value}"; +let CamelCase = "{value}"; +const SOME_CONSTANT = "constant value"; ``` ## Object Literals -Object literals should have no space after the '{' or before the '}' signs. +Object literals must have no space after the '{' or before the '}' signs. Valid Example ```JS @@ -172,13 +178,16 @@ var objectLiteral = {"key": "value", "key2": "value2"}; var objectLiteral = { "key": "value", - "key2": "value2" + "key2": "value2", + "key3": "value3", + "key4": "value4" }; ``` ## JSDoc -If there is a return there should be a type and description. -If there is one or multiple parameter/s there should be a name, type and description for each one. +JSDoc block should not be needed if they are needed to these rules apply: + - If there is a return there must be a type and description. + - If there is one or multiple parameter/s there must be a name, type and description for each one. Example: ```JS @@ -221,7 +230,7 @@ function test(number, callback) { ## JSX ### Self contained elements -On self contained elements attributes should be indented with 2 spaces. +On self contained elements attributes must be indented with 2 spaces. Example: ```JS @@ -231,7 +240,7 @@ Example: ``` ### Non self contained elements -On elements which are not self contained the indentation of attributes should be 4 spaces. And the childNodes should have a indentation of 2 spaces to the element and -2 spaces to the attributes. +On elements which are not self contained the indentation of attributes must be 4 spaces. And the childNodes must have a indentation of 2 spaces to the element and -2 spaces to the attributes. Example: ```JS From d89365586b2f4635c0751596ba34660f1916455a Mon Sep 17 00:00:00 2001 From: Philipp Hinrichsen Date: Tue, 19 Jan 2016 14:28:26 +0100 Subject: [PATCH 05/17] Add general info section at the top --- coding-guidelines/coding-guidelines.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/coding-guidelines/coding-guidelines.md b/coding-guidelines/coding-guidelines.md index b97e61a13..a5a11c14f 100644 --- a/coding-guidelines/coding-guidelines.md +++ b/coding-guidelines/coding-guidelines.md @@ -1,10 +1,16 @@ # Coding Guidelines # General +We are using the eslintrc to lint our code. All basic rules are defined there, some important rules are: + - Max line length is 80 characters. + - Indentation is 2 spaces. + - No multiple empty lines. + We prefer a functional approach and try to use the abstractions over normal control statements. Functions and code must be self-descriptive, use JSDoc blocks only if necessary. + ## Strings - Strings are defined with double quotes. - Use template strings if variables are used. From 040089ee5ea52839073360b86a653d4b0f282f83 Mon Sep 17 00:00:00 2001 From: Philipp Hinrichsen Date: Tue, 19 Jan 2016 14:30:22 +0100 Subject: [PATCH 06/17] Change new eslint settings to warnings This change is so that the build does not break until all new rules are refactored --- .eslintrc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.eslintrc b/.eslintrc index 4ba35de3b..c313b37d2 100644 --- a/.eslintrc +++ b/.eslintrc @@ -28,13 +28,13 @@ "indent": [2, 2, {"SwitchCase": 1, "VariableDeclarator": 1}], "camelcase": [2, {"properties": "always"}], "strict": [2, "never"], // <-- fix - "block-spacing": [2, "always"], + "block-spacing": [1, "always"], "no-mixed-spaces-and-tabs": [2], "no-trailing-spaces": [2, { "skipBlankLines": false }], - "no-underscore-dangle": 2, + "no-underscore-dangle": 1, "no-multiple-empty-lines": [2, {"max": 1}], "no-empty": [2], - "one-var": [2, "never"], + "one-var": [1, "never"], "object-curly-spacing": [2, "never"], "space-after-keywords": [2, "always"], "space-before-blocks": [2, "always"], From 1866a7ea98527068291967ce451fd68de3e48257 Mon Sep 17 00:00:00 2001 From: Philipp Hinrichsen Date: Tue, 19 Jan 2016 14:33:03 +0100 Subject: [PATCH 07/17] Change General from topic to subtopic --- coding-guidelines/coding-guidelines.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/coding-guidelines/coding-guidelines.md b/coding-guidelines/coding-guidelines.md index a5a11c14f..6fe39ceb8 100644 --- a/coding-guidelines/coding-guidelines.md +++ b/coding-guidelines/coding-guidelines.md @@ -1,5 +1,5 @@ # Coding Guidelines -# General +## General We are using the eslintrc to lint our code. All basic rules are defined there, some important rules are: - Max line length is 80 characters. - Indentation is 2 spaces. @@ -9,8 +9,6 @@ We prefer a functional approach and try to use the abstractions over normal control statements. Functions and code must be self-descriptive, use JSDoc blocks only if necessary. - - ## Strings - Strings are defined with double quotes. - Use template strings if variables are used. From 23c9e672f362a24566302d0890c3b0b6833f440a Mon Sep 17 00:00:00 2001 From: Philipp Hinrichsen Date: Tue, 19 Jan 2016 14:47:17 +0100 Subject: [PATCH 08/17] Change the order of the topics --- coding-guidelines/coding-guidelines.md | 102 ++++++++++++++----------- 1 file changed, 59 insertions(+), 43 deletions(-) diff --git a/coding-guidelines/coding-guidelines.md b/coding-guidelines/coding-guidelines.md index 6fe39ceb8..34e14eb3a 100644 --- a/coding-guidelines/coding-guidelines.md +++ b/coding-guidelines/coding-guidelines.md @@ -1,4 +1,19 @@ # Coding Guidelines +## Table of Contents + +- [General](#general) +- [Comments](#comments) +- [Strings](#strings) +- [Variables and Attribute names](#variables-and-attribute-names) +- [Object Literals](#object-literals) +- [Indentation and Line-Breaks](#indentation-and-line-breaks) +- [Functions](#functions) +- [Control Statements](#control-statements) +- [JSDoc](#jsdoc) +- [JSX](#jsx) + - [Self contained elements](#self-contained-elements) + - [Non self contained elements](#non-self-contained-elements) + ## General We are using the eslintrc to lint our code. All basic rules are defined there, some important rules are: - Max line length is 80 characters. @@ -9,6 +24,22 @@ We prefer a functional approach and try to use the abstractions over normal control statements. Functions and code must be self-descriptive, use JSDoc blocks only if necessary. +## Comments +Rules: +- Comments must be prefixed with a space sign. +- The `*` sign is a exception to the rule. + +Examples: +```JS +// Single line Comment + +//* A Exception to the space rule + +/** +* Block Comment +*/ +``` + ## Strings - Strings are defined with double quotes. - Use template strings if variables are used. @@ -18,6 +49,33 @@ Example: var string = `Hello ${world}!`; ``` +## Variables and Attribute names +Variable names always use camelCase names, except Constants which use UPPER_CASE. +One var, let or const per variable and line. + +Examples: +```JS +var camelCase = "{value}"; +let CamelCase = "{value}"; +const SOME_CONSTANT = "constant value"; +``` + +## Object Literals +Object literals must have no space after the '{' or before the '}' signs. + +Valid Example +```JS +var objectLiteral = {"key": "value", "key2": "value2"}; + +var objectLiteral = { + "key": "value", + "key2": "value2", + "key3": "value3", + "key4": "value4" +}; +``` + + ## Indentation and Line-Breaks Rules: - Line breaks are only done if needed. @@ -101,23 +159,7 @@ var es6 = (parameter, index) => { } ``` -## Comments -Rules: - - Comments must be prefixed with a space sign. - - The `*` sign is a exception to the rule. - -Examples: -```JS -// Single line Comment - -//* A Exception to the space rule - -/** - * Block Comment - */ -``` - -## If, loops, switch blocks +## Control Statements Rules: - Space after the keyword - Space before opening parentheses @@ -162,32 +204,6 @@ for (var a = 10; a !== 0; a--) { } ``` -## Variables and Attribute names -Variable names always use camelCase names, except Constants which use UPPER_CASE. -One var, let or const per variable and line. - -Examples: -```JS -var camelCase = "{value}"; -let CamelCase = "{value}"; -const SOME_CONSTANT = "constant value"; -``` - -## Object Literals -Object literals must have no space after the '{' or before the '}' signs. - -Valid Example -```JS -var objectLiteral = {"key": "value", "key2": "value2"}; - -var objectLiteral = { - "key": "value", - "key2": "value2", - "key3": "value3", - "key4": "value4" -}; -``` - ## JSDoc JSDoc block should not be needed if they are needed to these rules apply: - If there is a return there must be a type and description. From e8c93ea9755638ca9f8648d820aaca311885bb98 Mon Sep 17 00:00:00 2001 From: Philipp Hinrichsen Date: Tue, 19 Jan 2016 14:48:14 +0100 Subject: [PATCH 09/17] Remove eslint example file --- coding-guidelines/eslint-example.js | 55 ----------------------------- 1 file changed, 55 deletions(-) delete mode 100644 coding-guidelines/eslint-example.js diff --git a/coding-guidelines/eslint-example.js b/coding-guidelines/eslint-example.js deleted file mode 100644 index 39cc99a82..000000000 --- a/coding-guidelines/eslint-example.js +++ /dev/null @@ -1,55 +0,0 @@ -var React = require("react"); -//* test -const dialogId = - DialogActions.prompt("Please provide a scaling factor for all " + - "applications in this group.", - "1.0", { - type: "number", - min: "0" - } - ); - -const dialogId = DialogActions.prompt( - "Please provide a scaling factor for all applications in this group.", - "1.0", { - type: "number", - min: "0" - } -); - -const dialogId = DialogActions.prompt( - "Please provide a scaling factor for all applications in this group.Please " + - "provide a scaling factor for all applications in this group.Please " + - "provide a scaling factor for all applications in this group.", - "1.0", - { - type: "number", - min: "0" - } -); - -const dialogId = DialogActions.prompt("Please provide a scaling factor for " + - "all applications in this group.", "1.0", {type: "number", min: "0"}); - -function test() { - - return ( -
  • - Hello World! -
  • - ); -} - -test( - "A Very long string which is longer then one line, which is 80 characters " + - "in this case. This demonstrates how the second line is indented", - "Another string parameter", - {and: "a Literal Object", as: "a parameter", type: "short"}, - { - yet: "another long parameter Object", - which: "needs to be split in multiple", - lines: 3 - } -); - -test({a: {b: 10}, c: 20, d: 30, e: 40, f:50, g: 60, h: {i: 70}}); From d311e80d106736d37440bfef9a2695ef56ee3264 Mon Sep 17 00:00:00 2001 From: Philipp Hinrichsen Date: Tue, 19 Jan 2016 14:52:54 +0100 Subject: [PATCH 10/17] Fix typos, add title case to all headlines --- coding-guidelines/coding-guidelines.md | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/coding-guidelines/coding-guidelines.md b/coding-guidelines/coding-guidelines.md index 34e14eb3a..c28966329 100644 --- a/coding-guidelines/coding-guidelines.md +++ b/coding-guidelines/coding-guidelines.md @@ -4,15 +4,16 @@ - [General](#general) - [Comments](#comments) - [Strings](#strings) -- [Variables and Attribute names](#variables-and-attribute-names) +- [Variables and Attribute Names](#variables-and-attribute-names) - [Object Literals](#object-literals) -- [Indentation and Line-Breaks](#indentation-and-line-breaks) +- [Indentation and Line Breaks](#indentation-and-line-breaks) - [Functions](#functions) - [Control Statements](#control-statements) - [JSDoc](#jsdoc) - [JSX](#jsx) - - [Self contained elements](#self-contained-elements) - - [Non self contained elements](#non-self-contained-elements) + - [Self Contained Elements](#self-contained-elements) + - [Non Self Contained Elements](#non-self-contained-elements) + ## General We are using the eslintrc to lint our code. All basic rules are defined there, some important rules are: @@ -49,7 +50,7 @@ Example: var string = `Hello ${world}!`; ``` -## Variables and Attribute names +## Variables and Attribute Names Variable names always use camelCase names, except Constants which use UPPER_CASE. One var, let or const per variable and line. @@ -76,7 +77,7 @@ var objectLiteral = { ``` -## Indentation and Line-Breaks +## Indentation and Line Breaks Rules: - Line breaks are only done if needed. - Strings are split at the latest possible position. @@ -249,8 +250,8 @@ function test(number, callback) { ## JSX -### Self contained elements -On self contained elements attributes must be indented with 2 spaces. +### Self Contained Elements +On self contained element attributes must be indented with 2 spaces. Example: ```JS @@ -259,7 +260,7 @@ Example: onDismiss={this.handleDismissDialog} /> ``` -### Non self contained elements +### Non Self Contained Elements On elements which are not self contained the indentation of attributes must be 4 spaces. And the childNodes must have a indentation of 2 spaces to the element and -2 spaces to the attributes. Example: From 79670d80753e4957cbf9c15ea00b61750c87ec60 Mon Sep 17 00:00:00 2001 From: Philipp Hinrichsen Date: Tue, 19 Jan 2016 15:04:14 +0100 Subject: [PATCH 11/17] Change string to object --- coding-guidelines/coding-guidelines.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coding-guidelines/coding-guidelines.md b/coding-guidelines/coding-guidelines.md index c28966329..025148252 100644 --- a/coding-guidelines/coding-guidelines.md +++ b/coding-guidelines/coding-guidelines.md @@ -57,7 +57,7 @@ One var, let or const per variable and line. Examples: ```JS var camelCase = "{value}"; -let CamelCase = "{value}"; +let CamelCase = new Object(); const SOME_CONSTANT = "constant value"; ``` From 785f8397994537079790c99c19c5cc58b7909876 Mon Sep 17 00:00:00 2001 From: Philipp Hinrichsen Date: Tue, 19 Jan 2016 15:06:56 +0100 Subject: [PATCH 12/17] Add semicolon warnings --- .eslintrc | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc b/.eslintrc index c313b37d2..cf47c1561 100644 --- a/.eslintrc +++ b/.eslintrc @@ -42,6 +42,7 @@ "anonymous": "always", "named": "never" }], "spaced-comment": [2, "always", { "exceptions": ["*"]}], + "semi": [1, "always"], "max-len": [2, 80, 4], "valid-jsdoc": [2, { "requireReturn": false, From 0692d97bb9342b1e0494d481dbc57f93ec71799a Mon Sep 17 00:00:00 2001 From: Philipp Hinrichsen Date: Tue, 19 Jan 2016 15:08:23 +0100 Subject: [PATCH 13/17] Add semicolon to the examples --- coding-guidelines/coding-guidelines.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/coding-guidelines/coding-guidelines.md b/coding-guidelines/coding-guidelines.md index 025148252..755485aa7 100644 --- a/coding-guidelines/coding-guidelines.md +++ b/coding-guidelines/coding-guidelines.md @@ -143,21 +143,21 @@ function test() { function test() { var a = 10; return a; } -var test = function () { var b = 10; return b; } +var test = function () { var b = 10; return b; }; var es6 = parameter => parameter(); var es6 = parameter => { parameter(); return false; -} +}; var es6 = (parameter, index) => parameter(index); var es6 = (parameter, index) => { parameter(index); return false; -} +}; ``` ## Control Statements From f4f36f7a987cb4518e67d4434932c4aa64c538bd Mon Sep 17 00:00:00 2001 From: Philipp Hinrichsen Date: Tue, 19 Jan 2016 15:17:50 +0100 Subject: [PATCH 14/17] Fix the wording of the JSDoc section --- coding-guidelines/coding-guidelines.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/coding-guidelines/coding-guidelines.md b/coding-guidelines/coding-guidelines.md index 755485aa7..b4ca05254 100644 --- a/coding-guidelines/coding-guidelines.md +++ b/coding-guidelines/coding-guidelines.md @@ -206,14 +206,14 @@ for (var a = 10; a !== 0; a--) { ``` ## JSDoc -JSDoc block should not be needed if they are needed to these rules apply: +JSDoc blocks should be avoided in favor to code descriptiveness. If the are necessary these rules apply: - If there is a return there must be a type and description. - If there is one or multiple parameter/s there must be a name, type and description for each one. Example: ```JS /** - * Description of what the function does + * Description how the function behaves. * * @param {Function} a A function containing a callback. */ @@ -222,7 +222,7 @@ function b(a) { } /** - * Description of what the function does. + * Description how the function behaves. * * @param {Function} a A function containing a callback. * @return {String} Returns a String containing "done". @@ -233,7 +233,7 @@ function test(a) { } /** - * Description of what the function does. + * Description how the function behaves. * * @param {Number} a A Number on how often the b should be called. * @param {Function} callback A function containing a callback function. From 6ed44c9138698a607cbac0a058119f2a7a01db30 Mon Sep 17 00:00:00 2001 From: Philipp Hinrichsen Date: Tue, 19 Jan 2016 15:18:14 +0100 Subject: [PATCH 15/17] Fix example to be valid code. --- coding-guidelines/coding-guidelines.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coding-guidelines/coding-guidelines.md b/coding-guidelines/coding-guidelines.md index b4ca05254..65fcf3a6d 100644 --- a/coding-guidelines/coding-guidelines.md +++ b/coding-guidelines/coding-guidelines.md @@ -242,7 +242,7 @@ function test(a) { function test(number, callback) { var counter; for (counter = 0; counter <= number; counter++) { - a(); + callback(); } return "done"; } From 0ff251dce5b7cc2d25ed53373a48a7bc0d196824 Mon Sep 17 00:00:00 2001 From: Philipp Hinrichsen Date: Tue, 19 Jan 2016 15:29:45 +0100 Subject: [PATCH 16/17] Fix typos --- coding-guidelines/coding-guidelines.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/coding-guidelines/coding-guidelines.md b/coding-guidelines/coding-guidelines.md index 65fcf3a6d..7ff7a9079 100644 --- a/coding-guidelines/coding-guidelines.md +++ b/coding-guidelines/coding-guidelines.md @@ -21,7 +21,7 @@ We are using the eslintrc to lint our code. All basic rules are defined there, s - Indentation is 2 spaces. - No multiple empty lines. -We prefer a functional approach and try to use the abstractions over +We prefer a functional approach and try to use these abstractions over normal control statements. Functions and code must be self-descriptive, use JSDoc blocks only if necessary. @@ -95,8 +95,8 @@ Rules: Examples: ```JS test( - "A Very long string which is longer then one line, which is 80 characters " + - "in this case. This demonstrates how the second line is indented", + "A very long string that is longer then one line, which is 80 characters " + + "in this case. This demonstrates how the second line is indented.", "Another string parameter.", {and: "a Literal Object", as: "a parameter", type: "short"}, { @@ -206,7 +206,7 @@ for (var a = 10; a !== 0; a--) { ``` ## JSDoc -JSDoc blocks should be avoided in favor to code descriptiveness. If the are necessary these rules apply: +JSDoc blocks should be avoided in favor to code descriptiveness. If they are necessary these rules apply: - If there is a return there must be a type and description. - If there is one or multiple parameter/s there must be a name, type and description for each one. From 3d6bbeaafd43fc3393e1018b768f6d02aa3a42c6 Mon Sep 17 00:00:00 2001 From: Philipp Hinrichsen Date: Wed, 20 Jan 2016 14:21:28 +0100 Subject: [PATCH 17/17] Add ternaries section --- coding-guidelines/coding-guidelines.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/coding-guidelines/coding-guidelines.md b/coding-guidelines/coding-guidelines.md index 7ff7a9079..072381101 100644 --- a/coding-guidelines/coding-guidelines.md +++ b/coding-guidelines/coding-guidelines.md @@ -9,6 +9,7 @@ - [Indentation and Line Breaks](#indentation-and-line-breaks) - [Functions](#functions) - [Control Statements](#control-statements) + - [Ternaries](#ternaries) - [JSDoc](#jsdoc) - [JSX](#jsx) - [Self Contained Elements](#self-contained-elements) @@ -84,7 +85,7 @@ Rules: - At the latest whitespace character. - The second line is indented with 2 spaces. ```JS - var longString = "A Very long string which is longer then one line, which is 80 characters " + + var longString = "A very long string which is longer then one line, which is 80 characters " + "in this case. This demonstrates how the second line is indented"; ``` - Object literals are kept on one line if possible. @@ -248,6 +249,18 @@ function test(number, callback) { } ``` +### Ternaries +Rules: + - We are using ternaries only for single line values. + - Operators are placed at the beginning of the line. + - Use ternaries sparingly. + +```JS +var title = !Util.isStringAndEmpty(props.title) + ?

    {props.title}

    + : null; +``` + ## JSX ### Self Contained Elements