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

Strict white space inconsistency

Expand Messages
  • Chris
    Hello, I have an example base64 encoding function. As messages in this group are sometimes displayed in a variable-width font, and that may make my question
    Message 1 of 4 , Sep 21, 2009
    • 0 Attachment
      Hello,

      I have an example base64 encoding function. As messages in this group
      are sometimes displayed in a variable-width font, and that may make my
      question harder to understand, I have placed a copy of this function
      with its current white space / indentation here: http://jsbin.com/enolu
      <http://jsbin.com/enolu>
      JSLint issues a warning: "Missing space after '+='." about this section:

      // those four 6-bit numbers are used as indices into the
      // base64 character list
      r +=
      chars[n[0]] +
      chars[n[1]] +
      chars[n[2]] +
      chars[n[3]];

      However, it does not issue a warning about this section, which is
      similarly formatted:

      // these three 8-bit (ASCII) characters become one 24-bit number
      n =
      (s.charCodeAt(c) << 16) +
      (s.charCodeAt(c + 1) << 8) +
      s.charCodeAt(c + 2);


      Both sections have a line break after the equal sign. I don't opine on
      whether this is a good idea or not. I merely wonder whether JSLint
      should warn about the second section, since it warns about the first, or
      perhaps it should ignore the first, as it ignores the second.

      Thanks!

      - Chris



      [Non-text portions of this message have been removed]
    • Douglas Crockford
      ... When I lint this code with strict white space checking: var c, chars, n, r, s; r += chars[n[0]] + chars[n[1]] + chars[n[2]] + chars[n[3]]; n =
      Message 2 of 4 , Sep 21, 2009
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "Chris" <Nielsen.Chris@...> wrote:
        >
        > Hello,
        >
        > I have an example base64 encoding function. As messages in this group
        > are sometimes displayed in a variable-width font, and that may make my
        > question harder to understand, I have placed a copy of this function
        > with its current white space / indentation here: http://jsbin.com/enolu
        > <http://jsbin.com/enolu>
        > JSLint issues a warning: "Missing space after '+='." about this section:
        >
        > // those four 6-bit numbers are used as indices into the
        > // base64 character list
        > r +=
        > chars[n[0]] +
        > chars[n[1]] +
        > chars[n[2]] +
        > chars[n[3]];
        >
        > However, it does not issue a warning about this section, which is
        > similarly formatted:
        >
        > // these three 8-bit (ASCII) characters become one 24-bit number
        > n =
        > (s.charCodeAt(c) << 16) +
        > (s.charCodeAt(c + 1) << 8) +
        > s.charCodeAt(c + 2);
        >
        >
        > Both sections have a line break after the equal sign. I don't opine on
        > whether this is a good idea or not. I merely wonder whether JSLint
        > should warn about the second section, since it warns about the first, or
        > perhaps it should ignore the first, as it ignores the second.

        When I lint this code with strict white space checking:

        var c, chars, n, r, s;
        r +=
        chars[n[0]] +
        chars[n[1]] +
        chars[n[2]] +
        chars[n[3]];
        n =
        (s.charCodeAt(c) << 16) +
        (s.charCodeAt(c + 1) << 8) +
        s.charCodeAt(c + 2);

        I see no warnings.
      • Chris
        ... The warning message can be generated when ONLY Strict white space is checked. Unchecking Strict white space will prevent the warning message. Other
        Message 3 of 4 , Sep 21, 2009
        • 0 Attachment
          --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...> wrote:
          >
          > When I lint this code with strict white space checking:
          >
          > var c, chars, n, r, s;
          > r +=
          > chars[n[0]] +
          > chars[n[1]] +
          > chars[n[2]] +
          > chars[n[3]];
          > n =
          > (s.charCodeAt(c) << 16) +
          > (s.charCodeAt(c + 1) << 8) +
          > s.charCodeAt(c + 2);
          >
          > I see no warnings.
          >

          The warning message can be generated when ONLY "Strict white space" is checked. Unchecking "Strict white space" will prevent the warning message. Other options do not appear to have an effect.

          The warning message is not generated if spaces are used as indentation.

          The warning message is not generated if `chars[n[0]] +` is indented to the same level as `r +=`

          The warning message is not generated if `chars[n[0]] +` is indented two tabs beyond the level of `r +=`

          The warning message is generated in your example code if the following sequence is present:

          var c, chars, n, r, s;[line break]
          [line break]
          r +=[line break]
          [tab]chars[n[0]] +[line break]
          [tab]chars[n[1]] +[line break]
          [tab]chars[n[2]] +[line break]
          [tab]chars[n[3]];[line break]
          [line break]
          n =[line break]
          [tab](s.charCodeAt(c) << 16) +[line break]
          [tab](s.charCodeAt(c + 1) << 8) +[line break]
          [tab]s.charCodeAt(c + 2);[line break]
        • Douglas Crockford
          ... Got it, thanks. Having a conversation about whitespace is really difficult when the conversation is conducted in HTML.
          Message 4 of 4 , Sep 21, 2009
          • 0 Attachment
            --- In jslint_com@yahoogroups.com, "Chris" <Nielsen.Chris@...> wrote:
            >
            > --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@> wrote:
            > >
            > > When I lint this code with strict white space checking:
            > >
            > > var c, chars, n, r, s;
            > > r +=
            > > chars[n[0]] +
            > > chars[n[1]] +
            > > chars[n[2]] +
            > > chars[n[3]];
            > > n =
            > > (s.charCodeAt(c) << 16) +
            > > (s.charCodeAt(c + 1) << 8) +
            > > s.charCodeAt(c + 2);
            > >
            > > I see no warnings.
            > >
            >
            > The warning message can be generated when ONLY "Strict white space" is checked. Unchecking "Strict white space" will prevent the warning message. Other options do not appear to have an effect.
            >
            > The warning message is not generated if spaces are used as indentation.
            >
            > The warning message is not generated if `chars[n[0]] +` is indented to the same level as `r +=`
            >
            > The warning message is not generated if `chars[n[0]] +` is indented two tabs beyond the level of `r +=`
            >
            > The warning message is generated in your example code if the following sequence is present:
            >
            > var c, chars, n, r, s;[line break]
            > [line break]
            > r +=[line break]
            > [tab]chars[n[0]] +[line break]
            > [tab]chars[n[1]] +[line break]
            > [tab]chars[n[2]] +[line break]
            > [tab]chars[n[3]];[line break]
            > [line break]
            > n =[line break]
            > [tab](s.charCodeAt(c) << 16) +[line break]
            > [tab](s.charCodeAt(c + 1) << 8) +[line break]
            > [tab]s.charCodeAt(c + 2);[line break]

            Got it, thanks. Having a conversation about whitespace is really difficult when the conversation is conducted in HTML.
          Your message has been successfully submitted and would be delivered to recipients shortly.