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

Re: [jslint] Re: option.indent

Expand Messages
  • Jim Auldridge
    I am a little confused. The code in this pastie: http://pastie.textmate.org/1482985 Gives this error: Problem at line 2 character 1: Expected exactly one
    Message 1 of 17 , Jan 20, 2011
    • 0 Attachment
      I am a little confused.

      The code in this pastie: http://pastie.textmate.org/1482985

      Gives this error: "Problem at line 2 character 1: Expected exactly one space
      between ')' and '{'."

      Indent is set to 0 and strict whitespace is not checked. Should this error
      be displayed with such settings?

      Thanks for any clarification that can be offered,
      Jim


      On Thu, Jan 20, 2011 at 8:35 PM, Douglas Crockford <douglas@...>wrote:

      >
      >
      > --- In jslint_com@yahoogroups.com <jslint_com%40yahoogroups.com>, "Merlin"
      > <g7awz@...> wrote:
      > >
      > > var a,
      > > b,
      > > c,
      > > d;
      >
      > > Why does JSLint not complain about line 2?
      >
      > Thanks. Please try it now.
      >
      >
      >



      --
      Jim Auldridge
      11012 Lincoln Ave
      Hagerstown MD 21740
      240.520.0240 (m)
      auldridgej@...
      http://jaaulde.com


      [Non-text portions of this message have been removed]
    • Merlin
      ... That is now corrected - thanks. var a, b, c; if ((a === b) && (b !== c)) { // ( at 5, ident set to 4 alert( fred ); } Assuming that the above is the
      Message 2 of 17 , Jan 21, 2011
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...> wrote:
        >
        > --- In jslint_com@yahoogroups.com, "Merlin" <g7awz@> wrote:
        > >
        > > var a,
        > > b,
        > > c,
        > > d;
        >
        > > Why does JSLint not complain about line 2?
        >
        > Thanks. Please try it now.
        >

        That is now corrected - thanks.

        var a, b, c;
        if ((a === b) &&
        (b !== c)) { // '(' at 5, ident set to 4
        alert("fred");
        }

        Assuming that the above is the correct form, why is this also accepted?

        var a, b, c;
        if ((a === b) &&
        (b !== c)) { // '(' at 9, ident set to 4
        alert("fred");
        }

        Is this a bug?
      • Merlin
        From json2.js: /*global text, reviver, walk */ var j; if (/^[ ],:{} s]*$/ .test(text.replace(/ (?:[ /bfnrt]|u[0-9a-fA-F]{4})/g, @ )
        Message 3 of 17 , Jan 21, 2011
        • 0 Attachment
          From json2.js:

          /*global text, reviver, walk */

          var j;
          if (/^[\],:{}\s]*$/
          .test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
          .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
          .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
          j = eval('(' + text + ')');
          return typeof reviver === 'function' ?
          walk({'': j}, '') : j;
          }

          Why are .test etc at 9 and not at 5? Ident = 4.
        • walfisch1
          indent: 0 If set in webinterface it does the job as descriped in instructions ( If 0, then no indentation checking takes place. ) If written as comment at the
          Message 4 of 17 , Jan 21, 2011
          • 0 Attachment
            indent: 0

            If set in webinterface it does the job as descriped in instructions ("If 0, then no indentation checking takes place.")

            If written as comment at the head of the code (/*jslint indent: 0 */), it throws the following error:
            "Problem at line 1 character 18: Expected a small integer and instead saw '0'."
          • Merlin
            ... My error: My question should have been: Why is .test allowed at 9. Indent =4. The .replace lines are continuations of the .test line and so are
            Message 5 of 17 , Jan 21, 2011
            • 0 Attachment
              --- In jslint_com@yahoogroups.com, "Merlin" <g7awz@...> wrote:
              >
              > From json2.js:
              >
              > /*global text, reviver, walk */
              >
              > var j;
              > if (/^[\],:{}\s]*$/
              > .test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
              > .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
              > .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
              > j = eval('(' + text + ')');
              > return typeof reviver === 'function' ?
              > walk({'': j}, '') : j;
              > }
              >
              > Why are .test etc at 9 and not at 5? Ident = 4.
              >

              My error: My question should have been:

              Why is '.test' allowed at 9. Indent =4.
              The '.replace' lines are continuations of the '.test' line and so are correctly placed at 9.
            • Douglas Crockford
              ... Thanks. Please try it now.
              Message 6 of 17 , Jan 21, 2011
              • 0 Attachment
                --- In jslint_com@yahoogroups.com, "walfisch1" <christian.wirkus@...> wrote:

                > If written as comment at the head of the code (/*jslint indent: 0 */), it throws the following error:
                > "Problem at line 1 character 18: Expected a small integer and instead saw '0'."


                Thanks. Please try it now.
              • Merlin
                ... /*global date */ var lookFor = /^( d{4}) -( d{2}) -( d{2})T( d{2}) :( d{2}) :( d{2})Z$/, found = date.match(lookFor), year, month, day, hours, mins, secs;
                Message 7 of 17 , Jan 21, 2011
                • 0 Attachment
                  --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...> wrote:
                  >
                  > JSLint is once again looking at indentation when option.indent contains a number that is greater than zero.
                  >
                  > It uses an enhanced K&R style, in which {} pairs, [] pairs, or () pairs can be opened by placing a line break after the opening character. So the open style can be used on blocks, object literals, array literals, subscripts, parameter lists, argument lists, control sections, and expressions.
                  >
                  > Indentation and script white space are now completely independent.
                  >

                  /*global date */
                  var lookFor = /^(\d{4})\-(\d{2})\-(\d{2})T(\d{2})\:(\d{2})\:(\d{2})Z$/,
                  found = date.match(lookFor), year, month,
                  day, hours, mins, secs;
                  /*
                  Error:
                  Problem at line 4 character 34: Expected 'year' at column 5, not column 34.
                  found = date.match(lookFor), year, month,

                  Problem at line 4 character 40: Expected 'month' at column 5, not column 40.
                  found = date.match(lookFor), year, month,

                  Problem at line 5 character 10: Expected 'hours' at column 5, not column 10.
                  day, hours, mins, secs;

                  Problem at line 5 character 17: Expected 'mins' at column 5, not column 17.
                  day, hours, mins, secs;

                  Problem at line 5 character 23: Expected 'secs' at column 5, not column 23.
                  day, hours, mins, secs;
                  */

                  /*global date, lookFor */

                  var found = date.match(lookFor), year, month,
                  day, hours, mins, secs;

                  // is OK

                  What is the rule, please?
                • Douglas Crockford
                  ... If it sees the second variable name at the start of a new line, it assumes that you want to list the names in the open format. So you can use the open form
                  Message 8 of 17 , Jan 21, 2011
                  • 0 Attachment
                    --- In jslint_com@yahoogroups.com, "Merlin" <g7awz@...> wrote:
                    >
                    > --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@> wrote:
                    > >
                    > > JSLint is once again looking at indentation when option.indent contains a number that is greater than zero.
                    > >
                    > > It uses an enhanced K&R style, in which {} pairs, [] pairs, or () pairs can be opened by placing a line break after the opening character. So the open style can be used on blocks, object literals, array literals, subscripts, parameter lists, argument lists, control sections, and expressions.
                    > >
                    > > Indentation and script white space are now completely independent.
                    > >
                    >
                    > /*global date */
                    > var lookFor = /^(\d{4})\-(\d{2})\-(\d{2})T(\d{2})\:(\d{2})\:(\d{2})Z$/,
                    > found = date.match(lookFor), year, month,
                    > day, hours, mins, secs;
                    > /*
                    > Error:
                    > Problem at line 4 character 34: Expected 'year' at column 5, not column 34.
                    > found = date.match(lookFor), year, month,
                    >
                    > Problem at line 4 character 40: Expected 'month' at column 5, not column 40.
                    > found = date.match(lookFor), year, month,
                    >
                    > Problem at line 5 character 10: Expected 'hours' at column 5, not column 10.
                    > day, hours, mins, secs;
                    >
                    > Problem at line 5 character 17: Expected 'mins' at column 5, not column 17.
                    > day, hours, mins, secs;
                    >
                    > Problem at line 5 character 23: Expected 'secs' at column 5, not column 23.
                    > day, hours, mins, secs;
                    > */
                    >
                    > /*global date, lookFor */
                    >
                    > var found = date.match(lookFor), year, month,
                    > day, hours, mins, secs;
                    >
                    > // is OK
                    >
                    > What is the rule, please?

                    If it sees the second variable name at the start of a new line,
                    it assumes that you want to list the names in the open format.
                    So you can use the open form


                    ` var lookFor = /^(\d{4})\-(\d{2})\-(\d{2})T(\d{2})\:(\d{2})\:(\d{2})Z$/,
                    ` found = date.match(lookFor),
                    ` year,
                    ` month,
                    ` day,
                    ` hours,
                    ` mins,
                    ` secs;

                    or the closed form

                    ` var lookFor = /^(\d{4})\-(\d{2})\-(\d{2})T(\d{2})\:(\d{2})\:(\d{2})Z$/, found =
                    ` date.match(lookFor), year, month, day, hours, mins, secs;
                  • urangatang@att.net
                    ... In K&R style, the opening brace should not appear in the same line of a function declaration, correct? JSLint does seem to accept that at the moment. The
                    Message 9 of 17 , Jan 21, 2011
                    • 0 Attachment
                      --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...> wrote:
                      > It uses an enhanced K&R style, in which {} pairs, [] pairs, or () pairs can be opened by placing a line break after the opening character. So the open style can be used on blocks, object literals, array literals, subscripts, parameter lists, argument lists, control sections, and expressions.


                      In K&R style, the opening brace should not appear in the same line of a function declaration, correct? JSLint does seem to accept that at the moment.

                      The following code produces three errors:

                      function a()
                      {
                      ____var b;
                      }


                      Problem at line 3 character 5: Expected 'var' at column 9, not column 5.

                      var b;

                      Problem at line 3 character 9: Expected 'b' at column 13, not column 9.

                      var b;

                      Problem at line 4 character 1: Expected '}' at column 5, not column 1.

                      }
                    • Merlin
                      ... Thanks - now I understand. I noticed also that the maxerr and indent settings are now unconditionally displayed in the jslint string, as in /*jslint
                      Message 10 of 17 , Jan 21, 2011
                      • 0 Attachment
                        --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...> wrote:
                        > If it sees the second variable name at the start of a new line,
                        > it assumes that you want to list the names in the open format.
                        > So you can use the open form
                        >
                        > ` var lookFor = /^(\d{4})\-(\d{2})\-(\d{2})T(\d{2})\:(\d{2})\:(\d{2})Z$/,
                        > ` found = date.match(lookFor),
                        > ` year,
                        > ` month,
                        > ` day,
                        > ` hours,
                        > ` mins,
                        > ` secs;
                        >
                        > or the closed form
                        >
                        > ` var lookFor = /^(\d{4})\-(\d{2})\-(\d{2})T(\d{2})\:(\d{2})\:(\d{2})Z$/, found =
                        > ` date.match(lookFor), year, month, day, hours, mins, secs;
                        >

                        Thanks - now I understand.

                        I noticed also that the maxerr and indent settings are now unconditionally displayed in the jslint string, as in

                        /*jslint maxerr: 50, indent: 4 */

                        I'll do likewise in Widget Tester.
                      • abyssoft@ymail.com
                        I used /**/ to represent the 4 spaces, due to no way to do CODE or PRE tags. /* Given */ /*jslint strict: true, white: true, browser: true, devel: true,
                        Message 11 of 17 , Jan 21, 2011
                        • 0 Attachment
                          I used /**/ to represent the 4 spaces, due to no way to do CODE or PRE tags.


                          /* Given */
                          /*jslint strict: true, white: true, browser: true, devel: true, windows: true, sub: true, undef: true */
                          /*jslint nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, immed: true */
                          /*jslint maxerr: 50, indent: 4 */

                          (
                          /**/function me() {
                          /**//**/"use strict";
                          /**/}()
                          );

                          results in

                          Problem at line 7 character 5: Expected 'function' at column 9, not column 5.

                          /**/function me() {
                        • Douglas Crockford
                          ... ( ````function me() { ```````` use strict ; ````}() ); results in Problem at line 7 character 5: Expected function at column 9, not column 5. Thanks.
                          Message 12 of 17 , Jan 21, 2011
                          • 0 Attachment
                            --- In jslint_com@yahoogroups.com, "abyssoft@..." <abyssoft@...> wrote:

                            (
                            ````function me() {
                            ````````"use strict";
                            ````}()
                            );

                            results in

                            Problem at line 7 character 5: Expected 'function' at column 9, not column 5.



                            Thanks. Please try it now.
                          • abyssoft@ymail.com
                            Tested and Fixed, Thank you.
                            Message 13 of 17 , Jan 21, 2011
                            • 0 Attachment
                              Tested and Fixed,
                              Thank you.

                              --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...> wrote:
                              >
                              > --- In jslint_com@yahoogroups.com, "abyssoft@" <abyssoft@> wrote:
                              >
                              > (
                              > ````function me() {
                              > ````````"use strict";
                              > ````}()
                              > );
                              >
                              > results in
                              >
                              > Problem at line 7 character 5: Expected 'function' at column 9, not column 5.
                              >
                              >
                              >
                              > Thanks. Please try it now.
                              >
                            Your message has been successfully submitted and would be delivered to recipients shortly.