Here, javascript sources have to begin with this header: :js:`/*jslint indent: 2,
In this project, JavaScript sources have to begin with the header: :js:`/*jslint indent: 2,
maxlen: 80, nomen: true */`, which means it uses two spaces indentation, 80
maxlen: 80, nomen: true */`, which means it uses two spaces indentation, 80
maximum characters by line and allow the use of '_' as first variable name
maximum characters per line and the use of '_' as first character in a variable name is allowed.
character. Other JSLint options can be added in sub functions if necessary;
Other JSLint options can be added in sub functions if necessary.
Allowed options are:
Some allowed options are:
* ``ass: true`` if assignment should be allowed outside of statement position.
* ``ass: true`` if assignment should be allowed outside of statement position.
* ``bitwise: true`` if bitwise operators should be allowed.
* ``bitwise: true`` if bitwise operators should be allowed.
* ``continue: true`` if the continue statement should be allowed.
* ``continue: true`` if the continue statement should be allowed.
* ``newcap: true`` if Initial Caps with constructor function is optional.
* ``newcap: true`` if Initial Caps with constructor function is optional.
* ``regexp: true`` if ``.`` and ``[^...]`` should be allowed in RegExp literals. They match more material than might be expected, allowing attackers to confuse applications. These forms should not be used when validating in secure applications.
* ``regexp: true`` if ``.`` and ``[^...]`` should be allowed in RegExp literals. They match more material than might be expected, allowing attackers to confuse applications. These forms should not be used when validating in secure applications.
* ``unparam: true`` if warnings should not be given for unused parameters.
* ``unparam: true`` if warnings should be silenced for unused parameters.
Coding Conventions
Coding Conventions
------------------
------------------
Coding conventions include generic patterns that ensure that written code adheres to certain formatting conventions.
Coding conventions include generic patterns that ensure that written code follows certain formatting conventions.
Uses two-space indentation
Uses two-space indentation
^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^
Tabs and 2-space indentation are being used equally. Since a lot of errors on
Tabs and 2-space indentation are being used equally. Since a lot of errors on
JSLint often result from mixed use of space and tab using 2 spaces throughout
JSLint often result from mixed use of space and tab, using 2 spaces throughout
prevents these errors up front.
prevents these errors up front.
...
@@ -189,7 +191,7 @@ Good Example
...
@@ -189,7 +191,7 @@ Good Example
Closing Brace Location
Closing Brace Location
^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^
The closing brace should be on the same indent as the original function call.
The closing brace should be on the same indent level as the original function call.
Bad Example
Bad Example
...
@@ -249,7 +251,7 @@ Naming conventions include generic patterns for setting names and identifiers th
...
@@ -249,7 +251,7 @@ Naming conventions include generic patterns for setting names and identifiers th
Constructors
Constructors
^^^^^^^^^^^^
^^^^^^^^^^^^
A constructor function starting with new should always start with a capital letter
Constructor functions (called with the ``new`` statement) should always start with a capital letter:
.. code-block:: javascript
.. code-block:: javascript
...
@@ -299,7 +301,7 @@ Follow the camel case convention, typing the words in lower-case, only capitaliz
...
@@ -299,7 +301,7 @@ Follow the camel case convention, typing the words in lower-case, only capitaliz
Variables
Variables
^^^^^^^^^
^^^^^^^^^
Variables with multiple words should always use an underscore between words.
Variable names with multiple words should always use an underscore between them.
.. code-block:: javascript
.. code-block:: javascript
...
@@ -325,7 +327,9 @@ Example
...
@@ -325,7 +327,9 @@ Example
var value_list = getObjectOrArray();
var value_list = getObjectOrArray();
// value_list can be an object which can be cast into an array
// value_list can be an object which can be cast into an array
To use camelCase, when sometimes it is impossible to declare a function directly, the function variable name should match some patterns which shows that it is a function.
To use camelCase, when sometimes it is not possible to declare a function
directly, the function variable name should match some pattern which shows
that it is a function.
.. code-block:: javascript
.. code-block:: javascript
...
@@ -402,7 +406,7 @@ Bad Example
...
@@ -402,7 +406,7 @@ Bad Example
No Abbreviations
No Abbreviations
^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^
Abbreviations should not be used to avoid confusion
Abbreviations should not be used to avoid confusion.
Good Example
Good Example
...
@@ -422,7 +426,7 @@ Bad Example
...
@@ -422,7 +426,7 @@ Bad Example
No Plurals
No Plurals
^^^^^^^^^^
^^^^^^^^^^
Plurals should not be used when assigning names
Plurals should not be used as variable names.
.. code-block:: javascript
.. code-block:: javascript
...
@@ -436,7 +440,8 @@ Plurals should not be used when assigning names
...
@@ -436,7 +440,8 @@ Plurals should not be used when assigning names
Use Comments
Use Comments
^^^^^^^^^^^^
^^^^^^^^^^^^
Should be used with reason but include enough information so that a reader can get a first grasp of what a part of code is supposed to do.
Comments should be used within reason but include enough information so that a
reader can get a first grasp of what a part of code is supposed to do.
Good Example
Good Example
...
@@ -463,9 +468,9 @@ Bad Example
...
@@ -463,9 +468,9 @@ Bad Example
Documentation
Documentation
^^^^^^^^^^^^^
^^^^^^^^^^^^^
You can use `YUIDoc <http://yuilibrary.com/projects/yuidoc>`_ and their custom comment
You can use `YUIDoc <http://yuilibrary.com/projects/yuidoc>`_ and its custom comment
tags together with Node.js to generate the documentation from the script file
tags together with Node.js to generate the documentation from the script file
itself. Comments will look something like this:
itself. Comments should look like this:
Good Example
Good Example
...
@@ -495,12 +500,10 @@ Bad Example
...
@@ -495,12 +500,10 @@ Bad Example
Additional Readings
Additional Readings
-------------------
-------------------
Resources, additional reading materials and links used
Resources, additional reading materials and links:
* `Javascript Patterns <http://shop.oreilly.com/product/9780596806767.do>`_, main ressource used.
* `Javascript Patterns <http://shop.oreilly.com/product/9780596806767.do>`_, main ressource used.
When multiple versions of a document are available, jIO returns the lastest, left-most version on the document tree (2-375... and labels all other versions as conflicting 2-068...).
When multiple versions of a document are available, jIO returns the latest,
left-most version on the document tree (2-375... and labels all other
versions as conflicting 2-068...).
#. Retrieve conflicts by setting option
#. Retrieve conflicts by setting option
...
@@ -156,6 +158,6 @@ update is executed.
...
@@ -156,6 +158,6 @@ update is executed.
When deleting the conflicting version of your namecard, jIO removes this
When deleting the conflicting version of your namecard, jIO removes this
version from all storages and sets the document tree leaf of this version to
version from all storages and sets the document tree leaf of this version to
deleted. All storages now contain just a single version of your namecard
deleted. All storages now contain just a single version of your namecard
(2-3753...). Note, that the on the document tree, removing a revison will
(2-3753...). Note that, on the document tree, removing a revison will
create a new revision with status set to *deleted*.
create a new revision with status set to *deleted*.