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

Strict white space bug?

Expand Messages
  • biggeleben
    Hi, after hours of figuring out why my code fails JSLINT s validation (edition 2010-12-23), I decided to post here. The original code uses some jQuery chains,
    Message 1 of 6 , Dec 29, 2010
    • 0 Attachment
      Hi,

      after hours of figuring out why my code fails JSLINT's validation (edition 2010-12-23), I decided to post here. The original code uses some jQuery chains, but I will give some simplified examples in the following that focus on "strict white space".

      The first example works - of course:

      /*jslint white: true */
      /*globals one, two */

      one(
      two()
      );

      Now, we extend this example by adding options to the second function:

      /*jslint white: true */
      /*globals one, two */

      one(
      two({
      works: true
      })
      );

      Next, we add a third function. This example still passes the validation:

      /*jslint white: true */
      /*globals one, two, three */

      one(
      two(
      three()
      )
      );

      No surprises so far. However, the next code will fail, although it's analog to the second example:

      /*jslint white: true */
      /*globals one, two, three */

      one(
      two(
      three({
      works: false
      })
      )
      );

      JSLINT says "Problem at line 7 character 13: Expected 'works' to have an indentation at 5 instead at 13." and "Problem at line 8 character 9: Expected '}' to have an indentation at 1 instead at 9."

      Following these hints, we get the following messy code which actually passes the validation:

      /*jslint white: true */
      /*globals one, two, three */

      one(
      two(
      three({
      works: false
      })
      )
      );

      For me, this is really strange, so that I even consider a bug in the latest JSLINT code. Can anyone help me understanding this? Are there any recent changes concerning JSLINT's indentation checks?

      - Matthias
    • biggeleben
      Please use the fixed width font option to read my previous post properly. Otherwise the indentation gets lost.
      Message 2 of 6 , Dec 29, 2010
      • 0 Attachment
        Please use the "fixed width font" option to read my previous post properly. Otherwise the indentation gets lost.
      • Douglas Crockford
        ... JSLint doesn t like silly indentation schemes. Turn off the Strict Whitespace option.
        Message 3 of 6 , Dec 29, 2010
        • 0 Attachment
          --- In jslint_com@yahoogroups.com, "biggeleben" <biggeleben@...> wrote:
          >
          > Hi,
          >
          > after hours of figuring out why my code fails JSLINT's validation (edition 2010-12-23), I decided to post here. The original code uses some jQuery chains, but I will give some simplified examples in the following that focus on "strict white space".
          >
          > The first example works - of course:
          >
          > /*jslint white: true */
          > /*globals one, two */
          >
          > one(
          > two()
          > );
          >
          > Now, we extend this example by adding options to the second function:
          >
          > /*jslint white: true */
          > /*globals one, two */
          >
          > one(
          > two({
          > works: true
          > })
          > );
          >
          > Next, we add a third function. This example still passes the validation:
          >
          > /*jslint white: true */
          > /*globals one, two, three */
          >
          > one(
          > two(
          > three()
          > )
          > );
          >
          > No surprises so far. However, the next code will fail, although it's analog to the second example:
          >
          > /*jslint white: true */
          > /*globals one, two, three */
          >
          > one(
          > two(
          > three({
          > works: false
          > })
          > )
          > );
          >
          > JSLINT says "Problem at line 7 character 13: Expected 'works' to have an indentation at 5 instead at 13." and "Problem at line 8 character 9: Expected '}' to have an indentation at 1 instead at 9."
          >
          > Following these hints, we get the following messy code which actually passes the validation:
          >
          > /*jslint white: true */
          > /*globals one, two, three */
          >
          > one(
          > two(
          > three({
          > works: false
          > })
          > )
          > );
          >
          > For me, this is really strange, so that I even consider a bug in the latest JSLINT code. Can anyone help me understanding this? Are there any recent changes concerning JSLINT's indentation checks?


          JSLint doesn't like silly indentation schemes.
          Turn off the Strict Whitespace option.
        • biggeleben
          ... Ok, that s a pragmatic solution :) However, the Strict Whitespace option is very helpful. Please think of tons of code and a bunch of developers of which
          Message 4 of 6 , Dec 30, 2010
          • 0 Attachment
            --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...> wrote:
            >
            >> [...]
            >
            > JSLint doesn't like silly indentation schemes.
            > Turn off the Strict Whitespace option.
            >

            Ok, that's a pragmatic solution :) However, the "Strict Whitespace" option is very helpful. Please think of tons of code and a bunch of developers of which some always need a punch to remember code conventions. Turning off that option reopens the door for messy code. Have you ever thought about splitting up this particular option into "Strict Whitespace" and "Strict indentation"?

            I just downloaded the JSLint code and played around a bit. The indentation check relies on "option.white" as well. Patching that single if clause keeps "Strict Whitespace" turned on without caring about indentation. That would be so great as a permanent feature!

            For complex JQuery chains, we still need those "silly" indentation schemes to get readable code. I could patch the JSLint code to even work with silly indentation (just an experiment). But afterwards, I recognized that strict indentation might be not as important as using "inline white spaces" properly, since developers tend to indent things right at least on the block level.
          • spence.randall@ymail.com
            Given the following code (view with fixed width): var tester = (function () { var names = Alex,Brandon,Carl + Don,Edward,Frank,Gale +
            Message 5 of 6 , Apr 28, 2011
            • 0 Attachment
              Given the following code (view with fixed width):

              var tester = (function () {
              var names = 'Alex,Brandon,Carl' +
              'Don,Edward,Frank,Gale' +
              'Hank,Ian,Jack,Ken,Leo'.split(','),
              other = function (test) {
              var string = '';
              return string + test;
              };
              return {
              names: names,
              other: other
              };
              }());

              JSLint reports Error:

              Problem at line 6 character 13: Expected 'var' at column 17, not column 13.
              Problem at line 7 character 13: Expected 'return' at column 17, not column 13.
              Problem at line 8 character 9: Expected '}' at column 13, not column 9.

              Change the code to this:

              var tester = (function () {
              var names = 'Alex,Brandon,Carl,Don,Edward,Frank,Gale,Hank,Ian,Jack,Ken,Leo'.split(','),
              other = function (test) {
              var string = '';
              return string + test;
              };
              return {
              names: names,
              other: other
              };
              }());

              And it doesn't produce an error.
            • Douglas Crockford
              Thanks for pointing out those two problems. Please try it now.
              Message 6 of 6 , Apr 28, 2011
              • 0 Attachment
                Thanks for pointing out those two problems. Please try it now.
              Your message has been successfully submitted and would be delivered to recipients shortly.