1 | # Contributions
|
2 | Before contributing, please take notice to this style-guide - it details simple instructions for what's expected of your changes. Pull-requests will be rejected if they fail to adhere to the points listed here.
|
3 |
|
4 | That being said, the requirements here are clear and simple.
|
5 |
|
6 | ## Formatting
|
7 | Some general points that apply to most aspects of the project:
|
8 | * Indentation should be with 4 **spaces**
|
9 | * Commas on the same line
|
10 |
|
11 | `npm test` runs eslint checks (`npm run test:lint`).
|
12 |
|
13 | ### package.json
|
14 | The package.json file should be indented with 4 spaces, not 2. Using commands like `npm install <package>` will reformat the file to 2-space indent, so for your convenience please add dependencies by hand.
|
15 |
|
16 | ### Source files
|
17 | Keep modules neat and tidy - follow the layout in other source files. Ensure you have `"use strict";` in each module.
|
18 |
|
19 | Modules are wrapped like so:
|
20 | ```
|
21 | (function(module) {
|
22 |
|
23 | "use strict";
|
24 |
|
25 | module.exports = something;
|
26 |
|
27 | })(module);
|
28 | ```
|
29 |
|
30 | Semicolons are to be used at all times.
|
31 |
|
32 | ## Technical
|
33 |
|
34 | ### Dependencies
|
35 | When adding dependencies, consider the nature of Buttercup and the required level of stability and security. Use patch-level semver only: `~1.2.3`.
|
36 |
|
37 | ## Tests & Documentation
|
38 | Please write tests. So many things can go wrong when functionality isn't covered by tests. Keep your tests at the same standard as your code.
|
39 |
|
40 | Document your functions, classes and variables with JSDoc blocks. Before making a PR, run `./generate-docs` to regenerate API documentation.
|
41 |
|
42 | Tests should be grouped by the method that they're testing, and test functions should begin with the word "test":
|
43 | ```
|
44 | module.exports = {
|
45 |
|
46 | getSomething: {
|
47 |
|
48 | testGetsSomething: function(test) {}
|
49 |
|
50 | }
|
51 |
|
52 | };
|
53 | ```
|
54 |
|
55 | ### JSDoc
|
56 | When documenting a private property (static), the block should resemble this:
|
57 | ```
|
58 | /**
|
59 | * My variable that does something
|
60 | * @type {string|number}
|
61 | * @private
|
62 | * @static
|
63 | * @memberof ClassInThisFile
|
64 | */
|
65 | var __myProp = 10;
|
66 | ```
|
67 |
|
68 | When documenting a constructor/class:
|
69 | ```
|
70 | /**
|
71 | * My class that does something
|
72 | * @class MyClass
|
73 | * @param {Object} paramName Class takes this property
|
74 | */
|
75 | var MyClass = function(paramName) {
|
76 | ```
|
77 |
|
78 | When documenting a class method:
|
79 | ```
|
80 | /**
|
81 | * Do something on the class instance
|
82 | * @param {string} action Action to take
|
83 | * @param {string=} something Something else to do (optional)
|
84 | * @returns {number} Returns a number
|
85 | * @throws {Error} Throws if you do something wrong
|
86 | * @memberof MyClass
|
87 | * @public
|
88 | * @instance
|
89 | */
|
90 | MyClass.prototype.doSomething = function(action, something) {
|
91 | ```
|
92 |
|
93 | A "protected" (not to be used externally) method:
|
94 | ```
|
95 | /**
|
96 | * Do something privately
|
97 | * (JSDoc properties as per normal functions minus @public)
|
98 | * @protected
|
99 | */
|
100 | MyClass.prototype._doPrivately = function() {
|
101 | ```
|