├── Angular(1.6) ├── README.md └── typescript │ └── README.md ├── Angular(1.x) ├── README.md ├── assets │ ├── above-the-fold-1.png │ ├── above-the-fold-2.png │ ├── brackets-angular-snippets.yaml │ ├── gde.png │ ├── modularity-1.png │ ├── modularity-2.png │ ├── ng-clean-code-banner.png │ ├── sublime-angular-snippets │ │ ├── angular.controller.sublime-snippet │ │ ├── angular.directive.sublime-snippet │ │ ├── angular.factory.sublime-snippet │ │ ├── angular.filter.sublime-snippet │ │ ├── angular.module.sublime-snippet │ │ └── angular.service.sublime-snippet │ ├── testing-tools.png │ ├── vim-angular-snippets │ │ ├── angular.controller.snip │ │ ├── angular.directive.snip │ │ ├── angular.factory.snip │ │ ├── angular.filter.snip │ │ ├── angular.module.snip │ │ └── angular.service.snip │ ├── vim-angular-ultisnips │ │ ├── javascript_angular.controller.snippets │ │ ├── javascript_angular.directive.snippets │ │ ├── javascript_angular.factory.snippets │ │ ├── javascript_angular.filter.snippets │ │ ├── javascript_angular.module.snippets │ │ └── javascript_angular.service.snippets │ ├── vscode-snippets │ │ ├── javascript.json │ │ └── typescript.json │ └── webstorm-angular-live-templates │ │ ├── angular.app.webstorm-live-template.xml │ │ ├── angular.config.webstorm-live-template.xml │ │ ├── angular.controller.webstorm-live-template.xml │ │ ├── angular.directive.webstorm-live-template.xml │ │ ├── angular.factory.webstorm-live-template.xml │ │ ├── angular.filter.webstorm-live-template.xml │ │ ├── angular.module.webstorm-live-template.xml │ │ ├── angular.route.webstorm-live-template.xml │ │ ├── angular.run.webstorm-live-template.xml │ │ ├── angular.service.webstorm-live-template.xml │ │ ├── angular.state.webstorm-live-template.xml │ │ └── webstorm-angular-live-templates.xml └── i18n │ ├── README.md │ ├── de-DE.md │ ├── es-ES.md │ ├── fr-FR.md │ ├── it-IT.md │ ├── ja-JP.md │ ├── ko_KR.md │ ├── mk-MK.md │ ├── pt-BR.md │ ├── ru-RU.md │ ├── tr-TR.md │ └── zh-CN.md ├── CONTRIBUTING.md ├── CSharp ├── .editorconfig ├── CSharpStyleguide.ruleset └── README.md ├── Java ├── README.md ├── eclipse-java-google-style.xml └── intellij-java-google-style.xml ├── Javascript(ES5) ├── .eslintrc └── README.md ├── Javascript(ES6) ├── .eslintrc └── README.md ├── NodeJs ├── .eslintrc ├── .jshintrc └── Readme.md ├── React ├── Courses │ └── README.md ├── Documentation │ └── README.md └── README.md ├── Readme.md └── Swift ├── Readme.md └── screens ├── indentation.png └── xcode-jump-bar.png /Angular(1.x)/assets/above-the-fold-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MakingSense/code-style-guides/517b852480c0acfe6d6fb5f95f32fceddab1f0fe/Angular(1.x)/assets/above-the-fold-1.png -------------------------------------------------------------------------------- /Angular(1.x)/assets/above-the-fold-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MakingSense/code-style-guides/517b852480c0acfe6d6fb5f95f32fceddab1f0fe/Angular(1.x)/assets/above-the-fold-2.png -------------------------------------------------------------------------------- /Angular(1.x)/assets/brackets-angular-snippets.yaml: -------------------------------------------------------------------------------- 1 | - trigger: ngfilter 2 | description: "Filter" 3 | scope: javascript 4 | text: | 5 | (function () { 6 | 'use strict'; 7 | 8 | angular 9 | .module('${1:module}') 10 | .filter('${2:filter}', ${2:filter}); 11 | 12 | function ${2:filter}() { 13 | ${4:} 14 | return ${2:filter}Filter; 15 | 16 | //////////////// 17 | 18 | function ${2:filter}Filter(${3:parameters}) { 19 | return ${3:parameters}; 20 | }; 21 | } 22 | })(); 23 | 24 | - trigger: ngservice 25 | description: "Service" 26 | scope: javascript 27 | text: | 28 | (function () { 29 | 'use strict'; 30 | 31 | angular 32 | .module('${1:module}') 33 | .service('${2:Service}', ${2:Service}); 34 | 35 | ${2:Service}.$inject = ['${3:dependencies}']; 36 | 37 | /* @ngInject */ 38 | function ${2:Service}(${3:dependencies}) { 39 | this.${4:func} = ${4:func}; 40 | 41 | //////////////// 42 | 43 | function ${4:func}() { 44 | ${5:} 45 | } 46 | } 47 | })(); 48 | 49 | - trigger: ngapp 50 | description: "Module definition" 51 | scope: javascript 52 | text: | 53 | (function () { 54 | 'use strict'; 55 | 56 | angular 57 | .module('${1:module}', [ 58 | '${2:dependencies}' 59 | ]); 60 | })(); 61 | 62 | - trigger: ngfactory 63 | description: "Factory" 64 | scope: javascript 65 | text: | 66 | (function () { 67 | 'use strict'; 68 | angular 69 | .module('${1:module}') 70 | .factory('${2:factory}', ${2:factory}); 71 | 72 | ${2:factory}.$inject = ['${3:dependencies}']; 73 | 74 | /* @ngInject */ 75 | function ${2: Factory}(${3:dependencies}){ 76 | var exports = { 77 | ${4:func}: ${4:func} 78 | }; 79 | ${5:} 80 | 81 | return exports; 82 | 83 | //////////////// 84 | 85 | function ${4:func}() { 86 | } 87 | } 88 | })(); 89 | 90 | - trigger: ngdirective 91 | description: "Directive" 92 | scope: javascript 93 | text: | 94 | (function () { 95 | 'use strict'; 96 | 97 | angular 98 | .module('${1:module}') 99 | .directive('${2:directive}', ${2:directive}); 100 | 101 | ${2:directive}.$inject = ['${3:dependencies}']; 102 | 103 | /* @ngInject */ 104 | function ${2: directive}(${3:dependencies}) { 105 | var directive = { 106 | bindToController: true, 107 | controller: ${4:Controller}, 108 | controllerAs: '${5:vm}', 109 | link: link, 110 | restrict: 'A', 111 | scope: {} 112 | }; 113 | return directive; 114 | 115 | function link(scope, element, attrs, controller) { 116 | ${7:} 117 | } 118 | } 119 | 120 | ${4:Controller}.$inject = ['${6:dependencies}']; 121 | 122 | /* @ngInject */ 123 | function ${4:Controller}(${6:dependencies}) { 124 | } 125 | })(); 126 | 127 | - trigger: ngcontroller 128 | description: "Controller" 129 | scope: javascript 130 | text: | 131 | (function() { 132 | 'use strict'; 133 | 134 | angular 135 | .module('${1:module}') 136 | .controller('${2:Controller}', ${2:Controller}); 137 | 138 | ${2:Controller}.$inject = ['${3:dependencies}']; 139 | 140 | /* @ngInject */ 141 | function ${2:Controller}(${3:dependencies}){ 142 | var vm = this; 143 | vm.${4:property} = '${2:Controller}'; 144 | ${5:} 145 | 146 | activate(); 147 | 148 | //////////////// 149 | 150 | function activate() { 151 | } 152 | } 153 | })(); 154 | 155 | - trigger: ngwhen 156 | description: "ngRoute 'when'" 157 | scope: javascript 158 | text: | 159 | .when('/${1:url}', { 160 | templateUrl: '${2:template}.html', 161 | controller: '${3:Controller}', 162 | controllerAs: '${4:vm}' 163 | })${5:} 164 | 165 | - trigger: ngstate 166 | description: "UI-Router state" 167 | scope: javascript 168 | text: | 169 | .state('${1:state}', { 170 | url: '${2:/url}', 171 | templateUrl: '${3:template}.html', 172 | controller: '${4:Controller}', 173 | controllerAs: '${5:vm}' 174 | })${6:} 175 | 176 | - trigger: ngmodule 177 | description: "Module getter" 178 | scope: javascript 179 | text: | 180 | angular 181 | .module('${1:module}')${2:} 182 | - trigger: ngconst 183 | description: "Constant" 184 | scope: javascript 185 | text: | 186 | .constant('${1:name}', ${2:value}); 187 | 188 | - trigger: ngvalue 189 | description: "Value" 190 | scope: javascript 191 | text: | 192 | .value('${1:name}', ${2:value}); 193 | 194 | - trigger: ngconfig 195 | description: "Config phase function" 196 | scope: javascript 197 | text: | 198 | .config(${1:configuration}) 199 | 200 | ${1:configuration}.$inject = ['${2:dependencies}']; 201 | 202 | /* @ngInject */ 203 | function ${1:configuration} (${2:dependencies}) { 204 | ${3:} 205 | } 206 | 207 | - trigger: ngrun 208 | description: "Run phase function" 209 | scope: javascript 210 | text: | 211 | .run(${1:runFn}) 212 | 213 | ${1:runFn}.$inject = ['${2:dependencies}']; 214 | 215 | /* @ngInject */ 216 | function ${1:runFn} (${2:dependencies}) { 217 | ${3:} 218 | } 219 | 220 | - trigger: ngtranslate 221 | description: "$translate service" 222 | scope: javascript 223 | text: | 224 | $translate(['${1:key1}']).then(function(translations){ 225 | ${2:value} = translations['${3:key1}']; 226 | }); 227 | -------------------------------------------------------------------------------- /Angular(1.x)/assets/gde.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MakingSense/code-style-guides/517b852480c0acfe6d6fb5f95f32fceddab1f0fe/Angular(1.x)/assets/gde.png -------------------------------------------------------------------------------- /Angular(1.x)/assets/modularity-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MakingSense/code-style-guides/517b852480c0acfe6d6fb5f95f32fceddab1f0fe/Angular(1.x)/assets/modularity-1.png -------------------------------------------------------------------------------- /Angular(1.x)/assets/modularity-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MakingSense/code-style-guides/517b852480c0acfe6d6fb5f95f32fceddab1f0fe/Angular(1.x)/assets/modularity-2.png -------------------------------------------------------------------------------- /Angular(1.x)/assets/ng-clean-code-banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MakingSense/code-style-guides/517b852480c0acfe6d6fb5f95f32fceddab1f0fe/Angular(1.x)/assets/ng-clean-code-banner.png -------------------------------------------------------------------------------- /Angular(1.x)/assets/sublime-angular-snippets/angular.controller.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 25 | ngcontroller 26 | text.plain, source.js 27 | 28 | -------------------------------------------------------------------------------- /Angular(1.x)/assets/sublime-angular-snippets/angular.directive.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 38 | ngdirective 39 | text.plain, source.js 40 | 41 | -------------------------------------------------------------------------------- /Angular(1.x)/assets/sublime-angular-snippets/angular.factory.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 25 | ngfactory 26 | text.plain, source.js 27 | 28 | -------------------------------------------------------------------------------- /Angular(1.x)/assets/sublime-angular-snippets/angular.filter.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 21 | ngfilter 22 | text.plain, source.js 23 | 24 | -------------------------------------------------------------------------------- /Angular(1.x)/assets/sublime-angular-snippets/angular.module.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 11 | ngmodule 12 | text.plain, source.js 13 | 14 | -------------------------------------------------------------------------------- /Angular(1.x)/assets/sublime-angular-snippets/angular.service.sublime-snippet: -------------------------------------------------------------------------------- 1 | 2 | 22 | ngservice 23 | text.plain, source.js 24 | 25 | -------------------------------------------------------------------------------- /Angular(1.x)/assets/testing-tools.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MakingSense/code-style-guides/517b852480c0acfe6d6fb5f95f32fceddab1f0fe/Angular(1.x)/assets/testing-tools.png -------------------------------------------------------------------------------- /Angular(1.x)/assets/vim-angular-snippets/angular.controller.snip: -------------------------------------------------------------------------------- 1 | snippet ngcontroller 2 | options head 3 | (function() { 4 | 'use strict'; 5 | 6 | angular 7 | .module('${1:module}') 8 | .controller('${2:Controller}Controller', $2Controller); 9 | 10 | /* @ngInject */ 11 | function $2Controller(${3:dependencies}) { 12 | var vm = this; 13 | vm.title = '$2Controller'; 14 | 15 | activate(); 16 | 17 | //////////////// 18 | 19 | function activate() { 20 | } 21 | } 22 | })(); 23 | -------------------------------------------------------------------------------- /Angular(1.x)/assets/vim-angular-snippets/angular.directive.snip: -------------------------------------------------------------------------------- 1 | snippet ngdirective 2 | options head 3 | (function() { 4 | 'use strict'; 5 | 6 | angular 7 | .module('${1:module}') 8 | .directive('${2:directive}', $2); 9 | 10 | /* @ngInject */ 11 | function $2(${3:dependencies}) { 12 | // Usage: 13 | // 14 | // Creates: 15 | // 16 | var directive = { 17 | bindToController: true, 18 | controller: ${4:Controller}, 19 | controllerAs: '${5:vm}', 20 | link: link, 21 | restrict: 'A', 22 | scope: { 23 | } 24 | }; 25 | return directive; 26 | 27 | function link(scope, element, attrs) { 28 | } 29 | } 30 | 31 | /* @ngInject */ 32 | function $4() { 33 | 34 | } 35 | })(); 36 | -------------------------------------------------------------------------------- /Angular(1.x)/assets/vim-angular-snippets/angular.factory.snip: -------------------------------------------------------------------------------- 1 | snippet ngfactory 2 | options head 3 | (function() { 4 | 'use strict'; 5 | 6 | angular 7 | .module('${1:module}') 8 | .factory('${2:factory}', $2); 9 | 10 | /* @ngInject */ 11 | function $2(${3:dependencies}) { 12 | var service = { 13 | ${4:func}: $4 14 | }; 15 | return service; 16 | 17 | //////////////// 18 | 19 | function $4() { 20 | } 21 | } 22 | })(); 23 | -------------------------------------------------------------------------------- /Angular(1.x)/assets/vim-angular-snippets/angular.filter.snip: -------------------------------------------------------------------------------- 1 | snippet ngfilter 2 | options head 3 | (function() { 4 | 'use strict'; 5 | 6 | angular 7 | .module('${1:module}') 8 | .filter('${2:filter}', $2); 9 | 10 | function $2() { 11 | return $2Filter; 12 | 13 | //////////////// 14 | function $2Filter(${3:params}) { 15 | return $3; 16 | }; 17 | } 18 | 19 | })(); 20 | -------------------------------------------------------------------------------- /Angular(1.x)/assets/vim-angular-snippets/angular.module.snip: -------------------------------------------------------------------------------- 1 | snippet ngmodule 2 | options head 3 | (function() { 4 | 'use strict'; 5 | 6 | angular 7 | .module('${1:module}', [ 8 | '${2:dependencies}' 9 | ]); 10 | })(); 11 | -------------------------------------------------------------------------------- /Angular(1.x)/assets/vim-angular-snippets/angular.service.snip: -------------------------------------------------------------------------------- 1 | snippet ngservice 2 | options head 3 | (function() { 4 | 'use strict'; 5 | 6 | angular 7 | .module('${1:module}') 8 | .service('${2:Service}', $2); 9 | 10 | /* @ngInject */ 11 | function $2(${3:dependencies}) { 12 | this.${4:func} = $4; 13 | 14 | //////////////// 15 | 16 | function $4() { 17 | } 18 | } 19 | })(); 20 | -------------------------------------------------------------------------------- /Angular(1.x)/assets/vim-angular-ultisnips/javascript_angular.controller.snippets: -------------------------------------------------------------------------------- 1 | snippet ngcontroller 2 | (function() { 3 | 'use strict'; 4 | 5 | angular 6 | .module('${1:module}') 7 | .controller('${2:Controller}Controller', $2Controller); 8 | 9 | /* @ngInject */ 10 | function $2Controller(${3:dependencies}) { 11 | var vm = this; 12 | vm.title = '$2Controller'; 13 | 14 | activate(); 15 | 16 | //////////////// 17 | 18 | function activate() { 19 | } 20 | } 21 | })(); 22 | endsnippet 23 | -------------------------------------------------------------------------------- /Angular(1.x)/assets/vim-angular-ultisnips/javascript_angular.directive.snippets: -------------------------------------------------------------------------------- 1 | snippet ngdirective 2 | (function() { 3 | 'use strict'; 4 | 5 | angular 6 | .module('${1:module}') 7 | .directive('${2:directive}', $2); 8 | 9 | /* @ngInject */ 10 | function $2(${3:dependencies}) { 11 | // Usage: 12 | // 13 | // Creates: 14 | // 15 | var directive = { 16 | bindToController: true, 17 | controller: ${4:Controller}, 18 | controllerAs: '${5:vm}', 19 | link: link, 20 | restrict: 'A', 21 | scope: { 22 | } 23 | }; 24 | return directive; 25 | 26 | function link(scope, element, attrs) { 27 | } 28 | } 29 | 30 | /* @ngInject */ 31 | function $4() { 32 | 33 | } 34 | })(); 35 | endsnippet 36 | -------------------------------------------------------------------------------- /Angular(1.x)/assets/vim-angular-ultisnips/javascript_angular.factory.snippets: -------------------------------------------------------------------------------- 1 | snippet ngfactory 2 | (function() { 3 | 'use strict'; 4 | 5 | angular 6 | .module('${1:module}') 7 | .factory('${2:factory}', $2); 8 | 9 | /* @ngInject */ 10 | function $2(${3:dependencies}) { 11 | var service = { 12 | ${4:func}: $4 13 | }; 14 | return service; 15 | 16 | //////////////// 17 | 18 | function $4() { 19 | } 20 | } 21 | })(); 22 | endsnippet 23 | -------------------------------------------------------------------------------- /Angular(1.x)/assets/vim-angular-ultisnips/javascript_angular.filter.snippets: -------------------------------------------------------------------------------- 1 | snippet ngfilter 2 | (function() { 3 | 'use strict'; 4 | 5 | angular 6 | .module('${1:module}') 7 | .filter('${2:filter}', $2); 8 | 9 | function $2() { 10 | return $2Filter; 11 | 12 | //////////////// 13 | function $2Filter(${3:params}) { 14 | return $3; 15 | }; 16 | } 17 | 18 | })(); 19 | endsnippet 20 | -------------------------------------------------------------------------------- /Angular(1.x)/assets/vim-angular-ultisnips/javascript_angular.module.snippets: -------------------------------------------------------------------------------- 1 | snippet ngmodule 2 | (function() { 3 | 'use strict'; 4 | 5 | angular 6 | .module('${1:module}', [ 7 | '${2:dependencies}' 8 | ]); 9 | })(); 10 | endsnippet 11 | -------------------------------------------------------------------------------- /Angular(1.x)/assets/vim-angular-ultisnips/javascript_angular.service.snippets: -------------------------------------------------------------------------------- 1 | snippet ngservice 2 | (function() { 3 | 'use strict'; 4 | 5 | angular 6 | .module('${1:module}') 7 | .service('${2:Service}', $2); 8 | 9 | /* @ngInject */ 10 | function $2(${3:dependencies}) { 11 | this.${4:func} = $4; 12 | 13 | //////////////// 14 | 15 | function $4() { 16 | } 17 | } 18 | })(); 19 | endsnippet 20 | -------------------------------------------------------------------------------- /Angular(1.x)/assets/vscode-snippets/javascript.json: -------------------------------------------------------------------------------- 1 | { 2 | "Angular Controller": { 3 | "prefix": "ngcontroller", 4 | "body": [ 5 | "(function() {", 6 | "'use strict';", 7 | "", 8 | "\tangular", 9 | "\t\t.module('${Module}')", 10 | "\t\t.controller('${Controller}Controller', ${Controller}Controller);", 11 | "", 12 | "\t${Controller}Controller.$inject = ['${dependency1}'];", 13 | "\tfunction ${Controller}Controller(${dependency1}) {", 14 | "\t\tvar vm = this;", 15 | "\t\t$0", 16 | "", 17 | "\t\tactivate();", 18 | "", 19 | "\t\t////////////////", 20 | "", 21 | "\t\tfunction activate() { }", 22 | "\t}", 23 | "})();" 24 | ], 25 | "description": "Angular 1 controller" 26 | }, 27 | "Angular Service": { 28 | "prefix": "ngservice", 29 | "body": [ 30 | "(function() {", 31 | "'use strict';", 32 | "", 33 | "\tangular", 34 | "\t\t.module('${Module}')", 35 | "\t\t.service('${Service}', ${Service});", 36 | "", 37 | "\t${Service}.$inject = ['${dependency1}'];", 38 | "\tfunction ${Service}(${dependency1}) {", 39 | "\t\tthis.${exposedFn} = ${exposedFn};", 40 | "\t\t$0", 41 | "\t\t////////////////", 42 | "\t\tfunction ${exposedFn}() { }", 43 | "\t}", 44 | "})();" 45 | ], 46 | "description": "Angular 1 service" 47 | }, 48 | "Angular Factory": { 49 | "prefix": "ngfactory", 50 | "body": [ 51 | "(function() {", 52 | "'use strict';", 53 | "", 54 | "\tangular", 55 | "\t\t.module('${Module}')", 56 | "\t\t.factory('${Service}', ${Service});", 57 | "", 58 | "\t${Service}.$inject = ['${dependency1}'];", 59 | "\tfunction ${Service}(${dependency1}) {", 60 | "\t\tvar service = {", 61 | "\t\t\t${exposedFn}:${exposedFn}", 62 | "\t\t};", 63 | "\t\t$0", 64 | "\t\treturn service;", 65 | "", 66 | "\t\t////////////////", 67 | "\t\tfunction ${exposedFn}() { }", 68 | "\t}", 69 | "})();" 70 | ], 71 | "description": "Angular 1 factory" 72 | }, 73 | "Angular Directive": { 74 | "prefix": "ngdirective", 75 | "body": [ 76 | "(function() {", 77 | "\t'use strict';", 78 | "", 79 | "\tangular", 80 | "\t\t.module('${Module}')", 81 | "\t\t.directive('${Directive}', ${Directive});", 82 | "", 83 | "\t${Directive}.$inject = ['${dependency1}'];", 84 | "\tfunction ${Directive}(${dependency1}) {", 85 | "\t\t// Usage:", 86 | "\t\t//", 87 | "\t\t// Creates:", 88 | "\t\t//", 89 | "\t\tvar directive = {", 90 | "\t\t bindToController: true,", 91 | "\t\t controller: ${Controller}Controller,", 92 | "\t\t controllerAs: '${vm}',", 93 | "\t\t link: link,", 94 | "\t\t restrict: 'A',", 95 | "\t\t scope: {", 96 | "\t\t }", 97 | "\t\t};", 98 | "\t\treturn directive;", 99 | "\t\t", 100 | "\t\tfunction link(scope, element, attrs) {", 101 | "\t\t}", 102 | "\t}", 103 | "\t/* @ngInject */", 104 | "\tfunction ${Controller}Controller () {", 105 | "\t\t$0", 106 | "\t}", 107 | "})();" 108 | ], 109 | "description": "Angular 1 directive" 110 | }, 111 | "Angular Module": { 112 | "prefix": "ngmodule", 113 | "body": [ 114 | "(function() {", 115 | "\t'use strict';", 116 | "", 117 | "\tangular.module('${module}', [", 118 | "\t\t$0", 119 | "\t]);", 120 | "})();" 121 | ], 122 | "description": "Angular 1 module" 123 | } 124 | } -------------------------------------------------------------------------------- /Angular(1.x)/assets/vscode-snippets/typescript.json: -------------------------------------------------------------------------------- 1 | { 2 | "Angular Controller": { 3 | "prefix": "ngcontroller", 4 | "body": [ 5 | "namespace ${module} {", 6 | "'use strict';", 7 | "", 8 | "export class ${Controller}Controller {", 9 | "\tstatic $inject: Array = ['${dependency1}'];", 10 | "\tconstructor(private ${dependency1}: ${dependency1Type}) {", 11 | "$0", 12 | "}", 13 | "", 14 | "\t${property}: ${propertyType} = ${propertyValue};", 15 | "", 16 | "\t${fn}() { }", 17 | "}", 18 | "", 19 | "angular", 20 | "\t.module('${Module}')", 21 | "\t.controller('${Controller}Controller', ${Controller}Controller);", 22 | "}" 23 | ] 24 | }, 25 | "Angular Service": { 26 | "prefix": "ngservice", 27 | "body": [ 28 | "namespace ${module} {", 29 | "'use strict';", 30 | "", 31 | "export interface I${Service} {", 32 | "\t${serviceFn}: (${dependency1}:${dependency1Type}) => ${returnType};", 33 | "}", 34 | "export class ${Service} implements I${Service} {", 35 | "\tstatic $inject: Array = ['${dependency1}'];", 36 | "\tconstructor(private ${dependency1}: ${dependency1Type}) {", 37 | "", 38 | "}", 39 | "", 40 | "\t${serviceFn}: (${dependency1}:${dependency1Type}) => ${returnType} = (${dependency1}:${dependency1Type}) => {", 41 | "\t\t$0", 42 | "\t}", 43 | "", 44 | "}", 45 | "", 46 | "angular", 47 | "\t.module('${Module}')", 48 | "\t.service('${Service}', ${Service});", 49 | "}" 50 | ] 51 | }, 52 | "Angular Module": { 53 | "prefix": "ngmodule", 54 | "body": [ 55 | "namespace ${module} {", 56 | "\t'use strict';", 57 | "", 58 | "\tangular.module('${module}', [", 59 | "\t$0", 60 | "\t]);", 61 | "}" 62 | ] 63 | } 64 | } -------------------------------------------------------------------------------- /Angular(1.x)/assets/webstorm-angular-live-templates/angular.app.webstorm-live-template.xml: -------------------------------------------------------------------------------- 1 | 2 | 33 | -------------------------------------------------------------------------------- /Angular(1.x)/assets/webstorm-angular-live-templates/angular.config.webstorm-live-template.xml: -------------------------------------------------------------------------------- 1 | 2 | 34 | -------------------------------------------------------------------------------- /Angular(1.x)/assets/webstorm-angular-live-templates/angular.controller.webstorm-live-template.xml: -------------------------------------------------------------------------------- 1 | 2 | 35 | -------------------------------------------------------------------------------- /Angular(1.x)/assets/webstorm-angular-live-templates/angular.directive.webstorm-live-template.xml: -------------------------------------------------------------------------------- 1 | 2 | 37 | 38 | -------------------------------------------------------------------------------- /Angular(1.x)/assets/webstorm-angular-live-templates/angular.factory.webstorm-live-template.xml: -------------------------------------------------------------------------------- 1 | 2 | 36 | -------------------------------------------------------------------------------- /Angular(1.x)/assets/webstorm-angular-live-templates/angular.filter.webstorm-live-template.xml: -------------------------------------------------------------------------------- 1 | 2 | 34 | -------------------------------------------------------------------------------- /Angular(1.x)/assets/webstorm-angular-live-templates/angular.module.webstorm-live-template.xml: -------------------------------------------------------------------------------- 1 | 2 | 31 | -------------------------------------------------------------------------------- /Angular(1.x)/assets/webstorm-angular-live-templates/angular.route.webstorm-live-template.xml: -------------------------------------------------------------------------------- 1 | 2 | 35 | -------------------------------------------------------------------------------- /Angular(1.x)/assets/webstorm-angular-live-templates/angular.run.webstorm-live-template.xml: -------------------------------------------------------------------------------- 1 | 2 | 34 | -------------------------------------------------------------------------------- /Angular(1.x)/assets/webstorm-angular-live-templates/angular.service.webstorm-live-template.xml: -------------------------------------------------------------------------------- 1 | 2 | 36 | -------------------------------------------------------------------------------- /Angular(1.x)/assets/webstorm-angular-live-templates/angular.state.webstorm-live-template.xml: -------------------------------------------------------------------------------- 1 | 2 | 36 | -------------------------------------------------------------------------------- /Angular(1.x)/assets/webstorm-angular-live-templates/webstorm-angular-live-templates.xml: -------------------------------------------------------------------------------- 1 | 2 | 35 | 70 | 104 | 136 | 167 | 201 | 233 | 267 | 299 | 328 | 361 | 362 | -------------------------------------------------------------------------------- /Angular(1.x)/i18n/README.md: -------------------------------------------------------------------------------- 1 | #Translations 2 | 3 | The [original English version](http://jpapa.me/ngstyles) is the source of truth, as it is maintained and updated first. 4 | 5 | *All translations are created by and maintained by the community.* 6 | 7 | 1. [French](fr-FR.md) by [Eric Le Merdy](https://github.com/ericlemerdy) and [Xavier Haniquaut] (@xavhan) 8 | 1. [German](de-DE.md) by [Michael Seeger](https://github.com/miseeger), [Sascha Hagedorn](https://github.com/saesh) and [Johannes Weber](https://github.com/johannes-weber) 9 | 1. [Italian](it-IT.md) by [Angelo Chiello](https://github.com/angelochiello) 10 | 1. [Japanese](ja-JP.md) by [@noritamago](https://github.com/noritamago) 11 | 1. [Macedonian](mk-MK.md) by [Aleksandar Bogatinov](https://github.com/Bogatinov) 12 | 1. [Portuguese-Brazil](pt-BR.md) by [Vinicius Sabadim Fernandes](https://github.com/vinicius-sabadim) 13 | 1. [Russian](ru-RU.md) by [Vasiliy Mazhekin](https://github.com/mazhekin) 14 | 1. [Simplified Chinese](zh-CN.md) by [Zhao Ke](https://github.com/natee) 15 | 1. [Spanish](es-ES.md) by [Alberto Calleja](https://github.com/AlbertoImpl) and [Gilberto](https://github.com/ingilniero) 16 | 1. [Korean](ko-KR.md) by [Joshua Ji](https://github.com/zirho) 17 | 1. [Turkish](tr-TR.md) by [Uğur Korfalı](https://github.com/kel-sakal-biyik) 18 | 19 | ## Contributing 20 | Language translations are welcomed and encouraged. The success of these translations depends on the community. I highly encourage new translation contributions and help to keep them up to date. 21 | 22 | All translations must preserve the intention of the original document. 23 | 24 | > All contributions fall under the [MIT License of this repository](https://github.com/johnpapa/angularjs-styleguide#license). In other words, you would be providing these free to the community. 25 | 26 | ### New Translations 27 | 1. Fork the repository 28 | 2. Create a translation file and name it using the 118n standard format. 29 | 3. Put this file in the i18n folder 30 | 4. Translate the original English version to be current with the latest changes 31 | 3. Make a Pull Request 32 | 33 | Once you do these I will merge, point the translation links to it, and enter the translation credit to you. 34 | 35 | ### Updated Translations 36 | 1. Fork the repository 37 | 2. Make the translation changes 38 | 3. Make a Pull Request 39 | 40 | Once you do these I will merge, point the translation links to it, and enter the translation credit to you. 41 | 42 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to this repository 2 | 3 | Thank you for being interested in contributing to this repository! Whether you're a part of Making Sense or not, you rule for helping us build quality guidelines. 4 | 5 | Here are a few guidelines for the contributions: 6 | 7 | - **Prefer pull requests over issues:** If you have a proposal and it's not too much work, feel free to open a pull request. It's always easier to discuss over a set of changes than on the idea of those changes. Sometimes that is not quite feasible and that's ok too -- but if you have something to show, it's always better to show the real stuff. 8 | - **Make sure you get the approval from the right people:** If you don't have a general consensus, or if nobody has looked at your changes, contact the following people that will help with the right technologies. Tag them in the PRs / issues so that you can get an answer whenever possible. 9 | - JavaScript ES5: [@AlphaGit][user_alphagit], [@MRavinale][user_mravinale], [@NoeliaSFranco][user_noeliasfranco] 10 | - JavaScript ES6: [@AlphaGit][user_alphagit], [@MRavinale][user_mravinale], [@NoeliaSFranco][user_noeliasfranco] 11 | - Angular 1.x: [@AlphaGit][user_alphagit], [@MRavinale][user_mravinale], [@NoeliaSFranco][user_noeliasfranco] 12 | - NodeJs: [@AlphaGit][user_alphagit], [@MRavinale][user_mravinale], [@NoeliaSFranco][user_noeliasfranco] 13 | - React: [@JuampiCK][user_juampick], [@KiliSoria][user_kilisoria], [@NoeliaSFranco][user_noeliasfranco] 14 | - .NET: [@AlphaGit][user_alphagit], [@MRavinale][user_mravinale], [@MVazquez-MS][user_mvazquez] 15 | - **If you have merging privileges, make sure the right people has approved the changes:** See previous item for the right people to approve changes for each technology. You should get at least an approval from one of them. 16 | 17 | [user_mravinale]: https://github.com/mravinale 18 | [user_alphagit]: https://github.com/AlphaGit 19 | [user_juampick]: https://github.com/juampick 20 | [user_noeliasfranco]: https://github.com/noeliasfranco 21 | [user_mvazquez]: https://github.com/mvazquez-ms 22 | [user_kilisoria]: https://github.com/kilisoria -------------------------------------------------------------------------------- /CSharp/.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome:http://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | [*] 7 | insert_final_newline = true 8 | indent_style = space 9 | 10 | # Code files 11 | [*.{cs,csx}] 12 | indent_size = 4 13 | 14 | # Xml project files 15 | [*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}] 16 | indent_size = 2 17 | 18 | # Xml config files 19 | [*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}] 20 | indent_size = 2 21 | 22 | # JavaScript/HTML 23 | [*.{js,ts,json,html,cshtml}] 24 | indent_size = 2 25 | 26 | # Dotnet & C# code style settings 27 | # See https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference 28 | [*.cs] 29 | 30 | # Avoid "this." and "Me." if not necessary 31 | dotnet_style_qualification_for_field = false:suggestion 32 | dotnet_style_qualification_for_property = false:suggestion 33 | dotnet_style_qualification_for_method = false:suggestion 34 | dotnet_style_qualification_for_event = false:suggestion 35 | 36 | # Use language keywords instead of framework type names for type references 37 | dotnet_style_predefined_type_for_locals_parameters_members = true:warning 38 | dotnet_style_predefined_type_for_member_access = true:suggestion 39 | 40 | # Naming 41 | dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = warning 42 | dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields 43 | dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style 44 | dotnet_naming_rule.camel_case_for_private_internal_fields.severity = warning 45 | dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields 46 | dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style 47 | dotnet_naming_style.camel_case_underscore_style.required_prefix = _ 48 | dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case 49 | dotnet_naming_style.pascal_case_style.capitalization = pascal_case 50 | 51 | # Prefer "var" everywhere 52 | csharp_style_var_for_built_in_types = true:suggestion 53 | csharp_style_var_when_type_is_apparent = true:suggestion 54 | csharp_style_var_elsewhere = true:suggestion 55 | 56 | # Prefer method-like constructs to have a block body 57 | csharp_style_expression_bodied_methods = false:none 58 | csharp_style_expression_bodied_constructors = false:none 59 | csharp_style_expression_bodied_operators = false:none 60 | 61 | # Prefer property-like constructs to have an expression-body 62 | csharp_style_expression_bodied_properties = true:none 63 | csharp_style_expression_bodied_indexers = true:none 64 | csharp_style_expression_bodied_accessors = true:none 65 | 66 | # Spacing 67 | csharp_space_after_cast = false:error 68 | csharp_space_after_colon_in_inheritance_clause = true:error 69 | csharp_space_after_comma = true:error 70 | csharp_space_after_dot = false:error 71 | csharp_space_after_keywords_in_control_flow_statements = true:error 72 | csharp_space_after_semicolon_in_for_statement = true:error 73 | csharp_space_around_binary_operators = before_and_after:error 74 | csharp_space_around_declaration_statements = do_not_ignore:error 75 | csharp_space_before_colon_in_inheritance_clause = true:error 76 | csharp_space_before_comma = false:error 77 | csharp_space_before_dot = false:error 78 | csharp_space_before_open_square_brackets = false:error 79 | csharp_space_before_semicolon_in_for_statement = false:error 80 | csharp_space_between_empty_square_brackets = false:error 81 | csharp_space_between_method_call_empty_parameter_list_parentheses = false:error 82 | csharp_space_between_method_call_name_and_opening_parenthesis = false:error 83 | csharp_space_between_method_call_parameter_list_parentheses = false:error 84 | csharp_space_between_method_declaration_empty_parameter_list_parentheses = false:error 85 | csharp_space_between_method_declaration_name_and_open_parenthesis = false:error 86 | csharp_space_between_method_declaration_parameter_list_parentheses = false:error 87 | csharp_space_between_parentheses = false:error 88 | csharp_space_between_square_brackets = false:error 89 | 90 | # New line 91 | csharp_new_line_before_open_brace = all 92 | csharp_new_line_before_else = true:error 93 | csharp_new_line_before_catch = true:error 94 | csharp_new_line_before_finally = true:error 95 | csharp_new_line_before_members_in_object_initializers = true:error 96 | csharp_new_line_before_members_in_anonymous_types = true:error 97 | csharp_new_line_within_query_expression_clauses = true:error 98 | 99 | # Indentation 100 | csharp_indent_block_contents = true:suggestion 101 | csharp_indent_braces = false:suggestion 102 | csharp_indent_case_contents = true:suggestion 103 | csharp_indent_switch_labels = true:suggestion 104 | csharp_indent_labels = flush_left:suggestion 105 | -------------------------------------------------------------------------------- /CSharp/CSharpStyleguide.ruleset: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /CSharp/README.md: -------------------------------------------------------------------------------- 1 | # C# Style Guide 2 | 3 | Remember that at the end of the day these are only _recommendations_. 4 | 5 | ## Table of Contents 6 | 7 | 1. [Tooling](#tooling) 8 | 1. [General](#general) 9 | 1. [Layout](#layout) 10 | 1. [Spacing](#spacing) 11 | 1. [Ordering](#ordering) 12 | 1. [Naming](#naming) 13 | 1. [Testing Code](#testing-code) 14 | 1. [Acknowledgments](#acknowledgments) 15 | 1. [References](#references) 16 | 17 | ## Tooling 18 | 19 | _Tool configuration_ links only provides the reference to the style for a given tool which doesn't mean that this style guide uses the same recommendation by the tool. 20 | 21 | ### StyleCop 22 | 23 | We include [a ruleset file](CSharpStyleguide.ruleset) for [StyleCop](http://stylecop.soyuz5.com/StyleCop%20Rules.html) where we try to keep the styles matching. 24 | 25 | For this to work you need to add the [NuGet package](https://www.nuget.org/packages/StyleCop.Analyzers/1.0.0) and manually add the ruleset file to each project. 26 | 27 | `..\CSharpStyleguide.ruleset` 28 | 29 | Another thing to consider is that **auto-generated** code (like EF7 migrations) should not be required to comply with these rules. In order to bypass the ruleset, you need to manually add at the top of the file: 30 | 31 | `// ` 32 | 33 | ### EditorConfig 34 | 35 | If you are used to `.editorconfig` files then you can [grab the one we include here](.editorconfig). 36 | 37 | ## General 38 | 39 | ### Use var instead of explicit types 40 | 41 | Tool configuration: 42 | [EditorConfig](https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#var) 43 | 44 | Exceptions are allowed. For more information read [this fantastic post from Eric Lippert](https://blogs.msdn.microsoft.com/ericlippert/2011/04/20/uses-and-misuses-of-implicit-typing/). 45 | 46 | ```csharp 47 | // Bad 48 | HttpClient httpClient = new HttpClient(); 49 | 50 | // Good 51 | var httpClient = new HttpClient(); 52 | 53 | // Allowed for using an interface instead of a class 54 | IUserService userService = new UserService(); 55 | ``` 56 | 57 | ### Don't use explicit *this* reference 58 | 59 | Tool configuration: 60 | [SA1101](http://stylecop.soyuz5.com/SA1101.html) 61 | [EditorConfig](https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#this_and_me) 62 | 63 | It is redundant and does not add for readability. For more information read [this SO post](http://stackoverflow.com/questions/5885249/to-use-or-not-to-use-the-this-qualifier-in-c-sharp). 64 | 65 | ```csharp 66 | // Bad 67 | this.ValidateParameters(); 68 | 69 | // Good 70 | ValidateParameters(); 71 | ``` 72 | 73 | ### Use language built-in alias instead of class names 74 | 75 | Tool configuration: 76 | [SA1121](http://stylecop.soyuz5.com/SA1121.html) 77 | [EditorConfig](https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#language_keywords) 78 | 79 | ```csharp 80 | // Bad 81 | String.IsNullOrEmpty(name); 82 | 83 | // Good 84 | string.IsNullOrEmpty(name); 85 | ``` 86 | 87 | ### Use readonly fields when possible 88 | 89 | ### Prefer string interpolation to *string.Format* 90 | 91 | ```csharp 92 | // Bad 93 | var message = string.Format("My name is {0} {1}.", person.FirstName, person.LastName); 94 | 95 | // Good 96 | var message = $"My name is {person.FirstName} {person.LastName}."; 97 | ``` 98 | 99 | ## Layout 100 | 101 | ### Use *four spaces* per indentation level 102 | 103 | Tool configuration: 104 | [EditorConfig](http://editorconfig.org/#file-format-details) 105 | 106 | You can enable the "View White Space" option and use CTRL+R/CTRL+W keyboard shortcuts. 107 | 108 | ```csharp 109 | // Bad 110 | public void SomeMethod() 111 | { 112 | ∙∙DoSomethingFirst(); 113 | ∙∙DoSomethingLater(); 114 | } 115 | 116 | // Good 117 | public void SomeMethod() 118 | { 119 | ∙∙∙∙DoSomethingFirst(); 120 | ∙∙∙∙DoSomethingLater(); 121 | } 122 | ``` 123 | 124 | ### Don't use more than one empty line in a row 125 | 126 | Tool configuration: 127 | [SA1507](http://stylecop.soyuz5.com/SA1507.html) 128 | 129 | ```csharp 130 | // Bad 131 | public void SomeMethod() 132 | { 133 | DoSomethingFirst(); 134 | DoSomethingLater(); 135 | 136 | 137 | DoSomethingAtTheEnd(); 138 | } 139 | 140 | // Good 141 | public void SomeMethod() 142 | { 143 | DoSomethingFirst(); 144 | DoSomethingLater(); 145 | 146 | DoSomethingAtTheEnd(); 147 | } 148 | ``` 149 | 150 | ### Remove unused or redundant *using* statements (or directives) 151 | 152 | ### Use single line and lambda getters for simple methods and read-only properties 153 | 154 | Tool configuration: 155 | [EditorConfig](https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#expression_bodied_members_properties) 156 | 157 | ```csharp 158 | // Good 159 | public string Name { get; private set; } 160 | 161 | // Good 162 | public string UppercaseName => Name.toUpperCase(); 163 | ``` 164 | 165 | ### Curly braces for multi line statements must not share line 166 | 167 | Tool configuration: 168 | [SA1500](http://stylecop.soyuz5.com/SA1500.html) 169 | 170 | ```csharp 171 | // Bad 172 | public void SomeMethod() { 173 | // ... 174 | } 175 | 176 | // Good 177 | public void SomeMethod() 178 | { 179 | // ... 180 | } 181 | ``` 182 | 183 | ### Opening or ending curly braces must not be followed/preceded by a blank line 184 | 185 | Tool configuration: 186 | [SA1508](http://stylecop.soyuz5.com/SA1508.html) 187 | [SA1509](http://stylecop.soyuz5.com/SA1509.html) 188 | 189 | ```csharp 190 | // Bad 191 | public void SomeMethod() 192 | { 193 | 194 | DoSomethingFirst(); 195 | DoSomethingLater(); 196 | 197 | } 198 | 199 | // Good 200 | public void SomeMethod() 201 | { 202 | DoSomethingFirst(); 203 | DoSomethingLater(); 204 | } 205 | ``` 206 | 207 | ### Don't use braces for just one line 208 | 209 | Tool configuration: 210 | [SA1503](http://stylecop.soyuz5.com/SA1503.html) 211 | 212 | ```csharp 213 | // Bad 214 | if (payment == null) 215 | { 216 | return "A payment is required."; 217 | } 218 | 219 | // Good 220 | if (payment == null) 221 | return "A payment is required."; 222 | ``` 223 | 224 | ## Spacing 225 | 226 | ### Commas must be spaced correctly 227 | 228 | Tool configuration: 229 | [SA1001](http://stylecop.soyuz5.com/SA1001.html) 230 | 231 | A comma should be followed by a single space and never be preceded by any whitespace. 232 | 233 | ```csharp 234 | // Bad 235 | var result = Calculate(3 , 5); 236 | var result = Calculate(3,5); 237 | 238 | // Good 239 | var result = Calculate(3, 5); 240 | ``` 241 | 242 | ### Symbols must be spaced correctly 243 | 244 | Tool configuration: 245 | [SA1003](http://stylecop.soyuz5.com/SA1003.html) 246 | 247 | An operator symbol must be surrounded by a single space on either side. 248 | 249 | ```csharp 250 | // Bad 251 | var result = 5+3; 252 | var result = 5 +3; 253 | var result = 5+ 3; 254 | 255 | // Good 256 | var result = 5 + 3; 257 | ``` 258 | 259 | Except for unary operators: 260 | 261 | ```csharp 262 | // Bad 263 | var result = ! toggle; 264 | 265 | // Good 266 | var result = !toggle; 267 | ``` 268 | 269 | ### Opening parenthesis should not be followed by a space 270 | 271 | Tool configuration: 272 | [SA1008](http://stylecop.soyuz5.com/SA1008.html) 273 | 274 | ```csharp 275 | // Bad 276 | var result = Calculate( 3, 5); 277 | 278 | // Good 279 | var result = Calculate(3, 5); 280 | ``` 281 | 282 | ### Closing parenthesis should not be preceded by a space 283 | 284 | Tool configuration: 285 | [SA1009](http://stylecop.soyuz5.com/SA1009.html) 286 | 287 | ```csharp 288 | // Bad 289 | var result = Calculate(3, 5 ); 290 | 291 | // Good 292 | var result = Calculate(3, 5); 293 | ``` 294 | 295 | ### Opening square brackets should not be preceded or followed by a space 296 | 297 | Tool configuration: 298 | [SA1010](http://stylecop.soyuz5.com/SA1010.html) 299 | 300 | ```csharp 301 | // Bad 302 | var element = myArray [index]; 303 | var element = myArray[ index]; 304 | 305 | // Good 306 | var element = myArray[index]; 307 | ``` 308 | 309 | ### Closing square brackets should not be preceded or followed by a space 310 | 311 | Tool configuration: 312 | [SA1011](http://stylecop.soyuz5.com/SA1011.html) 313 | 314 | ```csharp 315 | // Bad 316 | var element = myArray[index ]; 317 | var element = myArray[index] ; 318 | 319 | // Good 320 | var element = myArray[index]; 321 | ``` 322 | 323 | ### Opening curly brackets should be preceded and followed by a space 324 | 325 | Tool configuration: 326 | [SA1012](http://stylecop.soyuz5.com/SA1012.html) 327 | 328 | ```csharp 329 | // Bad 330 | var names = new string[] {"Marie", "John", "Paul" }; 331 | 332 | // Good 333 | var names = new string[] { "Marie", "John", "Paul" }; 334 | ``` 335 | 336 | ### Closing curly brackets should be preceded and followed by a space 337 | 338 | Tool configuration: 339 | [SA1013](http://stylecop.soyuz5.com/SA1013.html) 340 | 341 | ```csharp 342 | // Bad 343 | var names = new string[] { "Marie", "John", "Paul"}; 344 | 345 | // Good 346 | var names = new string[] { "Marie", "John", "Paul" }; 347 | ``` 348 | 349 | ## Ordering 350 | 351 | ### Within a class, struct, or interface, elements should be ordered 352 | 353 | Tool configuration: 354 | [SA1201](http://stylecop.soyuz5.com/SA1201.html) 355 | 356 | 1. Constants 357 | 1. Fields 358 | 1. Constructors 359 | 1. Delegates 360 | 1. Events 361 | 1. Properties 362 | 1. Methods 363 | 1. Finalizers (Destructors) 364 | 365 | ### Elements should be ordered by access 366 | 367 | Tool configuration: 368 | [SA1202](http://stylecop.soyuz5.com/SA1202.html) 369 | 370 | 1. `public` 371 | 1. `internal` 372 | 1. `protected internal` 373 | 1. `protected` 374 | 1. `private` 375 | 376 | ### It is recommended to follow certain order when using declaration keywords 377 | 378 | Tool configuration: 379 | [SA1206](http://stylecop.soyuz5.com/SA1206.html) 380 | 381 | 1. Access modifiers 382 | 1. `static` 383 | 1. All other keywords 384 | 385 | ```csharp 386 | // Bad 387 | override public int Area() 388 | { 389 | // ... 390 | } 391 | 392 | // Good 393 | public override int Area() 394 | { 395 | // ... 396 | } 397 | ``` 398 | 399 | ```csharp 400 | // Bad 401 | static public void Drive() { } 402 | 403 | // Good 404 | public static void Drive() { } 405 | ``` 406 | 407 | ### It is recommended to order *using* directives alphabetically 408 | 409 | Tool configuration: 410 | [SA1210](http://stylecop.soyuz5.com/SA1210.html) 411 | 412 | ```csharp 413 | // Bad 414 | using System; 415 | using Newtonsoft.Json; 416 | using System.Linq; 417 | using System.Collections.Generic; 418 | 419 | // Good 420 | using Newtonsoft.Json; 421 | using System; 422 | using System.Collections.Generic; 423 | using System.Linq; 424 | ``` 425 | 426 | ## Naming 427 | 428 | ### Be descriptive with your naming, avoid abbreviations and single letter names 429 | 430 | ```csharp 431 | // Bad 432 | var hc = new HttpClient(); 433 | 434 | // Good 435 | var httpClient = new HttpClient(); 436 | ``` 437 | 438 | ```csharp 439 | // Bad 440 | var e = "test@test.com"; 441 | 442 | // Good 443 | var email = "test@test.com"; 444 | ``` 445 | 446 | ### Use *PascalCase* for namespaces, classes, enums, structs, constants, delegates, events, methods and properties 447 | 448 | Tool configuration: 449 | [SA1300](http://stylecop.soyuz5.com/SA1300.html) 450 | [SA1303](http://stylecop.soyuz5.com/SA1303.html) 451 | 452 | ```csharp 453 | // Bad 454 | public class file_reader 455 | { 456 | // ... 457 | } 458 | 459 | // Good 460 | public class FileReader 461 | { 462 | // ... 463 | } 464 | ``` 465 | 466 | ```csharp 467 | // Bad 468 | public const int TIME_IN_SECONDS = 5; 469 | 470 | // Good 471 | public const int TimeInSeconds = 5; 472 | ``` 473 | 474 | ```csharp 475 | // Bad 476 | public string secondAddress { get; set; } 477 | 478 | // Good 479 | public string SecondAddress { get; set; } 480 | ``` 481 | 482 | ### Use *camelCase* for variables 483 | 484 | ```csharp 485 | // Bad 486 | var FileReader = new FileReader(); 487 | var file_reader = new FileReader(); 488 | var _fileReader = new FileReader(); 489 | 490 | // Good 491 | var fileReader = new FileReader(); 492 | ``` 493 | 494 | ### Use *_underscoreCase* for private instance/static fields 495 | 496 | Tool configuration: 497 | [SA1309](http://stylecop.soyuz5.com/SA1309.html) 498 | 499 | ```csharp 500 | // Bad 501 | private IUserService UserService; 502 | private IUserService userService; 503 | private IUserService user_service; 504 | 505 | // Good 506 | private IUserService _userService; 507 | ``` 508 | 509 | ### Interface names must begin with "I" 510 | 511 | Tool configuration: 512 | [SA1302](http://stylecop.soyuz5.com/SA1302.html) 513 | 514 | ```csharp 515 | // Bad 516 | public interface LoggerInterface 517 | { 518 | // ... 519 | } 520 | 521 | // Good 522 | public interface ILogger 523 | { 524 | // ... 525 | } 526 | ``` 527 | 528 | ### Include *Async* suffix on async methods 529 | 530 | ```csharp 531 | // Bad 532 | public async Task GetLatestPosition() 533 | { 534 | // ... 535 | } 536 | 537 | // Good 538 | public async Task GetLatestPositionAsync() 539 | { 540 | // ... 541 | } 542 | ``` 543 | 544 | ## Testing Code 545 | 546 | We all know testing code is not built the same way that regular code is, because its purpose is different. This is why we have special guidelines for this type of code. 547 | 548 | ### Test Class naming: {TargetTestClass}Tests 549 | 550 | ```csharp 551 | // Bad 552 | namespace MyProject 553 | { 554 | [TestClass] 555 | public class MyService 556 | { } 557 | } 558 | 559 | // Good 560 | namespace MyProject 561 | { 562 | [TestClass] 563 | public class MyServiceTests 564 | { } 565 | } 566 | ``` 567 | 568 | ### Test Class Location: keep a correspondence with the code being tested 569 | 570 | Use the same folder structure / namespace structure as the code that's being tested. This makes it easier to find test classes for a particular class and classes being tested by a particular test class. 571 | 572 | ### Method naming: {TargetTestMethod}_{Expectation}[_When{Condition}] 573 | 574 | The name needs to express: 575 | 576 | - **What** is being tested 577 | - **What** should happen. 578 | - Under **which** conditions. 579 | 580 | What is being tested will usually be a particular method. (These are unit tests, after all.) For integration tests, there is more freedom in choosing this portion, but should still be a good name indicating the scenario being tested. 581 | 582 | What should happen should be concise and to the point. Avoid _should_ or _must_ or expressions of rule/desire. The test itself is that validation, there's no need to specify it. 583 | 584 | The conditions can be avoided if "normal" conditions are easy to assume and they're the one being tested. For example, a "must work under regular conditions" test says nothing. A good name would be "SaveToDatabase_PersistsChanges" 585 | 586 | ```csharp 587 | // Bad: Uses filler words 588 | public void SaveToDatabase_ShouldPersistChanges() { } 589 | 590 | // Bad: does not correctly indicate responsibility 591 | public void SaveToDatabase_Works() { } 592 | 593 | // Good 594 | public void SaveToDatabase_PersistsChanges() { } 595 | 596 | // Also good 597 | public void SaveToDatabase_ThrowsArgumentException_WhenConnectionStringIsNotPresent() { } 598 | ``` 599 | 600 | ### Group tests by test target 601 | 602 | We generally avoid using `#region` since it is a symptom of poorly designed code. However, tests classes are likely to grow if the same class handles several scenarios to be tested, or if several methods are exposed. Group them by the method being tested. 603 | 604 | Include overloaded versions of methods in the same region. 605 | 606 | ```csharp 607 | #region SaveToDatabase 608 | public void SaveToDatabase_PersistsChanges() { } 609 | 610 | public void SaveToDatabase_ThrowsArgumentException_WhenConnectionStringIsNotPresent() { } 611 | #endregion 612 | 613 | #region RetrieveFromDatabase 614 | public void RetrieveFromDatabase_RetrievesClientById() { } 615 | 616 | public void RetrieveFromDatabase_RetrievesClientsByName() { } 617 | 618 | public void RetrieveFromDatabase_ThrowsArgumentOutOfRangeException_WhenIdIsEmptyGuid() { } 619 | #endregion 620 | ``` 621 | 622 | ## Acknowledgments 623 | 624 | Thank you to all who contributed to any of the styles in this document or mentioned references. 625 | 626 | ## References 627 | 628 | - [StyleCop](http://stylecop.soyuz5.com/StyleCop%20Rules.html) 629 | - [Roslyn](https://github.com/dotnet/roslyn) 630 | - [CoreFX C# Coding Style](https://github.com/dotnet/corefx/blob/master/Documentation/coding-guidelines/coding-style.md) 631 | - [Microsoft C# Coding Conventions](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/inside-a-program/coding-conventions) 632 | - [Framework Design Guidelines](https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/index) 633 | - [Ruby Style Guide by bbatsov](https://github.com/bbatsov/ruby-style-guide) 634 | - [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript) 635 | -------------------------------------------------------------------------------- /Java/intellij-java-google-style.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 15 | 21 | 28 | 599 | -------------------------------------------------------------------------------- /Javascript(ES5)/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "parserOptions": { 3 | "ecmaVersion": 5, 4 | "sourceType": "script" 5 | }, 6 | "rules": { 7 | "no-new-object": ["error"], 8 | "quote-props": ["error", "as-needed"], 9 | "no-array-constructor": ["error"], 10 | "array-callback-return": ["error"], 11 | "quotes": ["error", "single", { "avoidEscape": true }], 12 | "no-useless-escape": ["error"], 13 | "func-style": ["warn", "expression"], 14 | "wrap-iife": ["error", "outside"], 15 | "no-loop-func": ["error"], 16 | "no-new-func": ["error"], 17 | "space-before-function-paren": ["error", "never"], 18 | "space-before-blocks": ["error", "always"], 19 | "no-param-reassign": ["error", { "props": false }], 20 | "no-restricted-syntax": ["error", "WithStatement"], 21 | "dot-notation": ["error", { "allowKeywords": false }], 22 | "no-undef": ["error", { "typeof": true }], 23 | "one-var": ["error", "never"], 24 | "no-plusplus": ["error", { "allowForLoopAfterthoughts": false }], 25 | "eqeqeq": ["error", "always"], 26 | "no-case-declarations": ["error"], 27 | "no-nested-ternary": ["error"], 28 | "no-unneeded-ternary": ["error", { "defaultAssignment": false }], 29 | "brace-style": ["error", "1tbs"], 30 | "spaced-comment": ["error", "always"], 31 | "indent": ["error", 2], 32 | "keyword-spacing": ["error", { "before": true, "after": true }], 33 | "space-infix-ops": ["error", { "int32Hint": true }], 34 | "eol-last": ["error", "always"], 35 | "newline-per-chained-call": ["error", { "ignoreChainWithDepth": 1 }], 36 | "padded-blocks": ["error", "never"], 37 | "space-in-parens": ["error", "never"], 38 | "array-bracket-spacing": ["error", "never"], 39 | "object-curly-spacing": ["error", "always"], 40 | "max-len": ["error", { "code": 100, "ignoreUrls": true }], 41 | "comma-style": ["error", "last"], 42 | "comma-dangle": ["error", "never"], 43 | "semi": ["error", "always"], 44 | "radix": ["error", "always"], 45 | "id-length": ["warn", { "min": 2, "properties": "never" }], 46 | "camelcase": ["error", { "properties": "always" }], 47 | "new-cap": ["error", { "newIsCap": true, "capIsNew": false, "properties": true }], 48 | "no-underscore-dangle": ["error", { "allowAfterThis": false, "allowAfterSuper": false }] 49 | } 50 | } -------------------------------------------------------------------------------- /Javascript(ES6)/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "parserOptions": { 3 | "ecmaVersion": 6, 4 | "sourceType": "module", 5 | "ecmaFeatures": { 6 | "modules": true 7 | } 8 | }, 9 | "plugins": [ 10 | "import" 11 | ], 12 | "rules": { 13 | "prefer-const": ["error", { "destructuring": "any", "ignoreReadBeforeAssign": false }], 14 | "no-const-assign": ["error"], 15 | "no-var": ["error"], 16 | "no-new-object": ["error"], 17 | "object-shorthand": ["error", "always"], 18 | "quote-props": ["error", "as-needed"], 19 | "no-array-constructor": ["error"], 20 | "array-callback-return": ["error"], 21 | "quotes": ["error", "single", { "avoidEscape": true }], 22 | "prefer-template": ["warn"], 23 | "template-curly-spacing": ["error", "never"], 24 | "no-useless-escape": ["error"], 25 | "func-style": ["warn", "expression"], 26 | "wrap-iife": ["error", "outside"], 27 | "no-loop-func": ["error"], 28 | "prefer-rest-params": ["error"], 29 | "no-new-func": ["error"], 30 | "space-before-function-paren": ["error", "never"], 31 | "space-before-blocks": ["error", "always"], 32 | "no-param-reassign": ["error", { "props": true }], 33 | "prefer-spread": ["error"], 34 | "prefer-arrow-callback": ["error", { "allowNamedFunctions": false, "allowUnboundThis": false }], 35 | "arrow-spacing": ["error", { "before": true, "after": true }], 36 | "arrow-parens": ["warn", "as-needed"], 37 | "arrow-body-style": ["error", "as-needed"], 38 | "no-confusing-arrow": ["error", { "allowParens": true }], 39 | "no-useless-constructor": ["error"], 40 | "no-dupe-class-members": ["error"], 41 | "no-duplicate-imports": ["error"], 42 | "import/no-mutable-exports": ["error", "always"], 43 | "import/prefer-default-export": ["error", "always"], 44 | "import/first": ["error", "always"], 45 | "import/no-webpack-loader-syntax": ["error", "always"], 46 | "no-iterator": ["error"], 47 | "no-restricted-syntax": ["error", "WithStatement"], 48 | "generator-star-spacing": ["error", { "before": false, "after": true }], 49 | "dot-notation": ["error", { "allowKeywords": false }], 50 | "no-undef": ["error", { "typeof": true }], 51 | "one-var": ["error", "never"], 52 | "no-plusplus": ["error", { "allowForLoopAfterthoughts": false }], 53 | "eqeqeq": ["error", "always"], 54 | "no-case-declarations": ["error"], 55 | "no-nested-ternary": ["error"], 56 | "no-unneeded-ternary": ["error", { "defaultAssignment": false }], 57 | "brace-style": ["error", "1tbs"], 58 | "spaced-comment": ["error", "always"], 59 | "indent": ["error", 2], 60 | "keyword-spacing": ["error", { "before": true, "after": true }], 61 | "space-infix-ops": ["error", { "int32Hint": true }], 62 | "eol-last": ["error", "always"], 63 | "newline-per-chained-call": ["error", { "ignoreChainWithDepth": 1 }], 64 | "padded-blocks": ["error", "never"], 65 | "space-in-parens": ["error", "never"], 66 | "array-bracket-spacing": ["error", "never"], 67 | "object-curly-spacing": ["error", "always"], 68 | "max-len": ["error", { "code": 100, "ignoreUrls": true }], 69 | "comma-style": ["error", "last"], 70 | "comma-dangle": ["error", "only-multiline"], 71 | "semi": ["error", "always"], 72 | "radix": ["error", "always"], 73 | "id-length": ["warn", { "min": 2, "properties": "never" }], 74 | "camelcase": ["error", { "properties": "always" }], 75 | "new-cap": ["error", { "newIsCap": true, "capIsNew": false, "properties": true }], 76 | "no-underscore-dangle": ["error", { "allowAfterThis": false, "allowAfterSuper": false }], 77 | "prefer-destructuring": ["warn", { "array": true, "object": true }, { "enforceForRenamedProperties": false }], 78 | "no-prototype-builtins": ["warn"], 79 | "no-eval": ["error", { "allowIndirect": false }], 80 | "no-multiple-empty-lines": ["error", { "max": 1, "maxEOF": 1, "maxBOF": 1 }], 81 | "no-trailing-spaces": ["error", { "skipBlankLines": false }], 82 | "no-implicit-coercion": ["error", { "boolean": false, "number": true, "string": true }], 83 | "consistent-this": ["error"] 84 | } 85 | } -------------------------------------------------------------------------------- /NodeJs/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "node": true 4 | }, 5 | "rules": { 6 | "block-scoped-var": 2, 7 | "brace-style": [2, "1tbs"], 8 | "camelcase": 1, 9 | "curly": 2, 10 | "eol-last": 2, 11 | "eqeqeq": [2, "smart"], 12 | "max-depth": [1, 3], 13 | "max-statements": [1, 15], 14 | "max-len": [1, 80], 15 | "new-cap": 1, 16 | "no-extend-native": 2, 17 | "no-mixed-spaces-and-tabs": 2, 18 | "no-trailing-spaces": 2, 19 | "no-use-before-define": [2, "nofunc"], 20 | "no-unused-vars": 1, 21 | "quotes": [2, "single", "avoid-escape"], 22 | "semi": [2, "always"], 23 | "space-after-keywords": [2, "always"], 24 | "space-in-brackets": [2, "never"], 25 | "space-unary-word-ops": 2 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /NodeJs/.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "camelcase": true, 3 | "curly": true, 4 | "eqeqeq": true, 5 | "freeze": true, 6 | "indent": 2, 7 | "newcap": true, 8 | "quotmark": "single", 9 | "maxdepth": 3, 10 | "maxstatements": 15, 11 | "maxlen": 80, 12 | "eqnull": true, 13 | "funcscope": true, 14 | "node": true 15 | } 16 | -------------------------------------------------------------------------------- /NodeJs/Readme.md: -------------------------------------------------------------------------------- 1 | (Adapted from [node-style-guide](https://github.com/felixge/node-style-guide)) 2 | 3 | # Node.js Style Guide 4 | 5 | This is a guide for writing consistent and aesthetically pleasing node.js code. 6 | It is inspired by what is popular within the community, and flavored with some 7 | personal opinions. 8 | 9 | There is a .jshintrc which enforces these rules as closely as possible. You can 10 | either use that and adjust it, or use 11 | [this script](https://gist.github.com/kentcdodds/11293570) to make your own. 12 | 13 | This guide was created by [Felix Geisendörfer](http://felixge.de/) and is 14 | licensed under the [CC BY-SA 3.0](http://creativecommons.org/licenses/by-sa/3.0/) 15 | license. You are encouraged to fork this repository and make adjustments 16 | according to your preferences. 17 | 18 | ![Creative Commons License](http://i.creativecommons.org/l/by-sa/3.0/88x31.png) 19 | 20 | ## 2 Spaces for indentation 21 | 22 | Use 2 spaces for indenting your code and swear an oath to never mix tabs and 23 | spaces - a special kind of hell is awaiting you otherwise. 24 | 25 | ## Newlines 26 | 27 | Use UNIX-style newlines (`\n`), and a newline character as the last character 28 | of a file. Windows-style newlines (`\r\n`) are forbidden inside any repository. 29 | 30 | ## No trailing whitespace 31 | 32 | Just like you brush your teeth after every meal, you clean up any trailing 33 | whitespace in your JS files before committing. Otherwise the rotten smell of 34 | careless neglect will eventually drive away contributors and/or co-workers. 35 | 36 | ## Use Semicolons 37 | 38 | According to [scientific research][hnsemicolons], the usage of semicolons is 39 | a core value of our community. Consider the points of [the opposition][], but 40 | be a traditionalist when it comes to abusing error correction mechanisms for 41 | cheap syntactic pleasures. 42 | 43 | [the opposition]: http://blog.izs.me/post/2353458699/an-open-letter-to-javascript-leaders-regarding 44 | [hnsemicolons]: http://news.ycombinator.com/item?id=1547647 45 | 46 | ## 80 characters per line 47 | 48 | Limit your lines to 80 characters. Yes, screens have gotten much bigger over the 49 | last few years, but your brain has not. Use the additional room for split screen, 50 | your editor supports that, right? 51 | 52 | ## Use single quotes 53 | 54 | Use single quotes, unless you are writing JSON. 55 | 56 | *Right:* 57 | 58 | ```js 59 | var foo = 'bar'; 60 | ``` 61 | 62 | *Wrong:* 63 | 64 | ```js 65 | var foo = "bar"; 66 | ``` 67 | 68 | ## Opening braces go on the same line 69 | 70 | Your opening braces go on the same line as the statement. 71 | 72 | *Right:* 73 | 74 | ```js 75 | if (true) { 76 | console.log('winning'); 77 | } 78 | ``` 79 | 80 | *Wrong:* 81 | 82 | ```js 83 | if (true) 84 | { 85 | console.log('losing'); 86 | } 87 | ``` 88 | 89 | Also, notice the use of whitespace before and after the condition statement. 90 | 91 | ## Declare one variable per var statement 92 | 93 | Declare one variable per var statement, it makes it easier to re-order the 94 | lines. However, ignore [Crockford][crockfordconvention] when it comes to 95 | declaring variables deeper inside a function, just put the declarations wherever 96 | they make sense. 97 | 98 | *Right:* 99 | 100 | ```js 101 | var keys = ['foo', 'bar']; 102 | var values = [23, 42]; 103 | 104 | var object = {}; 105 | while (keys.length) { 106 | var key = keys.pop(); 107 | object[key] = values.pop(); 108 | } 109 | ``` 110 | 111 | *Wrong:* 112 | 113 | ```js 114 | var keys = ['foo', 'bar'], 115 | values = [23, 42], 116 | object = {}, 117 | key; 118 | 119 | while (keys.length) { 120 | key = keys.pop(); 121 | object[key] = values.pop(); 122 | } 123 | ``` 124 | 125 | [crockfordconvention]: http://javascript.crockford.com/code.html 126 | 127 | ## Use lowerCamelCase for variables, properties and function names 128 | 129 | Variables, properties and function names should use `lowerCamelCase`. They 130 | should also be descriptive. Single character variables and uncommon 131 | abbreviations should generally be avoided. 132 | 133 | *Right:* 134 | 135 | ```js 136 | var adminUser = db.query('SELECT * FROM users ...'); 137 | ``` 138 | 139 | *Wrong:* 140 | 141 | ```js 142 | var admin_user = db.query('SELECT * FROM users ...'); 143 | ``` 144 | 145 | ## Use UpperCamelCase for class names 146 | 147 | Class names should be capitalized using `UpperCamelCase`. 148 | 149 | *Right:* 150 | 151 | ```js 152 | function BankAccount() { 153 | } 154 | ``` 155 | 156 | *Wrong:* 157 | 158 | ```js 159 | function bank_Account() { 160 | } 161 | ``` 162 | 163 | ## Use UPPERCASE for Constants 164 | 165 | Constants should be declared as regular variables or static class properties, 166 | using all uppercase letters. 167 | 168 | Node.js / V8 actually supports mozilla's [const][const] extension, but 169 | unfortunately that cannot be applied to class members, nor is it part of any 170 | ECMA standard. 171 | 172 | *Right:* 173 | 174 | ```js 175 | const SECOND = 1 * 1000; 176 | 177 | function File() { 178 | } 179 | File.FULL_PERMISSIONS = 0777; 180 | ``` 181 | 182 | *Wrong:* 183 | 184 | ```js 185 | const SECOND = 1 * 1000; 186 | 187 | function File() { 188 | } 189 | File.fullPermissions = 0777; 190 | ``` 191 | 192 | [const]: https://developer.mozilla.org/en/JavaScript/Reference/Statements/const 193 | 194 | ## Object / Array creation 195 | 196 | Use trailing commas and put *short* declarations on a single line. Only quote 197 | keys when your interpreter complains: 198 | 199 | *Right:* 200 | 201 | ```js 202 | var a = ['hello', 'world']; 203 | var b = { 204 | good: 'code', 205 | 'is generally': 'pretty', 206 | }; 207 | ``` 208 | 209 | *Wrong:* 210 | 211 | ```js 212 | var a = [ 213 | 'hello', 'world' 214 | ]; 215 | var b = {"good": 'code' 216 | , is generally: 'pretty' 217 | }; 218 | ``` 219 | 220 | ## Use the === operator 221 | 222 | Programming is not about remembering [stupid rules][comparisonoperators]. Use 223 | the triple equality operator as it will work just as expected. 224 | 225 | *Right:* 226 | 227 | ```js 228 | var a = 0; 229 | if (a !== '') { 230 | console.log('winning'); 231 | } 232 | 233 | ``` 234 | 235 | *Wrong:* 236 | 237 | ```js 238 | var a = 0; 239 | if (a == '') { 240 | console.log('losing'); 241 | } 242 | ``` 243 | 244 | [comparisonoperators]: https://developer.mozilla.org/en/JavaScript/Reference/Operators/Comparison_Operators 245 | 246 | ## Use single-line ternary operator 247 | 248 | Ternaries should not be nested and generally be single line expressions. 249 | 250 | *Right:* 251 | 252 | ```js 253 | var foo = (a === b) ? 1 : 2; 254 | ``` 255 | 256 | *Wrong:* 257 | 258 | ```js 259 | var foo = (a === b) 260 | ? 1 261 | : 2; 262 | ``` 263 | 264 | Also, avoid unneeded ternary statements. 265 | 266 | *Right:* 267 | 268 | ```js 269 | var foo = a || b; 270 | var bar = !!c; 271 | var baz = !c; 272 | ``` 273 | 274 | *Wrong:* 275 | 276 | ```js 277 | var foo = a ? a : b; 278 | var bar = c ? true : false; 279 | var baz = c ? false : true; 280 | ``` 281 | 282 | Avoid side effects in ternary comparisons. Prefer if statements in cases like that. Side effects written in a single line disrupt the rythym of code reading for other developers. Furthermore, if you happen to be debugging line-by-line, side effects in ternary are difficult to work with. 283 | 284 | *Right:* 285 | 286 | ```js 287 | if (shouldBeVisible) 288 | show(); 289 | else 290 | hide(); 291 | 292 | a += 1; 293 | var isAPositive = a > 0; 294 | var aDoubled = a * 2; 295 | var myResult = isAPositive ? aDoubled : a; 296 | ``` 297 | 298 | *Wrong:* 299 | 300 | ```js 301 | shouldBeVisible ? show() : hide(); 302 | 303 | var myResult = (a += 1 > 0) ? a *= 2 : a; 304 | ``` 305 | 306 | ## Do not extend built-in prototypes 307 | 308 | Do not extend the prototype of native JavaScript objects. Your future self will 309 | be forever grateful. 310 | 311 | *Right:* 312 | 313 | ```js 314 | var a = []; 315 | if (!a.length) { 316 | console.log('winning'); 317 | } 318 | ``` 319 | 320 | *Wrong:* 321 | 322 | ```js 323 | Array.prototype.empty = function() { 324 | return !this.length; 325 | } 326 | 327 | var a = []; 328 | if (a.empty()) { 329 | console.log('losing'); 330 | } 331 | ``` 332 | 333 | ## Use descriptive conditions 334 | 335 | Any non-trivial conditions should be assigned to a descriptively named variable or function: 336 | 337 | *Right:* 338 | 339 | ```js 340 | var isValidPassword = password.length >= 4 && /^(?=.*\d).{4,}$/.test(password); 341 | 342 | if (isValidPassword) { 343 | console.log('winning'); 344 | } 345 | ``` 346 | 347 | *Wrong:* 348 | 349 | ```js 350 | if (password.length >= 4 && /^(?=.*\d).{4,}$/.test(password)) { 351 | console.log('losing'); 352 | } 353 | ``` 354 | 355 | ## Write small functions 356 | 357 | Keep your functions short. A good function fits on a slide that the people in 358 | the last row of a big room can comfortably read. So don't count on them having 359 | perfect vision and limit yourself to ~15 lines of code per function. 360 | 361 | ## Return early from functions 362 | 363 | To avoid deep nesting of if-statements, always return a function's value as early 364 | as possible. 365 | 366 | *Right:* 367 | 368 | ```js 369 | function isPercentage(val) { 370 | if (val < 0) { 371 | return false; 372 | } 373 | 374 | if (val > 100) { 375 | return false; 376 | } 377 | 378 | return true; 379 | } 380 | ``` 381 | 382 | *Wrong:* 383 | 384 | ```js 385 | function isPercentage(val) { 386 | if (val >= 0) { 387 | if (val < 100) { 388 | return true; 389 | } else { 390 | return false; 391 | } 392 | } else { 393 | return false; 394 | } 395 | } 396 | ``` 397 | 398 | Or for this particular example it may also be fine to shorten things even 399 | further: 400 | 401 | ```js 402 | function isPercentage(val) { 403 | var isInRange = (val >= 0 && val <= 100); 404 | return isInRange; 405 | } 406 | ``` 407 | 408 | ## Name your closures 409 | 410 | Feel free to give your closures a name. It shows that you care about them, and 411 | will produce better stack traces, heap and cpu profiles. 412 | 413 | *Right:* 414 | 415 | ```js 416 | req.on('end', function onEnd() { 417 | console.log('winning'); 418 | }); 419 | ``` 420 | 421 | *Wrong:* 422 | 423 | ```js 424 | req.on('end', function() { 425 | console.log('losing'); 426 | }); 427 | ``` 428 | 429 | ## No nested closures 430 | 431 | Use closures, but don't nest them. Otherwise your code will become a mess. 432 | 433 | *Right:* 434 | 435 | ```js 436 | setTimeout(function() { 437 | client.connect(afterConnect); 438 | }, 1000); 439 | 440 | function afterConnect() { 441 | console.log('winning'); 442 | } 443 | ``` 444 | 445 | *Wrong:* 446 | 447 | ```js 448 | setTimeout(function() { 449 | client.connect(function() { 450 | console.log('losing'); 451 | }); 452 | }, 1000); 453 | ``` 454 | 455 | ## Use slashes for comments 456 | 457 | Use slashes for both single line and multi line comments. Try to write 458 | comments that explain higher level mechanisms or clarify difficult 459 | segments of your code. Don't use comments to restate trivial things. 460 | 461 | *Right:* 462 | 463 | ```js 464 | // 'ID_SOMETHING=VALUE' -> ['ID_SOMETHING=VALUE', 'SOMETHING', 'VALUE'] 465 | var matches = item.match(/ID_([^\n]+)=([^\n]+)/)); 466 | 467 | // This function has a nasty side effect where a failure to increment a 468 | // redis counter used for statistics will cause an exception. This needs 469 | // to be fixed in a later iteration. 470 | function loadUser(id, cb) { 471 | // ... 472 | } 473 | 474 | var isSessionValid = (session.expires < Date.now()); 475 | if (isSessionValid) { 476 | // ... 477 | } 478 | ``` 479 | 480 | *Wrong:* 481 | 482 | ```js 483 | // Execute a regex 484 | var matches = item.match(/ID_([^\n]+)=([^\n]+)/)); 485 | 486 | // Usage: loadUser(5, function() { ... }) 487 | function loadUser(id, cb) { 488 | // ... 489 | } 490 | 491 | // Check if the session is valid 492 | var isSessionValid = (session.expires < Date.now()); 493 | // If the session is valid 494 | if (isSessionValid) { 495 | // ... 496 | } 497 | ``` 498 | 499 | ## Object.freeze, Object.preventExtensions, Object.seal, with, eval 500 | 501 | Crazy shit that you will probably never need. Stay away from it. 502 | -------------------------------------------------------------------------------- /React/Courses/README.md: -------------------------------------------------------------------------------- 1 | ### React Basics 2 | * [React fundamentals](https://tylermcginnis.com/courses/react-fundamentals/): this is a really good course if you want to start learning React from scratch. The code is up to date with the latest React version. 3 | * [ReactJS Getting Started](https://app.pluralsight.com/library/courses/react-js-getting-started/table-of-contents): learn the basics of React.js, and build an in-browser, math skills kids' game from scratch with it. 4 | * [React Fundamentals - Pluralsight](https://app.pluralsight.com/library/courses/react-fundamentals/table-of-contents): react is a high-performance, reactive UI library for client-side web applications. 5 | * [Start Using React to Build Web Applications](https://egghead.io/courses/start-using-react-to-build-web-applications): this course explore the basic fundamentals for React. You will need to take another course after this one, since doesn´t contains much information about Flux or Redux, is just about basic React components and structure 6 | * [ReactJS Training - Making Sense](https://github.com/makingsensetraining/ReactJS-Training): our developer Juan Pablo Cook created this useful wiki that contains the code for some Pluralsight courses 7 | * [React.js Program - React.js Fundamentals](http://courses.reactjsprogram.com/courses/reactjsfundamentals) 8 | * [React for Beginners](https://reactforbeginners.com/) 9 | 10 | ### React Advanced 11 | * [Build Virtual Reality Experiences Using React VR](https://egghead.io/courses/build-virtual-reality-experiences-using-react-vr) 12 | * [Advanced React](https://www.pluralsight.com/courses/reactjs-advanced): Take a deep dive into full-stack JavaScript with React.js and learn advanced concepts like the context API, HOCs, external state, performance optimization, asynchronous APIs, testing, deployment, and more. 13 | 14 | 15 | ### Redux 16 | * [Getting started with Redux](https://egghead.io/courses/getting-started-with-redux): once you learn the basis, you can take a look to this one that contains all the information about using Redux with React 17 | * [Learn Redux](https://learnredux.com/): you can take this course if you already know about React fundaments or not. It will go into React, React router and Redux 18 | * [Building Applications with React and Redux in ES6](https://app.pluralsight.com/library/courses/react-redux-react-router-es6/table-of-contents): learn how to use Redux, React Router, and ES6 to build a real world app with React. Use Webpack, Babel, ESLint, npm scripts, Mocha, Enzyme, and more to build a rich, one step, custom React development environment and build process from the ground up. 19 | * [Building React Applications with Idiomatic Redux - Video Series](Building React Applications with Idiomatic Redux - Video Series 20 | https://egghead.io/series/building-react-applications-with-idiomatic-redux) 21 | * [How to Use the React-Redux package](http://code.tutsplus.com/tutorials/how-to-use-the-react-redux-package--cms-27150) 22 | * [Interactive Frontend Development with React and Redux](https://courses.cs.ut.ee/2016/react/spring/Main/Lectures) 23 | -------------------------------------------------------------------------------- /React/Documentation/README.md: -------------------------------------------------------------------------------- 1 | ### React Documentation 2 | * [Official React documentation](https://facebook.github.io/react/) 3 | * [React Github repository](https://github.com/facebook/react/tree/master/docs) 4 | * [Original FB talk](https://www.youtube.com/watch?v=nYkdrAPrdcw) 5 | * [React DevTools](https://github.com/facebook/react-devtools) 6 | * [React Community GitHub](https://github.com/reactjs) 7 | * [30 Days of React](https://www.fullstackreact.com/30-days-of-react/) 8 | * [Learn React From Your Browser: Introducing React](https://reactarmory.com/guides/learn-react-by-itself) 9 | * [React: Getting Started and Concepts](https://scotch.io/tutorials/learning-react-getting-started-and-concepts) 10 | * [React.js Tutorial and Guide to the Gotchas](https://zapier.com/engineering/react-js-tutorial-guide-gotchas/) 11 | * [Build with React](http://buildwithreact.com/#articles) 12 | 13 | ### React Server Side Rendering 14 | * [Server-side React rendering](https://css-tricks.com/server-side-react-rendering/) 15 | * [Client-side vs. server-side rendering: why it’s not all black and white](https://medium.freecodecamp.org/what-exactly-is-client-side-rendering-and-hows-it-different-from-server-side-rendering-bd5c786b340d) 16 | 17 | ### React Components 18 | * [React elements vs components](https://tylermcginnis.com/react-elements-vs-react-components/) 19 | * [React Components, Elements, and Instances](https://facebook.github.io/react/blog/2015/12/18/react-components-elements-and-instances.html) 20 | 21 | * [React components lifecycle](http://javascript.tutorialhorizon.com/2014/09/13/execution-sequence-of-a-react-components-lifecycle-methods/) 22 | * [React lifecycle cheatsheet](https://gist.github.com/bvaughn/923dffb2cd9504ee440791fade8db5f9) 23 | * [React In-Depth: The React Life Cycle](https://developmentarc.gitbooks.io/react-indepth/content/) 24 | 25 | ### React Events 26 | * [Events in React](https://docs.google.com/a/makingsense.com/presentation/d/1wAmH5RrOTcpG3P8YcjO29LdrgigadE3gUrt2nqFo03U/edit?usp=sharing) 27 | * [Handling Events in React](https://appendto.com/2017/01/react-events-101/) 28 | * [Everything About Events](https://reactarmory.com/guides/learn-react-by-itself/inputs-and-events) 29 | * [Normalize Events with Reacts Synthetic Event System](https://egghead.io/lessons/react-react-synthetic-event-system) 30 | * [Events Handling](http://www.react.express/event_handling) 31 | 32 | ### React Forms 33 | * [React Docs: Forms](https://facebook.github.io/react/docs/forms.html) 34 | * [React "controlled" vs "uncontrolled" inputs](https://gist.github.com/markerikson/d71cfc81687f11609d2559e8daee10cc) 35 | * [React Form Components](http://donavon.js.org/react-forms/) 36 | * [ReactJS and controlled forms](http://leftdevel.com/blog/reactjs-controlled-forms/) 37 | * [React Forms: Using Refs](https://css-tricks.com/react-forms-using-refs/) 38 | * [Forms in React and Redux](http://x-team.com/2016/02/tutorial-forms-in-react-and-redux/) 39 | * [Making dynamic form inputs with React](https://goshakkk.name/array-form-inputs/) 40 | 41 | ### React Native 42 | * [React Native: Bringing modern web techniques to mobile](https://code.facebook.com/posts/1014532261909640/react-native-bringing-modern-web-techniques-to-mobile/) 43 | * [React native official documentation](https://code.facebook.com/posts/1014532261909640/react-native-bringing-modern-web-techniques-to-mobile/) 44 | * [Create-react-native-app](https://github.com/react-community/create-react-native-app) 45 | * [React Native Express](http://www.reactnativeexpress.com/) 46 | * [React Native Workshop](https://rangle-io.gitbooks.io/react-native-workshop/content/) 47 | 48 | ### React Drag & Drop 49 | * [DragDropContainer and DropTarget](https://github.com/peterh32/react-drag-drop-container) 50 | * [React Sortable (HOC)](https://github.com/clauderic/react-sortable-hoc) 51 | 52 | ### React Router 53 | * [React Router Repository](https://github.com/rackt/react-router) 54 | * [React Router Official Documentation](https://rackt.github.io/react-router/) 55 | 56 | ### React Chart 57 | | Type | Library | Pros | Cons | Cost | Demo 58 | | ------------- |:------------- |:------------- |:------------- |:-------------:|:-------------:| 59 | | CHART | [React D3](http://www.reactd3.org/) | * Reusable components
* Interactive features, like zoom and tooltips
Good github repo with examples
* Based on D3 | * There is no component for each chart, just generic components for the chart parts
* Didn't say anything about CSS changes and UI customization of the charts
* Not mantained anymore | MIT license | | 60 | | CHART | [Rechart](http://recharts.org/) | * Already have lot of components for different type of chart
* Components for interactive features
* Easy way to customize CSS properties
* Active repository with good response for issues
* Based on D3 | * No example of how to create a new chart based on the existing componentse | MIT license | http://recharts.org/#/en-US/examples | 61 | | CHART | [Victory](https://github.com/FormidableLabs/victory) | | | MIT license | http://recharts.org/#/en-US/examples | 62 | | CHART | [react-d3-component](https://github.com/codesuki/react-d3-components) | | | MIT license | http://codesuki.github.io/react-d3-components/example.htmls | 63 | | CHART | [react-highcharts](https://github.com/kirjs/react-highcharts) | * Reknown chart library
* Complex visualizations allowed | * Low community participation (propietary development)
* Non-react native (based in jQuery, might be troublesome)
* React port is done by individual,not backed up by HighCharts | $5K/year (10+ devs) | http://kirjs.github.io/react-highcharts/ | 64 | | SLIDER | [rc-slider](https://github.com/react-component/slider) | * Active Supports IE9, IE9+, Chrome, Firefox & Safari | | MIT license | http://react-component.github.io/slider/examples/handle.html | 65 | | SLIDER | [react-input-slider](https://github.com/wangzuo/react-input-slider) | | | MIT license | https://wangzuo.github.io/react-input-slider/ | 66 | | SLIDER | [react-range-slider](https://github.com/jpuri/react-range-slider) | | | MIT license | http://jpuri.github.io/react-range-slider/ | 67 | | GAUGE / SPEEDOMETER | [react-gauge](https://github.com/jpuri/react-range-slider) | | | | https://github.com/michigan-com/react-gauge | 68 | | GAUGE / SPEEDOMETER | [react-gauge-speedometer](https://github.com/Entali/react-gauge-speedometer) | | | | http://entali.github.io/react-gauge-speedometer/ | 69 | | GAUGE / LIQUID | [react-liquid-gauge](https://github.com/trendmicro-frontend/react-liquid-gauge) | | | MIT license | hhttps://trendmicro-frontend.github.io/react-liquid-gauge/ | 70 | | GAUGE / TEMP | [react-svg-gauge](https://github.com/Reggino/react-svg-gauge) | | | | | 71 | | FAMILY TREE | [d3-react-family-tree](https://github.com/mrblueblue/d3-react-family-tree) | | | | | 72 | 73 | 74 | ### React Books 75 | * [React in depth](https://www.gitbook.com/book/developmentarc/react-indepth/details) 76 | * [React enlightenment](https://www.reactenlightenment.com/) 77 | * [Best ReactJS Books in 2017](https://reactdom.com/blog/reactjs-books) 78 | 79 | ### Webpack 80 | * [Webpack Respository](https://github.com/webpack/webpack) 81 | * [Webpack Official Documentation](http://webpack.github.io/docs/what-is-webpack.html) 82 | * [Setting up Webpack for React](https://robots.thoughtbot.com/setting-up-webpack-for-react-and-hot-module-replacement) 83 | * [Webpack: Build Performance](https://github.com/webpack/docs/wiki/build-performance) 84 | * [Advanced Frontend Optimization with Webpack](http://sokra.github.io/slides/frontend-optimize) 85 | * [Webpack Dashboard](https://github.com/FormidableLabs/webpack-dashboard) 86 | * [Webpack Visualizer](https://chrisbateman.github.io/webpack-visualizer/) 87 | 88 | ### Redux 89 | * [Redux official documentation](http://redux.js.org/index.html) 90 | * [Getting Started with Redux - Video Series](https://egghead.io/series/getting-started-with-redux) 91 | * [Building React Applications with Idiomatic Redux - Video Series](https://egghead.io/series/building-react-applications-with-idiomatic-redux) 92 | * [Modern Web Development with React and Redux](http://blog.isquaredsoftware.com/2017/02/presentation-react-redux-intro/) 93 | * [Understanding Redux](http://www.youhavetolearncomputers.com/blog/2015/9/15/a-conceptual-overview-of-redux-or-how-i-fell-in-love-with-a-javascript-state-container) 94 | * [Getting started with Redux](https://www.codementor.io/mz026/getting-started-with-react-redux-an-intro-8r6kurcxf) 95 | * [Redux Tutorial](https://github.com/happypoulp/redux-tutorial) 96 | * [React / Redux Style Guide](https://github.com/ghengeveld/react-redux-styleguide) 97 | * [Awesome Redux](https://github.com/xgrommx/awesome-redux): amazing collection of links about Redux and Middlewares 98 | 99 | 100 | 101 | ### Virtual DOM 102 | * [React Virtual DOM Demo](https://jscomplete.github.io/react-virtual-dom-demo/demo/) 103 | * [The difference between Virtual Dom and Dom](http://reactkungfu.com/2015/10/the-difference-between-virtual-dom-and-dom/) 104 | * [Virtual Dom vs Incremental Dom vs Glimmer](https://auth0.com/blog/face-off-virtual-dom-vs-incremental-dom-vs-glimmer/) 105 | 106 | ### Others 107 | * [React Rocks: find components](https://react.rocks/) 108 | * [React Redux Links](https://github.com/markerikson/react-redux-links) 109 | * [Reactjs for stupid people - blog entry](http://blog.andrewray.me/reactjs-for-stupid-people/) 110 | * https://github.com/brillout/awesome-react-components 111 | * [React examples](http://www.reactexamples.com/) 112 | -------------------------------------------------------------------------------- /React/README.md: -------------------------------------------------------------------------------- 1 | # MakingSense React/JSX Style Guide 2 | 3 | *A mostly reasonable approach to React and JSX* 4 | 5 | Forked from the excellent [Airbnb React Style Guide](https://github.com/react), slightly modified to fit MakingSense conventions. 6 | 7 | 8 | ## Table of Contents 9 | 10 | 1. [Basic Rules](#basic-rules) 11 | 1. [Class vs `React.createClass` vs stateless](#class-vs-reactcreateclass-vs-stateless) 12 | 1. [Mixins](#mixins) 13 | 1. [Naming](#naming) 14 | 1. [Declaration](#declaration) 15 | 1. [Alignment](#alignment) 16 | 1. [Quotes](#quotes) 17 | 1. [Spacing](#spacing) 18 | 1. [Props](#props) 19 | 1. [Refs](#refs) 20 | 1. [Parentheses](#parentheses) 21 | 1. [Tags](#tags) 22 | 1. [Methods](#methods) 23 | 1. [Ordering](#ordering) 24 | 1. [`isMounted`](#ismounted) 25 | 26 | ## Basic Rules 27 | 28 | - Only include one React component per file. 29 | - However, multiple [Stateless, or Pure, Components](https://facebook.github.io/react/docs/reusable-components.html#stateless-functions) are allowed per file. eslint: [`react/no-multi-comp`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-multi-comp.md#ignorestateless). 30 | - Always use JSX syntax. 31 | - Do not use `React.createElement` unless you're initializing the app from a file that is not JSX. 32 | 33 | ## Class vs `React.createClass` vs stateless 34 | 35 | - If you have internal state and/or refs, prefer `class extends React.Component` over `React.createClass`. eslint: [`react/prefer-es6-class`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md) [`react/prefer-stateless-function`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-stateless-function.md) 36 | 37 | ```jsx 38 | // bad 39 | const Listing = React.createClass({ 40 | // ... 41 | render() { 42 | return
{this.state.hello}
; 43 | } 44 | }); 45 | 46 | // good 47 | class Listing extends React.Component { 48 | // ... 49 | render() { 50 | return
{this.state.hello}
; 51 | } 52 | } 53 | ``` 54 | 55 | And if you don't have state or refs, prefer normal functions (not arrow functions) over classes: 56 | 57 | ```jsx 58 | // bad 59 | class Listing extends React.Component { 60 | render() { 61 | return
{this.props.hello}
; 62 | } 63 | } 64 | 65 | // bad (relying on function name inference is discouraged) 66 | const Listing = ({ hello }) => ( 67 |
{hello}
68 | ); 69 | 70 | // good 71 | function Listing({ hello }) { 72 | return
{hello}
; 73 | } 74 | ``` 75 | 76 | ## Mixins 77 | 78 | - [Do not use mixins](https://facebook.github.io/react/blog/2016/07/13/mixins-considered-harmful.html). 79 | 80 | > Why? Mixins introduce implicit dependencies, cause name clashes, and cause snowballing complexity. Most use cases for mixins can be accomplished in better ways via components, higher-order components, or utility modules. 81 | 82 | ## Naming 83 | 84 | - **Extensions**: Use `.js` extension for React components. 85 | - **Filename**: Use PascalCase for filenames. E.g., `ReservationCard.js`. 86 | - **Reference Naming**: Use PascalCase for React components and camelCase for their instances. eslint: [`react/jsx-pascal-case`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-pascal-case.md) 87 | 88 | ```jsx 89 | // bad 90 | import reservationCard from './ReservationCard'; 91 | 92 | // good 93 | import ReservationCard from './ReservationCard'; 94 | 95 | // bad 96 | const ReservationItem = ; 97 | 98 | // good 99 | const reservationItem = ; 100 | ``` 101 | 102 | - **Component Naming**: Use the filename as the component name. For example, `ReservationCard.js` should have a reference name of `ReservationCard`. However, for root components of a directory, use `index.js` as the filename and use the directory name as the component name: 103 | 104 | ```jsx 105 | // bad 106 | import Footer from './Footer/Footer'; 107 | 108 | // bad 109 | import Footer from './Footer/index'; 110 | 111 | // good 112 | import Footer from './Footer'; 113 | ``` 114 | - **Higher-order Component Naming**: Use a composite of the higher-order component's name and the passed-in component's name as the `displayName` on the generated component. For example, the higher-order component `withFoo()`, when passed a component `Bar` should produce a component with a `displayName` of `withFoo(Bar)`. 115 | 116 | > Why? A component's `displayName` may be used by developer tools or in error messages, and having a value that clearly expresses this relationship helps people understand what is happening. 117 | 118 | ```jsx 119 | // bad 120 | export default function withFoo(WrappedComponent) { 121 | return function WithFoo(props) { 122 | return ; 123 | } 124 | } 125 | 126 | // good 127 | export default function withFoo(WrappedComponent) { 128 | function WithFoo(props) { 129 | return ; 130 | } 131 | 132 | const wrappedComponentName = WrappedComponent.displayName 133 | || WrappedComponent.name 134 | || 'Component'; 135 | 136 | WithFoo.displayName = `withFoo(${wrappedComponentName})`; 137 | return WithFoo; 138 | } 139 | ``` 140 | 141 | - **Props Naming**: Avoid using DOM component prop names for different purposes. 142 | 143 | > Why? People expect props like `style` and `className` to mean one specific thing. Varying this API for a subset of your app makes the code less readable and less maintainable, and may cause bugs. 144 | 145 | ```jsx 146 | // bad 147 | 148 | 149 | // good 150 | 151 | ``` 152 | 153 | ## Declaration 154 | 155 | - Do not use `displayName` for naming components. Instead, name the component by reference. 156 | 157 | ```jsx 158 | // bad 159 | export default React.createClass({ 160 | displayName: 'ReservationCard', 161 | // stuff goes here 162 | }); 163 | 164 | // good 165 | export default class ReservationCard extends React.Component { 166 | } 167 | ``` 168 | 169 | ## Alignment 170 | 171 | - Follow these alignment styles for JSX syntax. eslint: [`react/jsx-closing-bracket-location`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md) 172 | 173 | ```jsx 174 | // bad 175 | 177 | 178 | // good 179 | 183 | 184 | // if props fit in one line then keep it on the same line 185 | 186 | 187 | // children get indented normally 188 | 192 | 193 | 194 | ``` 195 | 196 | ## Quotes 197 | 198 | - Always use double quotes (`"`) for JSX attributes, but single quotes (`'`) for all other JS. eslint: [`jsx-quotes`](http://eslint.org/docs/rules/jsx-quotes) 199 | 200 | > Why? Regular HTML attributes also typically use double quotes instead of single, so JSX attributes mirror this convention. 201 | 202 | ```jsx 203 | // bad 204 | 205 | 206 | // good 207 | 208 | 209 | // bad 210 | 211 | 212 | // good 213 | 214 | ``` 215 | 216 | ## Spacing 217 | 218 | - Always include a single space in your self-closing tag. eslint: [`no-multi-spaces`](http://eslint.org/docs/rules/no-multi-spaces), [`react/jsx-space-before-closing`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-space-before-closing.md) 219 | 220 | ```jsx 221 | // bad 222 | 223 | 224 | // very bad 225 | 226 | 227 | // bad 228 | 230 | 231 | // good 232 | 233 | ``` 234 | 235 | - Do not pad JSX curly braces with spaces. eslint: [`react/jsx-curly-spacing`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-curly-spacing.md) 236 | 237 | ```jsx 238 | // bad 239 | 240 | 241 | // good 242 | 243 | ``` 244 | 245 | ## Props 246 | 247 | - Always use camelCase for prop names. 248 | 249 | ```jsx 250 | // bad 251 | 255 | 256 | // good 257 | 261 | ``` 262 | 263 | - Omit the value of the prop when it is explicitly `true`. eslint: [`react/jsx-boolean-value`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md) 264 | 265 | ```jsx 266 | // bad 267 |