You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

There are two tools that will greatly improve the quality of the code in the JS framework, if used consistently. They are: gjslint and JSHint.

Class Metadata

Each class in the FlexJS JS framework needs to have the following member (replace class and package name with relevant information (wink) ):

/**
 * Metadata
 *
 * @type {Object.<string, Array.<Object>>}
 */
org.apache.flex.core.Application.prototype.FLEXJS_CLASS_INFO =
    { names: [{ name: 'Application',
                qName: 'org.apache.flex.core.Application'}] };

This property must hold at least the 'names' array, but must also contain the following metadata information, if relevant:

  1. implemented interfaces:
    org.apache.flex.core.Application.prototype.FLEXJS_CLASS_INFO =
        { names: [{ name: 'Application',
                    qName: 'org.apache.flex.core.Application'}],
          interfaces: [org.apache.flex.core.IBead] };

gjslint

gjslint is the linter that comes with the Google Closure Tools. You can download it from here and get instructions on how to install and use it.

gjslint is a command line tool. The proper use for FlexJS is:

gjslint --strict --disable 0100 -r ./

FlexJS uses the --disable command because it's interface handling relies on a variable on the prototype that is initialised with a 'non primitive' value. You might want to check occasionally with this argument removed, to make sure no actual errors are hidden behind it.

JSHint

JSHint is a fork of the original JavaScript linter, JSLint. JSHint is still under active development and has gathered an amazing feature set over the years. Read all about it here.

In order to check a class against JSHint, copy the code below to the top of the file and then either copy-paste the entire contents (with the new 'header') to the online linter, or run the linter from the editor or command line tool.

/*jshint
    globalstrict: true,
    indent: 2,
    strict: true,
    white: false */
/*global flash, goog, mx, org */

'use strict';

FlexJS uses no 'maxlen' to avoid a warning for long lines caused by long 'goog.require' statements. 'gjslint' takes care of the 80 char enforcement.

  • No labels