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

To Indent or Not to Indent

Expand Messages
  • benxwhite
    I find the indentation requirements for the switch statement are not what I expect. Expected: switch (value) { case 1: case 2: return true; default: return
    Message 1 of 2 , Jul 13, 2009
    • 0 Attachment
      I find the indentation requirements for the switch statement are not
      what I expect.

      Expected:

      switch (value) {
      case 1:
      case 2:
      return true;
      default:
      return false;
      }

      Required:

      switch (value) {
      case 1:
      case 2:
      return true;
      default:
      return false;
      }

      Also, I think it would be nice to allow a single line "if" statement in
      some cases.

      if (typeof value === 'undefined') { return false; }
      if (typeof param === 'undefined') { return false; }

      compared to the currently required indentation

      if (typeof value === 'undefined') {
      return false;
      }
      if (typeof param === 'undefined') {
      return false;
      }

      Could there be some logic added to allow for a single statements within
      an "if" to appear on the same line? (assuming no "else" statement
      appears)

      As an alternative, could you disconnect the "strict white space" option
      from the "indentation" validation?
      I really like having the white space validation, but the above scenarios
      lead me to want the indentation validation disabled.


      [Non-text portions of this message have been removed]
    • Douglas Crockford
      Turn off the Strict whitespace option.
      Message 2 of 2 , Jul 13, 2009
      • 0 Attachment
        Turn off the Strict whitespace option.

        benxwhite wrote:
        > I find the indentation requirements for the switch statement are not
        > what I expect.
        >
        > Expected:
        >
        > switch (value) {
        > case 1:
        > case 2:
        > return true;
        > default:
        > return false;
        > }
        >
        > Required:
        >
        > switch (value) {
        > case 1:
        > case 2:
        > return true;
        > default:
        > return false;
        > }
        >
        > Also, I think it would be nice to allow a single line "if" statement in
        > some cases.
        >
        > if (typeof value === 'undefined') { return false; }
        > if (typeof param === 'undefined') { return false; }
        >
        > compared to the currently required indentation
        >
        > if (typeof value === 'undefined') {
        > return false;
        > }
        > if (typeof param === 'undefined') {
        > return false;
        > }
        >
        > Could there be some logic added to allow for a single statements within
        > an "if" to appear on the same line? (assuming no "else" statement
        > appears)
        >
        > As an alternative, could you disconnect the "strict white space" option
        > from the "indentation" validation?
        > I really like having the white space validation, but the above scenarios
        > lead me to want the indentation validation disabled.
        >
        >
        > [Non-text portions of this message have been removed]
        >
        >
        >
        > ------------------------------------
        >
        > Yahoo! Groups Links
        >
        >
        >
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.