Forráskód Böngészése

Add a styleguide to the documentation.

Also update the contributor guidelines to mention the styleguide.
JC Brand 10 éve
szülő
commit
785244f15e

+ 5 - 9
CONTRIBUTING.rst

@@ -18,6 +18,8 @@ make your changes and then submit a pull request.
 Before submitting a pull request
 --------------------------------
 
+Please read the `style guide <https://conversejs.org/docs/html/style_guide.html>`_ and make sure that your code follows it.
+
 Add tests for your bugfix or feature
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Add a test for any bug fixed or feature added. We use Jasmine
@@ -29,13 +31,7 @@ to see how tests are implemented.
 
 Check that the tests pass
 ~~~~~~~~~~~~~~~~~~~~~~~~~
-Check that the Jasmine tests complete sucessfully. Open
-`tests.html <https://github.com/jcbrand/converse.js/blob/master/tests.html>`_
-in your browser, and the tests will run automatically.
-
-Check your code for errors or bad habits by running JSHint
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-If you haven't yet done so, run ``npm install`` to install all development
-dependencies.
+Check that all tests complete sucessfully.
 
-Then run ``grunt jshint`` and check the output.
+Run ``make check`` in your terminal or open `tests.html <https://github.com/jcbrand/converse.js/blob/master/tests.html>`_
+in your browser.

+ 1 - 0
Makefile

@@ -124,6 +124,7 @@ build:: stamp-npm
 ## Tests
 
 check:: stamp-npm
+	$(GRUNT) jshint
 	$(PHANTOMJS) node_modules/phantom-jasmine/lib/run_jasmine_test.coffee tests.html
 
 ########################################################################

+ 1 - 0
docs/source/configuration.rst

@@ -414,6 +414,7 @@ formatted sound files. We need both, because neither format is supported by all
 You can set the URL where the sound files are hosted with the `sounds_path`_
 option.
 
+.. _`prebind_url`:
 
 prebind_url
 -----------

+ 17 - 35
docs/source/development.rst

@@ -114,47 +114,29 @@ depends on need to be loaded.
 Before submitting a pull request
 ================================
 
-Add tests for your bugfix or feature
-------------------------------------
-
-Add a test for any bug fixed or feature added. We use Jasmine
-for testing.
-
-Take a look at ``tests.html`` and ``spec/MainSpec.js`` to see how
-the tests are implemented.
-
-If you are unsure how to write tests, please
-`contact me <http://opkode.com/contact>`_ and I'll be happy to help.
-
-Check that the tests pass
--------------------------
-
-Check that the Jasmine tests complete sucessfully. Open
-`tests.html <https://github.com/jcbrand/converse.js/blob/master/tests.html>`_
-in your browser, and the tests will run automatically.
-
-On the command line you can run:
-
-::
-
-    grunt test
-
-Check your code for errors or bad habits by running JSHint
-----------------------------------------------------------
+Please follow the usual github workflow. Create your own local fork of this repository,
+make your changes and then submit a pull request.
 
-`JSHint <http://jshint.com>`_ will do a static analysis of your code and hightlight potential errors
-and/or bad habits.
-
-::
+Before submitting a pull request
+--------------------------------
 
-    grunt jshint
+Please read the `style guide </docs/html/style_guide.html>`_ and make sure that your code follows it.
 
+Add tests for your bugfix or feature
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Add a test for any bug fixed or feature added. We use Jasmine
+for testing. 
 
-You can run both the tests and jshint in one go by calling:
+Take a look at `tests.html <https://github.com/jcbrand/converse.js/blob/master/tests.html>`_
+and the `spec files <https://github.com/jcbrand/converse.js/blob/master/tests.html>`_
+to see how tests are implemented.
 
-::
+Check that the tests pass
+~~~~~~~~~~~~~~~~~~~~~~~~~
+Check that all tests complete sucessfully.
 
-    grunt check
+Run ``make check`` in your terminal or open `tests.html <https://github.com/jcbrand/converse.js/blob/master/tests.html>`_
+in your browser.
 
 
 Developer API

+ 1 - 0
docs/source/index.rst

@@ -48,6 +48,7 @@ Table of Contents
    setup
    configuration
    development
+   style_guide 
    theming
    translations
    documentation

+ 106 - 0
docs/source/style_guide.rst

@@ -0,0 +1,106 @@
+Software Style Guide
+====================
+
+.. note:: Converse.js currently does not use any of the new ES6 or ES7 features.
+    We don't use a transpiler and still support older browsers, so we only use ES5.
+
+Most of the style guide recommendations here come from Douglas Crockford's book
+"Javascript, the good parts".
+
+This style guide is fairly opinionated. Some of these opinions perhaps don't
+conform to your expectations on how Javascript should be written.
+I apologize for that. However, for the sake of sanity, consistency and having
+code that is pleasing to the eye, please stick to these guidelines.
+
+Tabs or spaces?
+---------------
+
+We always indent 4 spaces.
+
+Proper indentation is very important for harmonious looking code.
+Poor indentation is distracting and causes irritation. When one is distracted and
+irritated, one is not in the relaxed, focused state of mind required for doing quality work.
+
+Underscores or camelCase?
+-------------------------
+
+We use camelCase for function names and underscores for variables names.
+
+For example:
+
+.. code-block:: javascript 
+
+    function thisIsAFunction () {
+        var this_is_a_variable;
+        ...
+    }
+
+Constants are written in ALL CAPS
+---------------------------------
+
+Identifiers that denote constant values should be written in
+all capital letters, with underscores between words.
+
+For example:
+
+.. code-block:: javascript 
+
+    var SECONDS_IN_HOUR = 3600;
+    var seconds_since_message = 0;
+
+
+Function declaration and invocation
+-----------------------------------
+
+When declaring a function, the function name and the brackets after it are separated
+with a space. Like so:
+
+.. code-block:: javascript 
+
+    function update (model) {
+        model.foo = 'bar';
+    }
+
+When calling the same function, the brackets are written without a space in
+between:
+
+.. code-block:: javascript 
+
+    update(model);
+
+This is to make a more explicit visual distinction between method declarations
+and method invocations.
+
+
+Checking for equality
+---------------------
+
+Javascript has a strict ``===`` and less strict ``==`` equality operator. To
+avoid subtle bugs when doing comparisons, always use the strict equality check.
+
+Always enclose blocks in curly brackets
+---------------------------------------
+
+When writing an a block such as an ``if`` or ``while`` statement, always use
+curly brackets around the block of code. Either when not strictly required by
+the compiler.
+
+For example, like this:
+
+.. code-block:: javascript 
+
+    if (condition === true) {
+        this.updateRoomsList();
+    }
+    somethingElse();
+
+and NOT like this:
+
+.. code-block:: javascript
+
+    if (converse.auto_list_rooms)
+        this.updateRoomsList();
+    somethingElse();
+
+This is to aid in readability and to avoid subtle bugs where certain lines are
+wrongly assumed to be executed within a block.

+ 1 - 1
spec/register.js

@@ -238,7 +238,7 @@
                         .c('instructions').t('xform instructions').up()
                         .c('field', {'type': 'text-single', 'var': 'username'}).c('required').up().up()
                         .c('field', {'type': 'text-private', 'var': 'password'}).c('required').up().up()
-                        .c('field', {'type': 'text-single', 'var': 'email'}).c('required').up().up()
+                        .c('field', {'type': 'text-single', 'var': 'email'}).c('required').up().up();
             this.connection._dataRecv(test_utils.createRequest(stanza));
             expect(registerview.form_type).toBe('xform');