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

Re: [jslint] Re: option.unparam

Expand Messages
  • Joshua Bell
    ... FWIW, I adopted the approach typically used in C/C++ to silence such warnings without disabling them: (function (global) { function unused() {} function
    Message 1 of 9 , May 6, 2011
    • 0 Attachment
      On Fri, May 6, 2011 at 3:25 PM, Zhami <stuart@...> wrote:

      > However, sometime the function is a callback and the unused param is
      > left-wards of a param that I do use, and so must name the unused param to
      > properly position.
      >

      FWIW, I adopted the approach typically used in C/C++ to silence such
      warnings without disabling them:

      (function (global) {

      function unused() {}

      function sample_function(a, b, c, d) {
      unused(b, d);
      // ....
      }

      }(this));

      On the one hand, it is reasonably self-documenting and modern JS
      environments should optimize this away. On the other, it's repetitive
      clutter to include in every module, and seems hackish. (Perhaps we should
      petition TC39 for Function.unused() or another standard no-op function.)

      -- Josh


      [Non-text portions of this message have been removed]
    • Zhami
      ... Yes, there are ways to use effective no-ops to silence the warning (I just assign the unused parameter to a junk variable), but any such code-based
      Message 2 of 9 , May 7, 2011
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, Joshua Bell <josh@...> wrote:
        >
        > On Fri, May 6, 2011 at 3:25 PM, Zhami <stuart@...> wrote:
        >
        > > However, sometime the function is a callback and the unused param is
        > > left-wards of a param that I do use, and so must name the unused param to
        > > properly position.
        > >
        >
        > FWIW, I adopted the approach typically used in C/C++ to silence such
        > warnings without disabling them:
        >
        > (function (global) {
        >
        > function unused() {}
        >
        > function sample_function(a, b, c, d) {
        > unused(b, d);
        > // ....
        > }
        >
        > }(this));
        >
        > On the one hand, it is reasonably self-documenting and modern JS
        > environments should optimize this away. On the other, it's repetitive
        > clutter to include in every module, and seems hackish. (Perhaps we should
        > petition TC39 for Function.unused() or another standard no-op function.)

        Yes, there are ways to use effective no-ops to silence the warning (I just assign the unused parameter to a junk variable), but any such code-based approach is a code solution to a non-code problem. What really is needed is a way to tell JSLint that the param is not actually used.
      • Rob Richardson
        I d like to know when I ve passed in more parameters than the function will use: /*jslint white: true, onevar: true, undef: true, nomen: true, regexp: true,
        Message 3 of 9 , May 7, 2011
        • 0 Attachment
          I'd like to know when I've passed in more parameters than the function will
          use:

          /*jslint white: true, onevar: true, undef: true, nomen: true, regexp: true,
          plusplus: true, bitwise: true, newcap: true */
          (function () {
          `
          ` var a = function (one, two) {
          ` // ...
          ` };
          `
          ` a(1, 2, 3); // <-- I've passed in too many
          `
          }());

          I grant that some functions declare themselves as having no (or fewer)
          parameters, then inspect arguments to handle them all, but this is confusing
          for the novice user of this code.

          Rob
        Your message has been successfully submitted and would be delivered to recipients shortly.