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

Re: [jslint] Re: Missing Warning

Expand Messages
  • James Clark
    I think it would be sufficient to warn only about using ! in an operand of , =, where (generally speaking) it is clearly unintended. So: !x
    Message 1 of 5 , Sep 28, 2009
    View Source
    • 0 Attachment
      I think it would be sufficient to warn only about using ! in an operand
      of <, >, <=, and >=, where (generally speaking) it is clearly unintended.

      So:
      !x < y // bad

      Warning about the same for ==, ===, !=, and !==, and warning about !(x
      == y) would be OK if you want, but hypothetically those construct might
      be used for good.

      -jamie

      Douglas Crockford wrote:
      >
      >
      > --- In jslint_com@yahoogroups.com <mailto:jslint_com%40yahoogroups.com>,
      > Jean-Charles Meyrignac <jcmeyrignac@...> wrote:
      > >
      > > Just found a nasty bug, in Adobe Spry Tabbed Panels:
      > >
      > >
      > http://labs.adobe.com/technologies/spry/widgets/tabbedpanels/SpryTabbedPanels.js
      > <http://labs.adobe.com/technologies/spry/widgets/tabbedpanels/SpryTabbedPanels.js>
      > >
      > > The bug is here:
      > > if (!tpIndex < 0 || tpIndex >= this.getTabbedPanelCount())
      > > return;
      > >
      > > The error is:
      > > !tpIndex < 0
      > > instead of:
      > > tpIndex < 0
      > >
      > > Could JsLint be able to send a warning in this case ?
      >
      > JSLint could complain when an operand of a relational operator is a !
      > expression. And it could complain when a relational expression is an
      > operand of a ! expression.
      > comparison operator.
      >
      > If I were to do this,
      >
      > !(x === y) // bad
      > !x === y // bad
      >
      > I don't know that that should increase your confidence about Spry.
      > A naive fix of the warning will make things worse, producing
      > something, like
      >
      > if (tpIndex >= 0 || tpIndex >= this.getTabbedPanelCount())
      >
      > Comments?
      >
      >
      >
      > ------------------------------------------------------------------------
      > *This message has been 'sanitized'. This means that potentially
      > dangerous content has been rewritten or removed. The following log
      > describes which actions were taken. *
      >
      >
      > Sanitizer (start="1254155399"):
      > Split unusually long word(s) in header.
      > Part (pos="3362"):
      > SanitizeFile (filename="unnamed.txt", mimetype="text/plain"):
      > Match (names="unnamed.txt", rule="2"):
      > Enforced policy: accept
      >
      > Total modifications so far: 1
      >
      > Part (pos="4495"):
      > SanitizeFile (filename="unnamed.html, filetype.html", mimetype="text/html"):
      > Match (names="unnamed.html, filetype.html", rule="4"):
      > ScanFile (file="/home/antivirus/quarantine/att-unnamed.html.1FX"):
      > Scan succeeded, file is clean.
      >
      > Enforced policy: accept
      >
      >
      >
      > Anomy 0.0.0 : Sanitizer.pm $Id: Sanitizer.pm,v 1.94 2006/01/02 16:43:10
      > bre Exp $
      >
    • Jean-Charles Meyrignac
      ... In my opinion, the first line is correct, and the second one is suspicious. About Spry, I had to build a quick prototype with tabs, and I got a Javascript
      Message 2 of 5 , Sep 29, 2009
      View Source
      • 0 Attachment
        > JSLint could complain when an operand of a relational operator is a ! expression. And it could complain when a relational expression is an
        > operand of a ! expression.
        > comparison operator.
        >
        > If I were to do this,
        >
        > !(x === y) // bad
        > !x === y // bad
        >
        > I don't know that that should increase your confidence about Spry.
        >

        In my opinion, the first line is correct, and the second one is suspicious.
        About Spry, I had to build a quick prototype with tabs, and I got a
        Javascript error within a few minutes.
        It took me a couple of minutes to locate and fix the problem, so I
        don't really trust Spry anymore.

        What is interesting for JsLint is that this kind of error could be
        discovered with source analysis.
        I *love* source code analysis since I discovered PCLint (in 1996).
        Imagine my delight when I discovered JsLint !

        On Mon, Sep 28, 2009 at 6:54 PM, James Clark <sbj@...> wrote:
        >
        > I think it would be sufficient to warn only about using ! in an operand
        > of <, >, <=, and >=, where (generally speaking) it is clearly unintended.
        >
        > So:
        > !x < y // bad
        >
        > Warning about the same for ==, ===, !=, and !==, and warning about !(x
        > == y) would be OK if you want, but hypothetically those construct might
        > be used for good.
        >
        In my common usage, I only use ! as a boolean operator.

        Some valid examples:
        !(expression1) | expression2
        !(expression1) || expression2
        !(expression1) & expression2
        !(expression1) && expression2
        are fine for me

        Mixing types should be prohibited:
        !(expression) + expression2
        !(expression) > expression2
        are bad.

        And I express doubts about:
        !(expression) == expression2
        since it's clearer as:
        expression != expression2

        Any expression involving a ! should at least display an optional warning.

        JC
      • Douglas Crockford
        ... I think you meant !(expression === expression2) Clearly there are hazards here.
        Message 3 of 5 , Sep 29, 2009
        View Source
        • 0 Attachment
          --- In jslint_com@yahoogroups.com, Jean-Charles Meyrignac <jcmeyrignac@...> wrote:
          > And I express doubts about:
          > !(expression) == expression2
          > since it's clearer as:
          > expression != expression2

          I think you meant

          !(expression === expression2)

          Clearly there are hazards here.
        Your message has been successfully submitted and would be delivered to recipients shortly.