Confirmed users
14,525
edits
Line 200: | Line 200: | ||
** things we lock down because alternatives are risky (array.forEach) | ** things we lock down because alternatives are risky (array.forEach) | ||
* Aaron: We should offer style guidelines on the license block | * Aaron: We should offer style guidelines on the license block | ||
== Style Guidelines == | |||
=== Naming === | |||
1. Local variables should be named using camel-case | |||
<pre> var exampleVariableName = value;</pre> | |||
2. Constants should be named using all-caps | |||
<pre>const EXAMPLE_CONSTANT = value;</pre> | |||
=== Commenting === | |||
1. Blocks of code should be commented in-line: | |||
<pre> | |||
// What the code does | |||
some code; | |||
</pre> | |||
2. Functions should use JSDoc block-style comments: | |||
<pre> | |||
/** | |||
* Purpose of the function | |||
* | |||
* @param {type} paramName | |||
* Purpose of the parameter | |||
*/ | |||
function someFunction(someParam) { | |||
</pre> | |||
=== Block-style === | |||
1. Arrays | |||
<pre> | |||
var obj = [ | |||
{ child: ‘value’, | |||
child: ‘value } | |||
{ child: ‘value’, | |||
child: ‘value} | |||
]; | |||
</pre> | |||
2. Named Functions | |||
<pre> | |||
function someFunction() { | |||
some code; | |||
} | |||
</pre> | |||
3. Anonymous Functions | |||
<pre> | |||
var someFunction() = function() { | |||
some code; | |||
} | |||
</pre> | |||
4. Function Usage | |||
<pre> | |||
var someVariable = someFunction( | |||
param1, | |||
param2, | |||
paramN, | |||
); | |||
</pre> | |||
5. Function Parameter Concatenation | |||
<pre> | |||
var someVariabe = someFunction(param1, | |||
'some' + | |||
'concat' + | |||
'string' | |||
); | |||
</pre> | |||
6. waitFor() | |||
<pre> | |||
controller.waitFor(function() { | |||
return something == somethingElse; | |||
}, "Some error message", TIMEOUT); | |||
</pre> | |||
=== Indentation === | |||
1. Lines of code should be indented 2-spaces to the right of their parent | |||
<pre> | |||
var cancelButton = new elementslib.Lookup(controller.window.document, | |||
'path/to/element' | |||
); | |||
</pre> | |||
2. Component declarations should be indented in line with the parent | |||
<pre> | |||
var obj = Cc['someComponentInferface']. | |||
getService('someService'); | |||
</pre> | |||
=== Line Length === | |||
1. Lines of code should not exceed 80 characters | |||
=== Idioms === | |||
1. Use waitFor() as much as possible. Only use sleep() when a waitFor() fails. | |||
== Refactoring == | == Refactoring == |