Thursday, October 11, 2012

ACE JavaScript Lint

‹prev | My Chain | next›

Last night I was able to get the ACE editor working fairly well with my fork of Mr Doob's code editor.

There is still one thing that bugs me about ACE. Tab markers:

They are not even tab markers since I have disabled tabs with setUseSoftTabs(true). They are more extra indent markers and they seem unnecessary.

To turn them off, I eventually find setDisplayIndentGuides():
var ace = ace.edit("editor");
With that, I am ready to look at something a little more interesting: JavaScript syntax checking.

In Gaming JavaScript, I had planned to introduce kids to the joys of the Chrome JavaScript console. But ACE supports syntax checking that might not make that necessary. Actually, I'll almost certainly include that anyway because I think it a fun introduction to hacking, but syntax checking can only help.

But, if I set the editor mode to JavaScript:
I am not seeing anything—even if I intentionally add an error.

Eventually, I notice the following in the JavaScript console:

Well, that is easy enough to fix. I copy the JavaScript worker from the ACE source that I downloaded the other day:
➜  code-editor git:(ace) ✗ cp ../ace-builds/src/worker-javascript.js js/ace 
With that, I see an error. Only not the right one:

Darn. I really want to include HTML tags in the Gaming JavaScript editor. I think that I helps to give a better perspective of how all of this fits together. But unfortunately ACE in JavaScript mode sees that HTML as a JavaScript syntax error.

I try switching to HTML/mixed mode instead:
var ace = ace.edit("editor");
But now there are no errors at all:

I do not know how important this really is to me. I may fiddle with the JavaScript worker to see if I can convince it to ignore HTML. I may also investigate Esprima a bit as an alternative. Tomorrow.

Day #537

No comments:

Post a Comment