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

Re: option.unparam

Expand Messages
  • Zhami
    ... Douglas, I don t want to suppress that report for the entire file, as I believe this is yet another valuable warning you have added to JSLint. However,
    Message 1 of 9 , May 6 3:25 PM
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...> wrote:
      >
      > --- In jslint_com@yahoogroups.com, "Zhami" <stuart@> wrote:
      >
      > > I often include names for arguments that aren't used as a form of reminder/documentation (say, for callbacks that are being invoked by libraries that are not mine).
      > >
      > > Perhaps JSLint could allow for a pragma or directive within a function body that indicates that the named argument is intentionally not be used.
      >
      >
      > If you want to suppress that report, set option.unparam to true.
      >

      Douglas,

      I don't want to suppress that report for the entire file, as I believe this is yet another valuable warning you have added to JSLint.

      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.

      I did try turning off the report by an inline comment prior to the declaration of the function:

      /*jslint unparam: false */

      But that didn't work.

      I do think it would be useful to either be able to turn iteh reporting on and off around certain function, or to have a pragma *within* a function:

      /*jslint unparam: varname */

      which would let JSLint know that a named parameter is intentionally not used.

      Thanks for considering this.
    • 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 2 of 9 , May 6 4:00 PM
      • 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 3 of 9 , May 7 7:03 AM
        • 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 4 of 9 , May 7 8:32 AM
          • 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.