Loading ...
Sorry, an error occurred while loading the content.

Dojo and JSLint?

Expand Messages
  • fjcastan
    I ve been exprimenting with mixing jslint and the dojo editor to make syntax checking script editor. I ve noticed that something in jslint seems to conflict
    Message 1 of 4 , Sep 14, 2008
    • 0 Attachment
      I've been exprimenting with mixing jslint and the dojo editor to make
      syntax checking script editor.

      I've noticed that something in jslint seems to conflict with
      something in dojo when when they are running together. Take the
      following test html:

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
      "http://www.w3.org/TR/html4/strict.dtd">
      <html>
      <head>

      <title>dojox.highlight - syntax highlighting | The Dojo
      Toolkit</title>

      <style type="text/css">
      @import "dijit/tests/css/dijitTests.css";

      /* a sample set of definitions to use as a foundation
      to color your code */
      @import "dojox/highlight/resources/highlight.css";

      /* additional styling for this test case */
      pre code[class]:after {
      content: 'highlight: ' attr(class);
      display: block; text-align: right;
      font-size: smaller;
      color: #CCC; background: white;
      border-top: solid 1px;
      padding-top: 0.5em;
      }

      pre code {
      display: block;
      }

      code {
      background: #F0F0F0;
      }

      pre code,
      .ruby .subst {
      color: black;
      }
      </style>

      <script type="text/javascript" djConfig="parseOnLoad: true,
      isDebug: true" src="dojo/dojo.js"></script>
      <script type="text/javascript"
      src="dojox/highlight/_base.js"></script>
      <script type="text/javascript" src="jslint.js"></script>


      <script type="text/javascript">
      // initHighlightOnLoad is deprecated.
      // if parseOnLoad==true, the onLoad init stuff is run.
      // if parseOnLoad==false, you can call
      dojox.highlight.init(domNode)
      //
      // utilizing the dojo build system, the
      dojox.highlight engine
      // will "do it's best" based on the language maps
      available
      // at the time of construction.
      //
      dojo.require("dojox.highlight");
      dojo.require("dijit.dijit"); // optimize: load dijit
      layer
      dojo.require("dijit.Editor");
      dojo.require
      ("dijit._editor.plugins.AlwaysShowToolbar");
      dojo.require
      ("dijit._editor.plugins.EnterKeyHandling");
      dojo.require
      ("dijit._editor.plugins.FontChoice"); // 'fontName','fontSize','forma
      tBlock'
      dojo.require("dijit._editor.plugins.TextColor");
      dojo.require("dijit._editor.plugins.LinkDialog");
      dojo.require("dojo.parser");

      // several layer-like files have been provided
      grouping
      // similar langauges, and a catch all language module
      // dojox.highlight.languages._all is available
      for "best results"

      // we need some language definitions:
      dojo.require("dojox.highlight.languages._all");
      var lazyCode = function(){

      dojo.query("code").forEach
      (dojox.highlight.init);

      dojo.xhrGet({
      url: "dojox/highlight/base.js",
      load: function(data){
      var n = dojo.byId("foobar"),
      c =
      document.createElement('div'),
      e =
      n.parentNode.parentNode;

      JSLINT(data);
      for (var i = 0; (i < JSLINT.errors.length) &&
      (JSLINT.errors[i]); i++) {
      console.debug
      ("line:"+JSLINT.errors[i].line+", character:"+JSLINT.errors
      [i].character+", reason:"+JSLINT.errors[i].reason);
      };
      c.innerHTML = '<pre><code
      class="javascript">' + data.replace(/\</gi,"<") + '</code></pre>';
      e.replaceChild(c.firstChild,
      n.parentNode);
      dojo.query("pre > code",
      e).forEach(dojox.highlight.init);
      }
      });
      };
      dojo.addOnLoad(lazyCode);

      </script>
      </head>
      <body>

      <h1 class="testTitle">dojox.highlight</h1>

      <p>client-side syntax highlighting for a number of
      languages.</p>

      <p>this is a trimmed down version of the dojox.highlight test
      designed to show highlight and jslint working together.</p>

      <p>Lazy, xhr'd code here:</p>
      <pre><code id="foobar"></code></pre>

      <div dojoType="dijit.Editor" height="1.5em" plugins="[]"
      focusOnLoad="true" style="border:0px;">
      </div>
      <p>End of test</p>

      </body></html>


      I consistently get a "node has no properties" error in dojo 1.1 when
      JSLINT is included. I have not narrowed the error down, but I was
      curious if anyone had any insight to the problem. Doug, have you
      considered building a dojo widget for JSLint?

      I have built a widget that calls JSLint via a hidden iFrame, kinda of
      weird hack/work around, but it does work and gets around this error.

      I did try a few different versions of JSLint I had lying around and
      interestingly the problem is does not occur with an old version dated
      2007-01-31. So this conflict was introduced between 2007-01-31 and
      2008-06-29. I know thats a pretty big gap but that's all the archived
      vversions I had on my system.

      Still hacking around, Thanks,
      - Frank Castaneda
    • Douglas Crockford
      ... Please let me know if you find out what it is. If it is failing on the dojo side, then it is likely a dojo problem that is triggered by something that
      Message 2 of 4 , Sep 15, 2008
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "fjcastan" <fjcastan@...> wrote:
        >
        > I've been exprimenting with mixing jslint and the dojo editor to make
        > syntax checking script editor.
        >
        > I've noticed that something in jslint seems to conflict with
        > something in dojo when when they are running together.

        > I consistently get a "node has no properties" error in dojo 1.1 when
        > JSLINT is included. I have not narrowed the error down, but I was
        > curious if anyone had any insight to the problem.

        Please let me know if you find out what it is. If it is failing on the
        dojo side, then it is likely a dojo problem that is triggered by
        something that JSLint does.

        > Doug, have you considered building a dojo widget for JSLint?

        No.
      • fjcastan
        ... make ... when ... the ... The culprit appears to be here: (line 497 of fulljslint.hs) Object.prototype.union = function (o) { var n; for (n in o) if
        Message 3 of 4 , Sep 15, 2008
        • 0 Attachment
          --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...>
          wrote:
          >
          > --- In jslint_com@yahoogroups.com, "fjcastan" <fjcastan@> wrote:
          > >
          > > I've been exprimenting with mixing jslint and the dojo editor to
          make
          > > syntax checking script editor.
          > >
          > > I've noticed that something in jslint seems to conflict with
          > > something in dojo when when they are running together.
          >
          > > I consistently get a "node has no properties" error in dojo 1.1
          when
          > > JSLINT is included. I have not narrowed the error down, but I was
          > > curious if anyone had any insight to the problem.
          >
          > Please let me know if you find out what it is. If it is failing on
          the
          > dojo side, then it is likely a dojo problem that is triggered by
          > something that JSLint does.

          The culprit appears to be here: (line 497 of fulljslint.hs)
          Object.prototype.union = function (o) {
          var n;
          for (n in o) if (o.hasOwnProperty(n)) {
          this[n] = o[n];
          }
          };

          and: (line 544 of dijit/_Widget.js)
          _attrToDom function in dijit._Widget attempts to copy attributes from
          a dom node and is failing because of the way its iterating through a
          list and picking up that union function. I'll look further into a fix
          from the dojo side, but it may be a more appropriate fix, to change
          it in JSLint, though I have not looked exactly how this union
          function is used.

          >
          > > Doug, have you considered building a dojo widget for JSLint?
          >
          > No.
          >

          Would you be interested in contributing JSLint to dojo? I'm currently
          working on contributing some stuff that we have on the plate possibly
          in 1.3. I can "widgetize" and test this.
        • Douglas Crockford
          ... I hope Dojo fixes it. It should be more resilient. The fix is easy. Have them contact me if they have trouble. ... You don t need permission. Everything
          Message 4 of 4 , Sep 17, 2008
          • 0 Attachment
            --- In jslint_com@yahoogroups.com, "fjcastan" <fjcastan@...> wrote:
            > I'll look further into a fix
            > from the dojo side, but it may be a more appropriate fix, to change
            > it in JSLint, though I have not looked exactly how this union
            > function is used.

            I hope Dojo fixes it. It should be more resilient. The fix is easy.
            Have them contact me if they have trouble.

            > Would you be interested in contributing JSLint to dojo? I'm currently
            > working on contributing some stuff that we have on the plate possibly
            > in 1.3. I can "widgetize" and test this.

            You don't need permission. Everything you need is at
            http://jslint.com/fulljslint.js

            All I ask is that you keep it up to date.
          Your message has been successfully submitted and would be delivered to recipients shortly.