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

changing jslint settings inline in a file

Expand Messages
  • firstbakingbook
    I see on other forums that people use jslint comments to change the settings for portions of a file, like /*jslint something: true */
    Message 1 of 2 , Jul 27, 2012
    View Source
    • 0 Attachment
      I see on other forums that people use jslint comments to change the settings for portions of a file, like

      /*jslint something: true */
      something_we_usually_disallow();
      /*jslint something: false */

      Is this expected or supported?

      I'm finding it's very sensitive to where it's placed. For example, this doesn't work:


      /*jslint something: true */
      return something_we_usually_disallow();
      /*jslint something: false */

      jslint complains about an 'unreachable' line after the return statement.

      It also fails in a var declaration, like

      var foo,
      /*jslint something: true */
      bar = something_we_usually_disallow();
      /*jslint something: false */

      where it complains about an unexpected keyword after foo.
    • douglascrockford
      ... The directives are treated as statements, so they can go where statements can go. They respect block scope, so if you turn something on in a block, you
      Message 2 of 2 , Jul 27, 2012
      View Source
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "firstbakingbook" <craft.brian@...> wrote:
        >
        > I see on other forums that people use jslint comments to change the settings for portions of a file, like
        >
        > /*jslint something: true */
        > something_we_usually_disallow();
        > /*jslint something: false */
        >
        > Is this expected or supported?
        >
        > I'm finding it's very sensitive to where it's placed. For example, this doesn't work:
        >
        >
        > /*jslint something: true */
        > return something_we_usually_disallow();
        > /*jslint something: false */
        >
        > jslint complains about an 'unreachable' line after the return statement.
        >
        > It also fails in a var declaration, like
        >
        > var foo,
        > /*jslint something: true */
        > bar = something_we_usually_disallow();
        > /*jslint something: false */
        >
        > where it complains about an unexpected keyword after foo.

        The directives are treated as statements, so they can go where statements can go. They respect block scope, so if you turn something on in a block, you don't have to turn it off at the end of the block.

        But in general, instead of taking time to put directives around bad code, you would be better off investing that time in making the code better.
      Your message has been successfully submitted and would be delivered to recipients shortly.