XUL Validator – Beta

I put together a simple XUL validator based on the ideas in my last post. There is a primitive front end where you can put XUL into a textarea and validate it. The validator is completely client-side JavaScript with a simple JSON rules file. You can view the source and the rules from the validator “Tests” page.

Currently, the validator checks the structure and semantics of the XUL using the rules given in the last post, with caveats I’ll discuss in a moment. The validator only tests for a subset of the best practices checks. The current tests are listed on the validator “Tests” page. I’ll be adding the rest of the best practice checks soon.

Now, the caveats for the structure checks. There are very few “hard-fast” rules when it comes to XUL. Elements can appear nearly anywhere. Elements can contain any one-off attributes, even made-up ones, which can be useful for CSS selectors. Attribute events, such as “onclick”, can appear on parent elements because events can bubble. The XUL validator, tries to apply some logical warnings and checks, primarily based on the XUL Reference and Tutorial, as well as what I have seen in the Firefox/Thunderbird source code itself.

The current logic is definitely open for discussion and revision! Feedback appreciated.

Update: I made some fixes to the code/rules based on feedback. I also added a small set of options so user can turn off types of checks.

5 thoughts on “XUL Validator – Beta

  1. > There are very few “hard-fast” rules when it comes to XUL.

    Is that a bug or a feature? 🙂

  2. I tried running a few of my XUL files through the validator. Here are the bogus messages:

    1. “unknown attribute: dialog[windowtype]” – well, Gecko recognizes windowtype on a dialog.
    2. “suspicious child element: popupset > tooltip” – according to XUL Tutorial tooltips are supposed to be inside a popupset.
    3. “suspicious child element: popup > menu” – that’s how you define submenus inside a content menu.
    4. “‘title’ should be used to determine window or dialog context” – not if that’s a window inside an overlay. Simply adding elements to a window here.
    5. “unknown attribute: dialog[ondialogextra2]” – the dialog has events associated with all buttons.
    6. “unknown attribute choice: key[modifiers=accel,shift]” – just fine according to XUL Reference.
    7. “unknown attribute: page[xmlns:html]” – yep, you can actually insert HTML in XUL. In this case this namespace was actually a relict however, I removed it 🙂
    8. “unknown attribute: textbox[oncommand]” – textboxes with type=”timed” actually fire the command event.
    9. “suspicious child element: menulist > template”, “suspicious child element: template > menupopup” – yep, templates can be just about anywhere.

    Other than that it outputs quite a few warning messages that should be marked “ignore unless you have a really good reason not too”. Nice tool nevertheless.

  3. Wladimir –

    Thanks for taking the time to run some tests. I updated the code/rules to handle all of your cases except #6 and #9, which I am working on.

    I also added a small set of options so users can “ignore” certain types of checks.

Comments are closed.