UNPKG

2.76 kBMarkdownView Raw
1# Contributions
2Before 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
4That being said, the requirements here are clear and simple.
5
6## Formatting
7Some 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
14The 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
17Keep modules neat and tidy - follow the layout in other source files. Ensure you have `"use strict";` in each module.
18
19Modules are wrapped like so:
20```
21(function(module) {
22
23 "use strict";
24
25 module.exports = something;
26
27})(module);
28```
29
30Semicolons are to be used at all times.
31
32## Technical
33
34### Dependencies
35When 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
38Please 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
40Document your functions, classes and variables with JSDoc blocks. Before making a PR, run `./generate-docs` to regenerate API documentation.
41
42Tests should be grouped by the method that they're testing, and test functions should begin with the word "test":
43```
44module.exports = {
45
46 getSomething: {
47
48 testGetsSomething: function(test) {}
49
50 }
51
52};
53```
54
55### JSDoc
56When 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 */
65var __myProp = 10;
66```
67
68When documenting a constructor/class:
69```
70/**
71 * My class that does something
72 * @class MyClass
73 * @param {Object} paramName Class takes this property
74 */
75var MyClass = function(paramName) {
76```
77
78When 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 */
90MyClass.prototype.doSomething = function(action, something) {
91```
92
93A "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 */
100MyClass.prototype._doPrivately = function() {
101```