└── README.md /README.md: -------------------------------------------------------------------------------- 1 | # Code Guide 2 | 3 | All code in any code-base should look like a single person typed it, no matter how many people contributed. 4 | 5 | ## General 6 | 7 | * write **DRY** (Don't repeat yourself) Code 8 | * do document and comment your code 9 | * consistent naming scheme per language (further defined in the language guidelines) 10 | * avoid deep nesting of code 11 | * keep short line length 12 | 13 | ## Tabs versus spaces 14 | 15 | * Use tabs for indenting to visualize your codes hierarchy 16 | * Use spaces for indenting to align your code 17 | 18 | 19 | **Tabs for hierarchy** 20 | ```javascript 21 | function alertSomething() { 22 | » alert('Something!'); 23 | } 24 | ``` 25 | 26 | **Spaces for aligning** 27 | 28 | ```javascript 29 | var foo = '', 30 | ····bar = '', 31 | ····baz = ''; 32 | ``` 33 | 34 | **Both mixed** 35 | 36 | ```javascript 37 | function alertSomething() { 38 | » var foo = 'Something', 39 | » ····bar = '!'; 40 | 41 | » alert(foo + bar); 42 | } 43 | ``` 44 | 45 | This is a really helpful practice. Code can be aligned and it will still be aligned for any monospaced font but you also preserve the semantic tab and every developer can decide his tab size by personal preference. 46 | 47 | ## Version Control (e.g. Git) 48 | 49 | ### Commit Message Format (inspired by [Angular Contributing Guidelines](https://github.com/angular/angular.js/blob/master/CONTRIBUTING.md)) 50 | Each commit message consists of a **header** and a **body**: 51 | 52 | ``` 53 | : 54 | 55 | ``` 56 | 57 | Any line of the commit message cannot be longer 100 characters! This allows the message to be easier to read on GitHub as well as in various Git tools. 58 | 59 | ### Type 60 | Must be one of the following: 61 | 62 | * **feat**: A new feature 63 | * **fix**: A bug fix 64 | * **docs**: Documentation only changes 65 | * **style**: Changes that do not affect the meaning of the code (white-space, formatting, missing 66 | semi-colons, etc) 67 | * **refactor**: A code change that neither fixes a bug nor adds a feature 68 | * **perf**: A code change that improves performance 69 | * **test**: Adding missing tests 70 | * **chore**: Changes to the build process or auxiliary tools and libraries such as documentation 71 | generation 72 | * **content**: Changes to site content or texts for websites or marketing 73 | 74 | ### Subject 75 | The subject contains succinct description of the change: 76 | 77 | * use the imperative, present tense: "change" not "changed" nor "changes" 78 | * don't capitalize first letter 79 | * no dot (.) at the end 80 | 81 | In case you want to commit a **fix**, use the present passive voice to describe the problem you fix: 82 | 83 | `fix: passwords aren't encrypted` 84 | 85 | `fix: emojis are missing` 86 | 87 | instead of ~~`fix: encrypt passwords`~~ or ~~`fix: add emojis`~~ 88 | 89 | ### Body 90 | Just as in the **subject**, use the imperative, present tense: "change" not "changed" nor "changes". 91 | The body further specifies what changed and may include the motivation for the change and contrast this with previous behavior. 92 | 93 | ## Frontend Code HTML and CSS 94 | 95 | * follow [codeguide.co](http://codeguide.co) 96 | 97 | ## JavaScript 98 | 99 | * follow [Google JavaScript Style Guide](http://google.github.io/styleguide/jsguide.html) 100 | 101 | ## PHP 102 | 103 | * follow [PSR-2](http://www.php-fig.org/psr/psr-2) 104 | * follow [PHPDoc](https://www.phpdoc.org/docs/latest/references/phpdoc/index.html) 105 | * the `@param` tag is followed by two spaces, the argument type, two more spaces and the variable name 106 | * use the short term for all primitives 107 | 108 | ## Ruby 109 | 110 | * follow [GitHub Ruby Styleguide](https://github.com/styleguide/ruby) 111 | --------------------------------------------------------------------------------