Friday, June 7, 2013

New Dart Tools: dartanalyzer and content_shell

‹prev | My Chain | next›

I am pretty jazzed about getting the beta version of the ICE Code Editor out yesterday. It is the first real Dart application that I pushed out—the first application that is more than an experiment.

I have been thrilled by the progress. Between my awesome #pairwithme partners, my collaborators, and Dart itself, I am amazed that we are nearly done with the “3D Game Programming for Kids” release—the release that is solid enough to support the development in that book.

The people that have been helping out go a long way to ensuring that the code is of high quality. What gives me assurance that the code is doing what it is supposed two is the combination of two tools: dart_analyzer and unittest. Coincidentally both are undergoing significant change requiring me to replace a few things.

I start with dart_analyzer, which parses code to ensure that there are no static typing problems. Dart is “optionally” statically typed, which means that you can specify types, but they will be ignored at compile and run times. Still, there is value in type information, and I make use of that as much as seems appropriate. In addition to making beautiful documentation with type information, tools like dart_analyzer can parse code for potential problems. The problem is that dart_analyzer is going away.

The old dart_analyzer was very good at what it did, but it was a little slow. It was not so slow that I noticed a problem on the command line but it was too slow when used in the Dart Editor to highlight problems (at least that's what I heard, I code in Emacs!).

Anyhow, I need to switch from dart_analyzer with-an-underscore to just dartanalyzer. I start by grabbing the most recent SDK from dartlang.org and then updating my dependencies:
➜  ice-code-editor git:(master) ✗ pub update
Resolving dependencies........
Downloading meta 0.5.13 from hosted...
Downloading unittest 0.5.13 from hosted...
Downloading browser 0.5.13 from hosted...
Dependencies updated!

I try out dartanalyzer:
➜  ice-code-editor git:(master) ✗ dartanalyzer lib/ice.dart 
Analyzing lib/ice.dart...
[warning] There is no such getter 'value' in 'Element' (/home/chris/repos/ice-code-editor/lib/full/copy_dialog.dart, line 46, col 53)
[warning] There is no such getter 'value' in 'Element' (/home/chris/repos/ice-code-editor/lib/full/new_project_dialog.dart, line 26, col 53)
[warning] There is no such getter 'value' in 'Element' (/home/chris/repos/ice-code-editor/lib/full/new_project_dialog.dart, line 33, col 57)
[warning] There is no such getter 'value' in 'Element' (/home/chris/repos/ice-code-editor/lib/full/rename_dialog.dart, line 27, col 53)
[warning] The method 'select' is not defined for the class 'Element' (/home/chris/repos/ice-code-editor/lib/full/share_dialog.dart, line 19, col 9)
[warning] There is no such setter 'disabled' in 'Element' (/home/chris/repos/ice-code-editor/lib/full/share_dialog.dart, line 20, col 9)
6 warnings found.
Ugh. I don't think any of those are legit. So far, I have to say that I am not a fan of dartanalyzer without-an-underscore. The problem occurs when I try to query for an input element so that I can grab the value:
var title = query('.ice-dialog').query('input').value;
The query method returns an instance of Element, which does not have a value getter. But InputElment does have such a getter. So I need to introduce an InputElement getter:
InputElement get _field => query('.ice-dialog').query('input');
This allows me to get the value from the _field getter, which I have declared as an InputElement:
var title = _field.value;
After making similar changes in the other classes, I have satisfied dartanalyzer without-an-underscore:
➜  ice-code-editor git:(master) ✗ dartanalyzer lib/ice.dart
Analyzing lib/ice.dart...
No issues found.
I have to admit that this is an improvement over dart_analyzer. The older version was unable to process js-interop code. I had to institute shell code that ignored js-interop warnings. I may have to perform goofy type casting to satisfy dartanalyzer, but I gain some speed and lose a bunch of useless warnings. So I suppose that counts as a net win.

With dartanalyzer working, I am ready to pre-fix my unit testing solution. Since ICE is browser-based, I need a browser context to run many of the tests. I have been using DumpRenderTree to provide that context. Due to Chrome's switch from webkit to blink, DumpRenderTree is going away. It's replacement is content_shell.

This turns out to be a much simpler affair. Replacing DumpRenderTree with content_shell --dump-render-tree does the trick:
➜  ice-code-editor git:(master) ✗ content_shell --dump-render-tree test/index.html
...
CONSOLE MESSAGE: All 81 tests passed.
CONSOLE MESSAGE: unittest-suite-success
With that, I have my code pre-fixed for changes that will be coming shortly. Now I can get back to regularly scheduled development starting with tonight's #pairwithme.


Day #775

No comments:

Post a Comment