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

JSLint "Unused" list is incomplete.

Expand Messages
  • pauanyu
    function foo(a, b) { var c; } In the above, the local variables a and b are never used, yet they are not listed as Unused . Instead, only c is listed.
    Message 1 of 7 , Aug 20, 2009
    • 0 Attachment
      function foo(a, b) {
      var c;
      }

      In the above, the local variables "a" and "b" are never used, yet they are not listed as "Unused". Instead, only "c" is listed.


      Also, see the example below:

      var foo = function bar() {};

      "bar" is only accessible inside the function (like a local variable), and is never used, yet it is not listed either.
    • Michael Lorton
      ... I don t think that a is unused -- in particular, it makes it possible for b to be declared. Consider the following: function foo(a, b) { var c = b; }
      Message 2 of 7 , Aug 20, 2009
      • 0 Attachment
        pauanyu <pcxunlimited@...> writes:

        > function foo(a, b) {
        > var c;
        > }

        > In the above, the local variables "a" and "b" are never used, yet they are not listed as "Unused". Instead, only "c" is listed.

        I don't think that "a" is unused -- in particular, it makes it possible for b to be declared. Consider the following:

        function foo(a, b) {
        var c = b;
        }

        Without a, how would you tell Javascript that b is the second positional argument? (Of course, since c is unused, b is unnecessary; and since b is unnecessary, a is unnecessary, but that's a lot of shaky calculations for just a warning.)


        > var foo = function bar() {};

        > "bar" is only accessible inside the function (like a local variable), and is never used, yet it is not listed either.

        Look at foo.name.


        M.
      • pauanyu
        ... I have to wonder... if you never use the variable a in your code, why do you need b to be the second argument? Why not write: function foo(b) { var c =
        Message 3 of 7 , Aug 20, 2009
        • 0 Attachment
          --- In jslint_com@yahoogroups.com, Michael Lorton <mlorton@...> wrote:
          >
          > I don't think that "a" is unused -- in particular, it makes it possible for b to be declared. Consider the following:
          >
          > function foo(a, b) {
          > var c = b;
          > }
          >
          > Without a, how would you tell Javascript that b is the second positional argument? (Of course, since c is unused, b is unnecessary; and since b is unnecessary, a is unnecessary, but that's a lot of shaky calculations for just a warning.)
          >

          I have to wonder... if you never use the variable "a" in your code, why do you need "b" to be the second argument? Why not write:

          function foo(b) {
          var c = b;
          }

          ?

          >
          > Look at foo.name.
          >

          Function name is non-standard. If it were ever standardized, it may not retain the same functionality. Regardless, my point about unused arguments still stands.
        • Michael Lorton
          ... do you need b to be the second argument? ... The otherwise always-sharp Pauanyu had a senior moment there and forgot about object-oriented programming,
          Message 4 of 7 , Aug 21, 2009
          • 0 Attachment
            > I have to wonder... if you never use the variable "a" in your code, why
            do you need "b" to be the second argument?

            :-O

            The otherwise always-sharp Pauanyu had a senior moment there and forgot about object-oriented programming, wherein a method-function has to conform to the signature defined in the super-class, regardless of its own implementation. One moderately popular OO language, C++, even allows you to declare anonymous positional parameters, just so you can declare a conforming method with unused parameters.

            The following works (but doesn't pass JSLint of course -- too bad).

            Subclass.prototype.overridingMethod = function(_, _, b) { ... }

            M.




            ________________________________
            From: pauanyu <pcxunlimited@...>
            To: jslint_com@yahoogroups.com
            Sent: Thursday, August 20, 2009 6:03:04 PM
            Subject: [jslint] Re: JSLint "Unused" list is incomplete.

            --- In jslint_com@yahoogroups.com, Michael Lorton <mlorton@...> wrote:
            >
            > I don't think that "a" is unused -- in particular, it makes it possible for b to be declared. Consider the following:
            >
            > function foo(a, b) {
            > var c = b;
            > }
            >
            > Without a, how would you tell Javascript that b is the second positional argument? (Of course, since c is unused, b is unnecessary; and since b is unnecessary, a is unnecessary, but that's a lot of shaky calculations for just a warning.)
            >

            I have to wonder... if you never use the variable "a" in your code, why do you need "b" to be the second argument? Why not write:

            function foo(b) {
            var c = b;
            }

            ?

            >
            > Look at foo.name.
            >

            Function name is non-standard. If it were ever standardized, it may not retain the same functionality. Regardless, my point about unused arguments still stands.



            ------------------------------------

            Yahoo! Groups Links



            [Non-text portions of this message have been removed]
          • inexorabletash
            ... Compatibility with an existing API. For example, you re implementing a callback function and the caller provides two arguments. Admittedly, you could
            Message 5 of 7 , Aug 21, 2009
            • 0 Attachment
              --- In jslint_com@yahoogroups.com, "pauanyu" <pcxunlimited@...> wrote:
              >
              > I have to wonder... if you never use the variable "a" in your code, why do you need "b" to be the second argument?

              Compatibility with an existing API. For example, you're implementing a callback function and the caller provides two arguments.

              Admittedly, you could declare your function with no arguments and dig b out with arguments[1] but that's just yucky and plays havoc with language-savvy IDEs.

              FWIW, the "pylint" checker over in python-land recommends using _ for unused positional arguments, e.g.:

              def foo(_, b):
              c = b

              This occurs frequently in another guise in python: tuple unpacking, e.g.:

              for a, _, c in array_of_triples:
              do_something(a, c)

              (I don't know if there is a PEP representing this usage, and I'm also not advocating this pattern for JavaScript/jslint.)
            • pauanyu
              ... That is true, but I m not advocating it throw an error. Simply that it would show up in the Unused list in the summary. I have had plenty of times where
              Message 6 of 7 , Aug 21, 2009
              • 0 Attachment
                --- In jslint_com@yahoogroups.com, "inexorabletash" <inexorabletash@...> wrote:
                >
                > Compatibility with an existing API. For example, you're implementing a callback function and the caller provides two arguments.
                >
                > Admittedly, you could declare your function with no arguments and dig b out with arguments[1] but that's just yucky and plays havoc with language-savvy IDEs.
                >
                > FWIW, the "pylint" checker over in python-land recommends using _ for unused positional arguments, e.g.:
                >
                > def foo(_, b):
                > c = b
                >
                > This occurs frequently in another guise in python: tuple unpacking, e.g.:
                >
                > for a, _, c in array_of_triples:
                > do_something(a, c)
                >
                > (I don't know if there is a PEP representing this usage, and I'm also not advocating this pattern for JavaScript/jslint.)
                >

                That is true, but I'm not advocating it throw an error. Simply that it would show up in the "Unused" list in the summary. I have had plenty of times where I'll write a function with multiple arguments, later on I no longer need some of the arguments, but they're still defined, causing confusion and inefficiency.

                Personally, I suffer from that problem far more often than I do from having to create backwards-compatible APIs, but that's probably just my personal experience.

                P.S. That's rather interesting usage in Python. It certainly does solve the problem, at least partially.
              • pauanyu
                ... Sorry, I write functional, not object-oriented, so I ve never had any reason to have intentionally-unused arguments, though I can see that others might
                Message 7 of 7 , Aug 21, 2009
                • 0 Attachment
                  --- In jslint_com@yahoogroups.com, Michael Lorton <mlorton@...> wrote:
                  >
                  > :-O
                  >
                  > The otherwise always-sharp Pauanyu had a senior moment there and forgot about object-oriented programming, wherein a method-function has to conform to the signature defined in the super-class, regardless of its own implementation. One moderately popular OO language, C++, even allows you to declare anonymous positional parameters, just so you can declare a conforming method with unused parameters.
                  >
                  > The following works (but doesn't pass JSLint of course -- too bad).
                  >
                  > Subclass.prototype.overridingMethod = function(_, _, b) { ... }
                  >
                  > M.
                  >

                  Sorry, I write functional, not object-oriented, so I've never had any reason to have intentionally-unused arguments, though I can see that others might need that.

                  I like the idea of using _ to indicate that it's an intentionally-unused argument. Maybe Douglas should consider adding that feature into JSLint?
                Your message has been successfully submitted and would be delivered to recipients shortly.