-
Notifications
You must be signed in to change notification settings - Fork 1
Coding standards
Robbert Broersma edited this page Jun 10, 2016
·
7 revisions
We use a subset of JSDoc annotations, as defined by Closure Compiler. See this document for the complete syntax: Annotating JavaScript for the Closure Compiler
Short takeaways:
- Use
@returninstead of@returns. - Use
string,numberandbooleaninstead ofString,NumberandBoolean.
To maintain coding standards, it is good practice to use project guidelines. For following these rules it is helpful to configure Sublime Text and make it detect coding violations, like using too much/too little whitespace for example!
- Open Sublime and press
Cmd+Shift+P(OS X) - Type install and choose
Package Control: Install Package - Find and select
EditorConfig - Find and select
SublimeLinter - Find and select
SublimeLinter-shellcheck - Find and select
SublimeLinter-contrib-eslint - Install
eslinton your computer withsudo npm install -g eslintin Terminal - Make sure you have a file names
.eslintrcin the root of your project - Restart Sublime and test if a violation of the code guidelines is detected (an extra space for example)
Using the issue number in your branch name will automatically add the commit to the issue info.
We'll use your_name/issue-issue_number so for example yolijn/issue-42
For renaming a branch locally and remotely:
git branch -m old_branch new_branch # Rename branch locally
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
git push origin :old_branch # Delete the old branch
When defining a module:
- First define a constructor or namespace object.
- Define static properties
- Define static methods
- Define prototype properties
- Define prototype methods that override the parent class
- Define prototype methods
For example:
/**
* @constructor
*/
function Vector()
{
// Step 1
}
/**
* @private
* @const {number}
*/
Vector.__min = -Infinity; // Step 2
/**
* @param {Array} array
*/
Vector.from = function (array)
{
// Step 3
};
/** @type {number} */
Vector.prototype.length = 0; // Step 4
/**
* @override
* @return {string}
*/
Vector.prototype.toString = function()
{
// Step 5
};
/**
* @override
* @return {string}
*/
Vector.prototype.clone = function()
{
// Step 6
};