Code Standards

These are the rules that we follow when we write the aria templates code. Please take a look at it and keep it in mind if you want to contribute pushing code to the aria templates Github repository.

Generic rules

# To be checked Comment
1 JsLint We are using JsLint. New classes should trigger no errors. Please take a look to our #jslint-rules.
2 Error reporting Any $log call should be made with an error referenced in $statics. When adding a new error message, make use of the %N string replacement.
3 Use of assert statements Verify the validity of variables.
4 There is enough logging At least deprecated methods and errors are logged.
5 JsDoc format JsDoc well formated (use only agreed types: String, Number, Object, Boolean, Array, Date, HTMLElement, Function, uic. TextField, flag private classes, methods and properties as such with @private, don't forget the @singleton if needed, don't forget the @protected flag and document usage examples with pre tags)
6 JsDoc well written and english Read through all your doc to make sure no copy/paste are remaining from other methods.
7 Js unit test added Using the aria.jsunit framework.
8 Js unit test passing Complete unit test suite must pass on all supported browser.
9 Js unit test are valid asserTrue(true) is not enough.
10 Reuse existing code Reuse as much as possible of other classes, methods, utilities. Have a look at our utils, dom, etc.
11 Responsibilities are well separated into several classes If the class does multiple different things, it will be harder to maintain, harder to unit test and may grow indefinitely after that. Make sure different responsibilities are handled in different classes that agree on a unit testable API.
12 Destroy DOM references Any class that does dom manipulation, or adds event listeners to dom object may have to keep reference in one way or another to a DOM object. In this case, implement the $destructor of your class to break these DOM references. And finally, call your superclass destructor too: this.$MySuperClass.$
13 Do not extend native objects prototypes Please don't extend native objects prototypes.
14 Do not introduce new globals Do not introduce new global objects.
15 Config beans Any public interface (widgets) should be defined through config beans, also internally, passing very complex objects between classes should be made with config beans. Beans must be defined either in an external beanDefinition class, or via $beans inside the class itself. Make use of .check() and .normalize() to validate your inputs.
16 Config beans documentation Properties of a bean must be documented in plain and understandable english.
17 Memory leaks Make sure you implement the destructor correctly and nullify the DOM element references you might have set. If you created a new widget, create a simple template to be used in the memory leak test application.
18 public/private/protected variables Choose carefully the visibility of your variables.
19 Closures Try not to create functions in closure scope. All functions should be declared at prototype level. Use Aria.empty, Aria.returnTrue or Aria.returnFalse for simple functions otherwise remember to set to null all variables in closure scope that are not needed by the newly defined function.

JsLint rules

For JsLint we are using these rules:

# Rule # Rule
1 Do not assume console, alert 19 Tolerate continue
2 Assume Browser 20 Tolerate ++ and -
3 Do not assume Node.js 21 Tolerate . and [^…] in regexp
4 Do not assume Rhino 22 Tolerate misordered definitions
5 Do not assume Yahoo widget 23 Do not tolerate unused names
6 Do not assume Windows 24 Tolerate missing use strict pragma
7 Do not stop on first error 25 Tolerate inefficient subscripting
8 Do not use safe subset 26 Do not tolerate many var statements per function
9 Do not verify ADsafe 27 Do not tolerate messy white space
10 Do not tolerate bitwise operators 28 Do not tolerate variables (Predef: Aria, aria, test)
11 Tolerate continue 29 Do not tolerate sloppy line breaking
12 Do not tolerate debugger statements 30 Do not tolerate wrapper forms
13 Do not tolerate == and != 31 Do not tolerate missing semicolon
14 Tolerate EcmaScript 5 syntax 32 Do not tolerate missing parens around immediate invocations
15 Do not tolerate eval 33 Do not tolerate unsafe character
16 Do not tolerate unfiltered for in 34 Do not tolerate new Array instead of the array literal notation []
17 Do not tolerate uncapitalized constructors 35 Do not tolerate new Object instead of the object literal notation {}
18 Tolerate dangling _ in identifiers


You can copy/paste our JsLint rules directely from here:

jslint devel: false, bitwise: false, undef: true, browser: true, continue: true, unparam: false, node: false, debug: false, sloppy: true, rhino: false, eqeq: true, widget: false, es5: false, sub: true, windows: false, evil: false, vars: false, forin: false, white: false, passfail: false, newcap: false, nomen: true, plusplus: true, regexp: true, maxerr: 50, maxlen: 120, indent: 4