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

Suggestion for new option

Expand Messages
  • crunchy_python
    Hi, I just discovered jslint and it is *great*. Thank you, thank you, thank you! Yes, it did hurt my feelings... but in a good way, except for one case. I
    Message 1 of 2 , Sep 21, 2008
    View Source
    • 0 Attachment
      Hi,

      I just discovered jslint and it is *great*. Thank you, thank you,
      thank you! Yes, it did hurt my feelings... but in a good way, except
      for one case.

      I like to structure my switch statements as follows:

      switch (some_test) {
      case 'a':
      x = 'something';
      break;
      case 'b':
      x = 'else';
      break;
      case 'c':
      x = 'altogether';
      break;
      default:
      throw "unknown case.";
      }

      However, jslint gives me an error message about spacing as it wants
      "case" to be aligned with "switch" (i.e. not indented in the above
      example).

      I found how to change the source of jslint.js to make it work the way
      I want but I think this might be a useful option to add.

      Cheers,
      André
    • William Chapman
      ... André, I ve found that most authoritative, standard references for C, C++, Java, JavaScript, etc., show case statements NOT to be indented relative to the
      Message 2 of 2 , Sep 21, 2008
      View Source
      • 0 Attachment
        On Sun, Sep 21, 2008 at 5:59 PM, crunchy_python <andre.roberge@...>wrote:

        > Hi,
        >
        > I just discovered jslint and it is *great*. Thank you, thank you,
        > thank you! Yes, it did hurt my feelings... but in a good way, except
        > for one case.
        >
        > I like to structure my switch statements as follows:
        >
        > switch (some_test) {
        > case 'a':
        > x = 'something';
        > break;
        > case 'b':
        > x = 'else';
        > break;
        > case 'c':
        > x = 'altogether';
        > break;
        > default:
        > throw "unknown case.";
        > }
        >
        > However, jslint gives me an error message about spacing as it wants
        > "case" to be aligned with "switch" (i.e. not indented in the above
        > example).
        >
        > I found how to change the source of jslint.js to make it work the way
        > I want but I think this might be a useful option to add.
        >
        > Cheers,
        > AndrÃ(c)
        >
        >
        >
        André,

        I've found that most authoritative, standard references for C, C++, Java,
        JavaScript, etc., show case statements NOT to be indented relative to the
        parent switch (expr) statement. I believe this is because switch / case
        constructs are not "structured" in the "structured programming" sense (like,
        from the '80s). I.e., introducing a switch / case construct is equivalent
        to introducing "goto" statements into code. (It's my understanding that
        this is one reason these statements have not found their way into the Python
        language.)

        Therefore, it's probably better - and more orthodox - to think about case
        statements as being "at the same level of indentation" as the parent switch
        statement.

        I've just reverified this matter against my reference books, and several web
        references, e.g.:
        Sun <http://java.sun.com/docs/codeconv/html/CodeConventions.doc6.html>
        Adobe <http://www.adobe.com/devnet/flash/articles/as_bestpractices_06.html>

        jslint hurts my feelings too!

        Ciao,
        -- Bill


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