Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

docs: add more code style guidelines.

  • Loading branch information...
commit 8f5b732e1899ec5339fa8d4edba1dfb980b66cec 1 parent 79ef244
Stephen Sawchuk stephenplusplus authored

Showing 2 changed files with 112 additions and 36 deletions. Show diff stats Hide diff stats

  1. +111 0 codestyle.md
  2. +1 36 contributing.md
111 codestyle.md
Source Rendered
... ... @@ -0,0 +1,111 @@
  1 +# Code Style
  2 +We think it's best for the project if the code you write looks like the code the last developer wrote. Please read this document in its entirety, and be sure to refer back to it throughout the development of your contribution. We greatly appreciate your cooperation.
  3 +
  4 +## General Rules
  5 +- Tab indentation
  6 +- Single-quotes
  7 +- Semicolon
  8 +- Strict mode
  9 +- No trailing whitespace
  10 +- Variables at the top of the scope
  11 +- Multiple variable statements
  12 +- Space after keywords and between arguments and operators
  13 +- Return early
  14 +- JSHint valid
  15 +- Consistency
  16 +
  17 +Example:
  18 +
  19 +```js
  20 +'use strict';
  21 +
  22 +function foo(bar, fum) {
  23 + var i, l, ret;
  24 + var hello = 'Hello';
  25 +
  26 + if (!bar) {
  27 + return;
  28 + }
  29 +
  30 + for (i = 0, l = bar.length; i < l; i++) {
  31 + if (bar[i] === hello) {
  32 + ret += fum(bar[i]);
  33 + }
  34 + }
  35 +
  36 + return ret;
  37 +}
  38 +```
  39 +
  40 +Read [idiomatic.js](https://github.com/rwldrn/idiomatic.js) for general JavaScript code style best practices.
  41 +
  42 +## Anonymous Functions
  43 +When using anonymous functions, leave a space between the function name and opening parenthesis.
  44 +
  45 +Example:
  46 +
  47 +```js
  48 +(function () {
  49 + 'use strict';
  50 +
  51 + var thanks = 'mate';
  52 +})
  53 +```
  54 +
  55 +## Comments
  56 +Inline comments are a great way of giving new users a better understanding of what you're doing and why.
  57 +
  58 +It's also helpful to let your functions breathe, by leaving additional lines between statements.
  59 +
  60 +Example:
  61 +
  62 +```js
  63 +// Ok.
  64 +var removeTodo = function (todoItem) {
  65 + var todoModel = todoItem.getModel(); // Grab the model from the todoItem.
  66 + todoItem.find('.destroy').click(); // Trigger a click to remove the element from the <ul>.
  67 + todoModel.remove(); // Removes the todo model from localStorage.
  68 +};
  69 +
  70 +// Better.
  71 +var removeTodo = function (todoItem) {
  72 + // Grab the model from the todoItem.
  73 + var todoModel = todoItem.getModel();
  74 +
  75 + // Trigger a click to remove the element from the <ul>.
  76 + todoItem.find('.destroy').click();
  77 +
  78 + // Removes the todo model from localStorage.
  79 + todoModel.remove();
  80 +};
  81 +```
  82 +
  83 +## RequireJS
  84 +When using RequireJS, please format your code to these specifications:
  85 +
  86 +```js
  87 +define('Block', [
  88 + 'jQuery',
  89 + 'Handlebars'
  90 +], function ($, Handlebars) {
  91 + 'use strict';
  92 +
  93 + // Code here.
  94 +});
  95 +```
  96 +
  97 +## JSHint
  98 +When you submit your pull request, one of the first things we will do is run JSHint against your code.
  99 +
  100 +You can help speed the process by running it yourself:
  101 +
  102 +```
  103 +jshint path/to/your/app/js
  104 +```
  105 +
  106 +Your JSHint code blocks must follow this style:
  107 +
  108 +```js
  109 +/*global define, App */
  110 +/*jshint unused:false */
  111 +```
37 contributing.md
Source Rendered
@@ -5,42 +5,7 @@ We're happy to accept contributions in the form of new apps, bug fixes, issues,
5 5
6 6 ## Code Style
7 7
8   -- Tab indentation
9   -- Single-quotes
10   -- Semicolon
11   -- Strict mode
12   -- No trailing whitespace
13   -- Variables at the top of the scope
14   -- Multiple variable statements
15   -- Space after keywords and between arguments and operators
16   -- Return early
17   -- JSHint valid
18   -- Consistency
19   -
20   -Example:
21   -
22   -```js
23   -'use strict';
24   -
25   -function foo(bar, fum) {
26   - var i, l, ret;
27   - var hello = 'Hello';
28   -
29   - if (!bar) {
30   - return;
31   - }
32   -
33   - for (i = 0, l = bar.length; i < l; i++) {
34   - if (bar[i] === hello) {
35   - ret += fum(bar[i]);
36   - }
37   - }
38   -
39   - return ret;
40   -}
41   -```
42   -
43   -Read [idiomatic.js](https://github.com/rwldrn/idiomatic.js) for general JavaScript code style best practices.
  8 +We think it's best for the project if the code you write looks like the code the last developer wrote, so we've put together [some guidelines we ask that you follow](https://github.com/addyosmani/todomvc/tree/gh-pages/codestyle.md). We greatly appreciate your cooperation and contribution.
44 9
45 10
46 11 ## Pull Request Guidelines

0 comments on commit 8f5b732

Please sign in to comment.
Something went wrong with that request. Please try again.