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

jslint.com issue: copy&paste of displayed /*jslint ... */ line doesn't work as expected

Expand Messages
  • Ger Hobbelt
    Just ran into this. The scenario, now using a small sample: Copy&paste this code into the edit area at jslint.com: - - - - - - - // TAB is ` var dummy_sample =
    Message 1 of 3 , Apr 9, 2011
    • 0 Attachment
      Just ran into this. The scenario, now using a small sample:

      Copy&paste this code into the edit area at jslint.com:

      - - - - - - -
      // TAB is `
      var dummy_sample = {
      `decode: function(s) {
      ``s = s.replace(/\$/g, '%');
      ``s = decodeURIComponent(s);
      ``return s;
      `},
      `removeListener: function(listenerID) { // use the interval ID returned by
      addListener
      ``return clearInterval(listenerID);
      `}
      };
      - - - - - - -

      after you've replaced the ` with TAB (ASCII 09) characters.

      Tick the 'Disallow undefined variables' and 'Assume a browser' checks and
      run jsLint.

      Expected result: ZERO errors.


      At the bottom of the page, this jslint config comment is shown:

      - - - - - - -
      /*jslint undef: true, browser: true, maxerr: 50, indent: 4 */
      - - - - - - -

      which we now include in the code:

      - - - - - - -
      /*jslint undef: true, browser: true, maxerr: 50, indent: 4 */

      // TAB is `
      var dummy_sample = {
      `decode: function(s) {
      ``s = s.replace(/\$/g, '%');
      ``s = decodeURIComponent(s);
      ``return s;
      `},
      `removeListener: function(listenerID) { // use the interval ID returned by
      addListener
      ``return clearInterval(listenerID);
      `}
      };
      - - - - - - -

      and then run jsLint again. (Either with those two checkmarks still ticked or
      not, doesn't matter.)

      Expected result: zero errors.
      Observed result: 2 errors!


      What led to this: the idea that copy&pasting that /*jslint*/ line into the
      code itself would, at a later date, reproduce the jsLint run exactly.
      Without the need to manually set/reset the ticks outside the site defaults.


      Diag:

      I expected the /*jslint*/ line to override (only) the mentioned items, but
      it _seems_ all unmentioned options are also overridden, and oddly enough,
      those seem to be treated as 'true' (checked) all of a sudden. For example,
      'strict whitespace' may show up as unchecked, but the /*jslint*/ line above
      implicitly sets that one to 'true' under the hood.

      The result: only adding the /*jslint*/ line in the code to be linted
      completely changes the report.



      Haven't inspected the site's sourcecode, so can't quote number and verse
      where this is happening, sorry.


      --
      Met vriendelijke groeten / Best regards,

      Ger Hobbelt

      --------------------------------------------------
      web: http://www.hobbelt.com/
      http://www.hebbut.net/
      mail: ger@...
      mobile: +31-6-11 120 978
      --------------------------------------------------


      [Non-text portions of this message have been removed]
    • Douglas Crockford
      ... The option object is used to determine the settings. It is overridden by the /*jslint*/ directive. Any setting that is not mentioned in either is assumed
      Message 2 of 3 , Apr 9, 2011
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, Ger Hobbelt <ger@...> wrote:

        > The result: only adding the /*jslint*/ line in the code to be linted
        > completely changes the report.
        >
        > Haven't inspected the site's sourcecode, so can't quote number and verse
        > where this is happening, sorry.

        The option object is used to determine the settings. It is overridden by the /*jslint*/ directive. Any setting that is not mentioned in either is assumed to be false.
      • Ger Hobbelt
        ... Yeah, that s what I thought. Still, we might talk about slightly different things here and what you say does not match the behaviour I m observing: Note,
        Message 3 of 3 , Apr 9, 2011
        • 0 Attachment
          On Sat, Apr 9, 2011 at 2:27 PM, Douglas Crockford <douglas@...>wrote:

          > The option object is used to determine the settings. It is overridden by
          > the /*jslint*/ directive. Any setting that is not mentioned in either is
          > assumed to be false.
          >

          Yeah, that's what I thought. Still, we might talk about slightly different
          things here and what you say does not match the behaviour I'm observing:

          Note, please, that I mention the jslint.com *website* so it's not an issue
          with the jslint standalone script, but with the jslint.com website only!
          Using the sample code I provided, it actually (on the site!) behaves like
          this: (>>>><<<< emphasis mine)

          test case #1:

          NOT providing any /*jslint*/ line with the code to be linted.

          Result: behaves exactly as when you'ld have this at the top: (1 error)
          /*jslint undef: false, browser: false, maxerr: 50, indent: 4, white:
          >>>>false<<<< */

          Good.


          test case #2:

          manually ticking the 'disallow unused variables' and 'assume browser' items;
          NOT any /*jslint*/ in the code.

          Result: behaves exactly as when you'ld have this at the top: (no errors)
          /*jslint undef: true, browser: true, maxerr: 50, indent: 4, white:
          >>>>false<<<< */

          Good.

          Note that the /*jslint*/ shown at the bottom of the web page now says:
          /*jslint undef: true, browser: true, maxerr: 50, indent: 4 */



          Assumption: copying that /*jslint*/ line into the code should behave like #2
          again, as we wouldn't really change _anything_; just copying the options
          block settings into the code.
          So:


          test case #3:

          This /*jslint*/ at the top of the code:
          /*jslint undef: true, browser: true, maxerr: 50, indent: 4 */

          Result: behaves exactly as when you'ld have this at the top:
          /*jslint undef: true, browser: true, maxerr: 50, indent: 4, white:
          >>>>true<<<< */

          *BAD*

          I did NOT set the 'strict whitespace' setting _anywhere_ on that page, yet
          it automagically kicks in now. I _have_ to explicitly add 'white: false' in
          the /*jslint*/ to get the #2 behaviour again.



          test case #4:

          This /*jslint*/ at the top of the code:
          /*jslint undef: true, browser: true, maxerr: 50, indent: 4, white:
          >>>>false<<<< */

          Result: behaves exactly like #2.

          Good.



          Unless I completely misunderstood, then this behaviour (#3 vs. #2 & #1) is
          not matching

          > The option object is used to determine the settings. It is overridden by
          > the /*jslint*/ directive. Any setting that is not mentioned in either is
          > assumed to be false.
          >
          > as 'strict whitespace' ('white') is not mentioned in the /*jslint*/
          included at the top of the code, while the option section has the checkbox
          _unchecked_, so it should read as 'white:false', but acts as 'white:true'
          instead. And in case you mean something else _entirely_ with the words
          'option object' (and it has white:true as a preset in there), then it still
          behaves counter to the rest of your line, as it should have identical
          behaviour for #2 and #3 (and #1 as well, with respect to the 'strict
          whitespace' setting, that is). Looks like a bug to me. Tell me I screwed
          up all the way, or can you reproduce the issue?



          (Tested with both Safari5 and FF3)


          --
          Met vriendelijke groeten / Best regards,

          Ger Hobbelt

          --------------------------------------------------
          web: http://www.hobbelt.com/
          http://www.hebbut.net/
          mail: ger@...
          mobile: +31-6-11 120 978
          --------------------------------------------------


          [Non-text portions of this message have been removed]
        Your message has been successfully submitted and would be delivered to recipients shortly.