├── .editorconfig ├── .gitignore ├── .jscs.json ├── .jshintrc ├── LICENSE ├── README.md └── sample.js /.editorconfig: -------------------------------------------------------------------------------- 1 | [*.js] 2 | indent_style = space 3 | indent_size = 2 4 | continuation_indent_size = 2 5 | insert_final_newline = true 6 | quote_type = single 7 | space_after_anonymous_functions = true 8 | space_after_control_statements = true 9 | spaces_around_operators = true 10 | trim_trailing_whitespace = true 11 | spaces_in_brackets = false 12 | curly_bracket_next_line = true 13 | indent_brace_style = 1TBS 14 | end_of_line = lf 15 | charset = utf-8 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .idea/ 3 | -------------------------------------------------------------------------------- /.jscs.json: -------------------------------------------------------------------------------- 1 | { 2 | "validateIndentation": 2, 3 | "requireCurlyBraces": [ 4 | "if", 5 | "else", 6 | "for", 7 | "while", 8 | "do", 9 | "try", 10 | "catch" 11 | ], 12 | "requireOperatorBeforeLineBreak": true, 13 | "requireCamelCaseOrUpperCaseIdentifiers": true, 14 | "validateIndentation": 2, 15 | "validateQuoteMarks": "'", 16 | "disallowMultipleLineStrings": true, 17 | "disallowMixedSpacesAndTabs": true, 18 | "disallowTrailingWhitespace": true, 19 | "disallowSpaceAfterPrefixUnaryOperators": true, 20 | "requireMultipleVarDecl": true, 21 | "disallowKeywordsOnNewLine": ["else"], 22 | "requireSpaceAfterKeywords": [ 23 | "if", 24 | "else", 25 | "for", 26 | "while", 27 | "do", 28 | "switch", 29 | "return", 30 | "try", 31 | "catch" 32 | ], 33 | "requireSpaceBeforeBinaryOperators": [ 34 | "=", 35 | "+=", 36 | "-=", 37 | "*=", 38 | "/=", 39 | "%=", 40 | "<<=", 41 | ">>=", 42 | ">>>=", 43 | "&=", 44 | "|=", 45 | "^=", 46 | "+=", 47 | "+", 48 | "-", 49 | "*", 50 | "/", 51 | "%", 52 | "<<", 53 | ">>", 54 | ">>>", 55 | "&", 56 | "|", 57 | "^", 58 | "&&", 59 | "||", 60 | "===", 61 | "==", 62 | ">=", 63 | "<=", 64 | "<", 65 | ">", 66 | "!=", 67 | "!==" 68 | ], 69 | "requireSpaceAfterBinaryOperators": true, 70 | "requireSpacesInConditionalExpression": true, 71 | "requireSpaceBeforeBlockStatements": true, 72 | "requireSpacesInForStatement": true, 73 | "requireLineFeedAtFileEnd": true, 74 | "requireSpacesInFunctionExpression": { 75 | "beforeOpeningCurlyBrace": true 76 | }, 77 | "requireSpacesInAnonymousFunctionExpression": { 78 | "beforeOpeningRoundBrace": true, 79 | "beforeOpeningCurlyBrace": true 80 | }, 81 | "disallowSpacesInsideObjectBrackets": "all", 82 | "disallowSpacesInsideArrayBrackets": "all", 83 | "disallowSpacesInsideParentheses": true, 84 | "validateJSDoc": { 85 | "checkParamNames": true, 86 | "requireParamTypes": true 87 | }, 88 | "disallowMultipleLineBreaks": true, 89 | "disallowNewlineBeforeBlockStatements": true 90 | } 91 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "node": true, 3 | "browser": true, 4 | "esnext": true, 5 | "bitwise": true, 6 | "camelcase": true, 7 | "curly": true, 8 | "eqeqeq": true, 9 | "immed": true, 10 | "indent": 2, 11 | "latedef": "nofunc", 12 | "newcap": true, 13 | "noarg": true, 14 | "quotmark": "single", 15 | "undef": false, 16 | "unused": true, 17 | "strict": true, 18 | "trailing": true, 19 | "smarttabs": true, 20 | "onevar": true, 21 | "globals": { 22 | "angular": true, 23 | "module": true, 24 | "define": true, 25 | "window": true, 26 | "showdown": true 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 showdownjs 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Shodown Code Style and Orientations 2 | =================================== 3 | 4 | Code-style for showdown and related projects. 5 | 6 | ## Introduction 7 | In this file, you can check the the code styling, rules and commit message convetions for showdown and it's related projects. It's roughly based on [Google JavaScript Style Guide][1] and [AngularJS Git Commit Msg Convention][8]. Using these rules is strongly advisable when contributing to showdown projects. 8 | In this repository you can also find a [.editorconfig][2], [.jshintrc][3] and [.jscs.json][4] file that you can use to automatically enforce 9 | these rules (if your IDE supports it). 10 | 11 | For more information, check the [editorconfig][5], [jshint][6] and [jscs][7] project pages. 12 | 13 | 14 | ## Tabs and indentation 15 | - **DO NOT USE** tab character, use spaces instead 16 | - Tab size is 2 spaces 17 | - Indentation is 1 tab size (2 spaces) 18 | - Continuation indent is 1 tab size 19 | - Multiple variable declaration MUST BE chopped and aligned (4 spaces, usually) 20 | - Empty lines MUST not keep indents 21 | - Blank lines CAN be added for readability 22 | - 2 consecutive blank lines are allowed 23 | - 'case' branches in switch statements MUST BE indented 24 | 25 | 26 | ```javascript 27 | function foo() { 28 | var bar = 'bar', 29 | baz = 1; 30 | 31 | if (bar === 'bar') { 32 | alert('something'); 33 | } 34 | } 35 | ``` 36 | 37 | ## Semicolons and quotation 38 | - **Statements must ALWAYS be terminated with semicolon**. However, multiple variable declaration is allowed. 39 | - Single quotes are preferred to double quotes. Exceptionally, double quotes might be used if single quotes would require escaping 40 | 41 | 42 | ```javascript 43 | var foo = 'some string', 44 | baz = "I'm using single quotes inside"; 45 | ``` 46 | 47 | 48 | ## Spaces 49 | 50 | ### Before parenthesis 51 | - **DO NOT ADD** before: 52 | - function declaration 53 | - function call 54 | 55 | 56 | ```javascript 57 | function foo() { 58 | return 0; 59 | } 60 | 61 | foo(); 62 | ``` 63 | 64 | 65 | - **ADD** before: 66 | - 'if' 67 | - 'for' 68 | - 'while' 69 | - 'switch' 70 | - 'catch' 71 | - in function expression 72 | 73 | 74 | ```javascript 75 | if (i > 10) { 76 | for (var j = 0; j < 10; j++) { 77 | switch (j) { 78 | case 0: 79 | value = 'zero'; 80 | break; 81 | case 1: 82 | value = 'one'; 83 | break; 84 | } 85 | } 86 | } 87 | ``` 88 | 89 | ### Around operators 90 | - **ADD** around: 91 | - assignment operators (=, +=, ...) 92 | - logical operators (&&, ||) 93 | - equality operators (==, ===, !=, !==) 94 | - relational operators (<, >, <=, >=) 95 | - bitwise operators (&, |, ^, ...) 96 | - additive operators (+, -) and multiplication operators (*,/,%) 97 | - shift operators (<<,>>,>>>, ...) 98 | 99 | 100 | ```javascript 101 | var a = 0, 102 | b = (i == j || j > 5), 103 | c = (j << 2) & 4, 104 | d += 1, 105 | e = a + d; 106 | ``` 107 | 108 | - **DO NOT ADD** around: 109 | - unary operators (!, -, +, ++, --) 110 | 111 | 112 | ```javascript 113 | j++; 114 | bar = !foo; 115 | ``` 116 | 117 | ### Before left brace 118 | - **ADD** before: 119 | - function 120 | - 'if' 121 | - 'else' 122 | - 'for' 123 | - 'while' 124 | - 'do' 125 | - 'switch' 126 | - 'try' 127 | - 'catch' 128 | - 'finally' 129 | 130 | ### Before keywords 131 | - **ADD** before: 132 | - 'else' 133 | - 'while' 134 | - 'catch' 135 | - 'finally' 136 | 137 | 138 | ```javascript 139 | var foo = function () { 140 | if (bar) { 141 | try { 142 | baz(); 143 | } catch (e) { 144 | alert('Failure: ' + e.message); 145 | } finally { 146 | reset(a, i); 147 | } 148 | } else { 149 | bazinga(); 150 | } 151 | } 152 | ``` 153 | 154 | ### Within 155 | - **DO NOT ADD** within: 156 | - brackets 157 | - object literal braces 158 | - function call, function declaration, 'if', 'for', 'while', 'switch' or 'catch' parentheses 159 | 160 | ### In ternary operators 161 | - **ADD** 162 | - before '?' 163 | - after '?' 164 | - before ':' 165 | - after ':' 166 | 167 | 168 | ```javascript 169 | var c = j > 5 ? 'GT 5' : 'LE 5'; 170 | ``` 171 | 172 | 173 | ### Other 174 | - **ADD** 175 | - after comma 176 | - after property name-value separator (:) 177 | - **DO NOT ADD** 178 | - before comma 179 | - before semicolon 180 | - before property name-value separator (:) 181 | 182 | ## Braces 183 | We use **egyptian braces**. That means braces are **ALWAYS** placed at the **End of Line** 184 | Also, braces are required in every block elements, even if they are oneliners ('if', 'while', 'do...while', 'try...catch...finally', etc...) 185 | 186 | ## Wrapping 187 | We use a soft wrap of 120 characters long. Also: 188 | - Comments MAY wrap at right margin 189 | - Function declaration arguments MAY wrap if long and aligned when multiline. 190 | - Function call arguments MAY wrap if long and aligned when multiline. 191 | - Object literals MUST ALWAYS BE chopped 192 | - Multiple variable declaration MUST BE chopped and aligned (4 spaces, usually) 193 | 194 | 195 | ```javascript 196 | foo(a, b, c, d); // Line comment 197 | // which can be 198 | // wrapped if 199 | // long. 200 | foo(a, b, c, d 201 | e, f, g, h, i); 202 | 203 | function foo(a, b, c, d, bla, 204 | ble, bli, blu) { 205 | 206 | } 207 | ``` 208 | 209 | --------------------------------------------------------------- 210 | 211 | ## Commit message convention 212 | 213 | We use the [AngularJS Git Commit Msg Convention][8] because it enables us to: 214 | - automatically generate the changelog with pointers to the appropriate issues and commits 215 | - simple navigatie through the git history, focusing on important things while ignoring trivial changes 216 | 217 | 218 | ### Format of the commit message: 219 | ```bash 220 | (): 221 | 222 | 223 | 224 |