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

possible erroneous warning due to multi-line layout

Expand Messages
  • Zhami
    I am receiving a warning about mis-positioning of text. My practice is to declare my vars on multiple lines, where I distinguish vars that hold variables from
    Message 1 of 7 , May 12, 2011
    View Source
    • 0 Attachment
      I am receiving a warning about mis-positioning of text.
      My practice is to declare my vars on multiple lines, where I distinguish
      vars that hold variables from vars that hold functions, as is done in
      the code snippet below (I have hollowed this out from actual code).
      I use tabs for indenting, but substitute with leading periods so that
      they are preserved ... please convert back to examine this in JSLint, or
      pull from my gist: https://gist.github.com/969076
      (function () {."use strict";
      .var processTheForm;
      .processTheForm = function () {
      ..var resultObjHash,...// functions...createElemHandler,
      createResultObj;
      ..createElemHandler = function () {..}; ..createResultObj = function ()
      {..}; ..resultObjHash = {}; .};}());
      JSLint reportsProblem at line 11 character 32: Expected
      'createResultObj' at column 13, not column 32.
      This warning will go away if a second non-function var is declared on
      the first line of the var statement, as in:
      ..var resultObjHash, another,
      I believe that the warning reported when only one var is declared on the
      first line is innapropriate.







      [Non-text portions of this message have been removed]
    • Douglas Crockford
      ... You have two options. You can either format it like this: (function () { ```` use strict ; ````var processTheForm; ````processTheForm = function () {
      Message 2 of 7 , May 12, 2011
      View Source
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "Zhami" <stuart@...> wrote:
        >
        > I am receiving a warning about mis-positioning of text.
        > My practice is to declare my vars on multiple lines, where I distinguish
        > vars that hold variables from vars that hold functions, as is done in
        > the code snippet below (I have hollowed this out from actual code).
        > I use tabs for indenting, but substitute with leading periods so that
        > they are preserved ... please convert back to examine this in JSLint, or
        > pull from my gist: https://gist.github.com/969076
        > (function () {."use strict";
        > .var processTheForm;
        > .processTheForm = function () {
        > ..var resultObjHash,...// functions...createElemHandler,
        > createResultObj;
        > ..createElemHandler = function () {..}; ..createResultObj = function ()
        > {..}; ..resultObjHash = {}; .};}());
        > JSLint reportsProblem at line 11 character 32: Expected
        > 'createResultObj' at column 13, not column 32.
        > This warning will go away if a second non-function var is declared on
        > the first line of the var statement, as in:
        > ..var resultObjHash, another,
        > I believe that the warning reported when only one var is declared on the
        > first line is innapropriate.


        You have two options. You can either format it like this:

        (function () {
        ````'use strict';
        ````var processTheForm;
        ````processTheForm = function () {
        ````````var resultObjHash, // functions
        ````````````createElemHandler,
        ````````````createResultObj;
        ````````createElemHandler = function () {
        ````````};
        ````````createResultObj = function () {
        ````````};
        ````````resultObjHash = {};
        ````};
        }());

        or you can turn off the strict whitespace option.
      • Cheney, Edward A SSG RES USAR USARC
        Classification: UNCLASSIFIED JSLint expects variables in a var keyword list to receive an extra indentation and then for this indentation level to be reverted
        Message 3 of 7 , May 12, 2011
        View Source
        • 0 Attachment
          Classification: UNCLASSIFIED
          JSLint expects variables in a var keyword list to receive an extra indentation and then for this indentation level to be reverted one count at the conclusion of the keyword list. This is typically an easy practice follow, except for a few rare cases, such as (periods mean indentation):

          var a = function () {
          .var startTime = (function () {
          ..var d = "start";
          ..},
          ..b,
          ..c;
          };

          This is a pain because line 4 is the closing of a block that is on the same level of indentation as the blocks contents, which would typically be indented an additional count. An additional count of indentation would mean that the third line is indented 3 times instead of 2. Fortunately, JSLint does not care either way, but it is a huge pain in the ass to program software that beautifies in accordance with the white space algorithm. I say its a pain, because the change mentioned here is minor to demonstrate, but is a pain to put into an existing pattern and causes problems with complex object assignments in object literals.

          I do have one complaint/question. Why would you do this:

          var processTheForm;
          processTheForm = function () {...

          Instead you could do this:
          var processTheForm = function () {...

          These are identical to the interpreter. The only exception is if the function is an example of immediate invocation. Immediately invoked functions are the value and type they return instead of type object.

          Austin Cheney, CISSP
          http://prettydiff.com/
          Classification: UNCLASSIFIED
        • spence.randall@ymail.com
          ... If the processTheForm function refers to itself (no idea based on the code supplied of course since they were empty), then you have to declare it first,
          Message 4 of 7 , May 12, 2011
          View Source
          • 0 Attachment
            > I do have one complaint/question. Why would you do this:
            >
            > var processTheForm;
            > processTheForm = function () {...
            >
            > Instead you could do this:
            > var processTheForm = function () {...
            >
            > These are identical to the interpreter. The only exception is if the function is an example of immediate invocation. Immediately invoked functions are the value and type they return instead of type object.
            >
            > Austin Cheney, CISSP
            > http://prettydiff.com/
            > Classification: UNCLASSIFIED
            >

            If the processTheForm function refers to itself (no idea based on the code supplied of course since they were empty), then you have to declare it first, otherwise you get a warning in JSLint 'processTheForm' has not been fully defined yet.

            -Randall
          • ossayu
            The following also works: (function () { ```` use strict ; ````var processTheForm; ````processTheForm = function () { ````````var resultObjHash, ````````````//
            Message 5 of 7 , May 13, 2011
            View Source
            • 0 Attachment
              The following also works:

              (function () {
              ````'use strict';
              ````var processTheForm;
              ````processTheForm = function () {
              ````````var resultObjHash,
              ````````````// functions
              ````````````createElemHandler,
              ````````````createResultObj;
              ````````createElemHandler = function () {
              ````````};
              ````````createResultObj = function () {
              ````````};
              ````````resultObjHash = {};
              ````};
              }());

              That said, why is there no warning if there is a second variable declared on the line with the var keyword, as in:

              The following also works:

              (function () {
              ````'use strict';
              ````var processTheForm;
              ````processTheForm = function () {
              ````````var resultObjHash, anotherVar,
              ````````````// functions
              ````````````createElemHandler, createResultObj;
              ````````createElemHandler = function () {
              ````````};
              ````````createResultObj = function () {
              ````````};
              ````````resultObjHash = {};
              ````};
              }());
            • Zhami
              ... Two reasons: 1) because I don t do the former... there were a number of names declared as variables. 2) I don t like to clutter the list of variable
              Message 6 of 7 , May 13, 2011
              View Source
              • 0 Attachment
                --- In jslint_com@yahoogroups.com, "Cheney, Edward A SSG RES USAR USARC" <austin.cheney@...> wrote:

                > I do have one complaint/question. Why would you do this:
                >
                > var processTheForm;
                > processTheForm = function () {...
                >
                > Instead you could do this:
                > var processTheForm = function () {...
                >

                Two reasons:

                1) because I don't do the former... there were a number of names declared as variables.

                2) I don't like to clutter the list of variable declarations with assignments. While the interpreter allows it, I prefer to keep very distinct variable name declarations, and assignment of values.
              • Zhami
                I have been having an off-list conversation with someone who has helped me understand that my original problem statement may be opaque. The essence is this:
                Message 7 of 7 , May 13, 2011
                View Source
                • 0 Attachment
                  I have been having an off-list conversation with someone who has helped me understand that my original problem statement may be opaque. The essence is this:

                  The following is okay:

                  var a, b,
                  c, d;


                  The following generates a warning about the position of d:

                  var a,
                  c, d;
                Your message has been successfully submitted and would be delivered to recipients shortly.