Skip to content

Javascript Strict Mode, Unit Tests, and Compressed Output #9

@samnotsowise

Description

@samnotsowise

We need some uniformity in our javascript. From resource loaders to view bridges, the current javascript follows no standards or best practices.

I propose the following:

Strict Mode

We should be writing our javascript using strict mode. There are many good arguments for this, most related to code security. The article I've linked to here is pretty comprehensive and worth a read.

Code Quality Validation

The form of the code should comply with the js lint rule set.

Compiled Output

If we are using strict mode, we must compile the code for client consumption. This should remove the "use strict"; markers and minify the javascript. This can be achieved using the likes of Google's Closure Compiler. Strict mode is usually slower to execute, as the flag triggers additional checks in the interpreter.

Unit Tests

in line with our test coverage goals on the PHP side, we should be aiming for 100% unit test coverage for our javascript. I like the JSTestDriver system, but there are many alternatives we could look into.

Both strict mode and JSLint have full PHPStorm support. There are a number of Composer Closure Compiler packages. JSTestDriver also has a Storm plugin.

Thoughts and suggestions welcomed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions