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

Mixed tabs and spaces in comments

Expand Messages
  • Rob Richardson
    JSLint highlights this as a problem: /* * My Library Descriptive Comment * some descriptive content here */ with a message about mixed tabs and spaces
    Message 1 of 5 , Oct 19, 2010
    • 0 Attachment
      JSLint highlights this as a problem:

      /*
      * My Library Descriptive Comment
      * some descriptive content here
      */

      with a message about mixed tabs and spaces because there's a space before
      the star char and a tab after it.

      It seems fair to say that

      /* anything in here */

      and

      // anything after this

      is irrelevant to validation.

      Rob
    • Douglas Crockford
      ... Mixing tabs and space is an indication of an editing problem. Pick one or the other and use it consistently. Fix your code.
      Message 2 of 5 , Oct 20, 2010
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "Rob Richardson" <erobrich@...> wrote:
        >
        > JSLint highlights this as a problem:
        >
        > /*
        > * My Library Descriptive Comment
        > * some descriptive content here
        > */
        >
        > with a message about mixed tabs and spaces because there's a space before
        > the star char and a tab after it.
        >
        > It seems fair to say that
        >
        > /* anything in here */
        >
        > and
        >
        > // anything after this
        >
        > is irrelevant to validation.

        Mixing tabs and space is an indication of an editing problem.
        Pick one or the other and use it consistently. Fix your code.
      • Cheney, Edward A SSG RES USAR
        ... It is also an indication that more than one person, each with different editing styles, has been in that file. You cannot force your peers to do exactly
        Message 3 of 5 , Oct 20, 2010
        • 0 Attachment
          > Mixing tabs and space is an indication of an editing problem.
          > Pick one or the other and use it consistently. Fix your code.

          It is also an indication that more than one person, each with different editing styles, has been in that file. You cannot force your peers to do exactly as you do for no reason beyond OCD. I recommend using a beautifier or an automated method of converting white space characters from one form to the other:

          x.replace(/\s/g, " ");

          or

          x.replace(/\s/g, "y"); //Where the y is a literal tab character pasted in.

          Austin Cheney - CISSP
          http://prettydiff.com/
        • pauanyu
          ... Just one nitpick: s will replace all whitespace, including newlines. You probably want something more like this: x.replace(/ t/g, ); x.replace(/
          Message 4 of 5 , Oct 20, 2010
          • 0 Attachment
            --- In jslint_com@yahoogroups.com, "Cheney, Edward A SSG RES USAR" <austin.cheney@...> wrote:
            >
            >
            > > Mixing tabs and space is an indication of an editing problem.
            > > Pick one or the other and use it consistently. Fix your code.
            >
            > It is also an indication that more than one person, each with different editing styles, has been in that file. You cannot force your peers to do exactly as you do for no reason beyond OCD. I recommend using a beautifier or an automated method of converting white space characters from one form to the other:
            >
            > x.replace(/\s/g, " ");
            >
            > or
            >
            > x.replace(/\s/g, "y"); //Where the y is a literal tab character pasted in.
            >
            > Austin Cheney - CISSP
            > http://prettydiff.com/
            >

            Just one nitpick: \s will replace all whitespace, including newlines. You probably want something more like this:

            x.replace(/\t/g, " ");

            x.replace(/ {4}/g, "\t");
          • Harry Whitfield
            The problem of dealing with the many issues surrounding the tab character arose in the early days of computers. I remember first having to deal with it in the
            Message 5 of 5 , Oct 24, 2010
            • 0 Attachment
              The problem of dealing with the many issues surrounding the tab character arose
              in the early days of computers. I remember first having to deal with it in the
              mid sixties. Kernighan and Plauger discussed various solutions to the problem in
              their Software Tools book, which was first published in 1976.

              I do not wish to engage in the "religious war" which surrounds this issue, and
              suspect that I may be cast into outer darkness for the following comments.

              I program in JavaScript and make frequent use of JSLint. Most of the time, I
              edit code files using the BBEdit text editor on a Macintosh. This can be
              configured to have tabstops at fixed character intervals (by default 4) and
              facilitates use of files which contain both tab and space characters.

              In editing files, my main concern is to make the layout/indentation look correct
              on the screen, no matter whether that has been achieved with tabs or spaces or a
              mixture of both. I can't easily tell whether the desired layout has been
              achieved with tabs or spaces and I really don't want to have to care.

              BBEdit has commands to detab and entab text files, so I could easily produce a
              file without tabs to use as input to JSLint or to make available to other users.

              However, most of the time I do not need to detab files as a very simple wrapper
              to JSLint does all that is needed.

              In my Widget Tester Widget, I make use of an unmodified version of JSLint
              maintained by Douglas at http://www.JSLint.com/jslint.js which is a minified
              version of fulljslint.js.

              In addition to preferences to set the standard JSLint options, there is an
              additional preference to set a tabstops option:
              <preference name="tabstops" group="Operation" defaultValue="4"
              title="Tab-stop Interval:" type="popup"
              description="Specify the tab-stop interval (default is 4). Select 0 for standard JSLint behavior."
              >
              <option>0</option>
              <option>1</option>
              <option>2</option>
              <option>3</option>
              <option>4</option>
              <option>5</option>
              <option>6</option>
              <option>7</option>
              <option>8</option>
              </preference>

              This is similar to the standard indent option:
              <preference name="indent" group="Operation" defaultValue="4"
              title="Indentation:" type="popup"
              description="Number of spaces in a properly formatted block indentation."
              >
              <option>0</option>
              <option>1</option>
              <option>2</option>
              <option>3</option>
              <option>4</option>
              <option>5</option>
              <option>6</option>
              <option>7</option>
              <option>8</option>
              </preference>

              The code used in the wrapper to call JSLint on a text file takes the following form:

              function detab(data, tabspace) {
              var i, c, col = 0, out = "";
              for (i = 0; i < data.length; i += 1) {
              c = data[i];
              if (c === "\t") {
              do {
              out += " ";
              col += 1;
              } while ((col % tabspace) !== 0);
              } else if (c === "\n") {
              out += "\n";
              col = 0;
              } else {
              out += c;
              col += 1;
              }
              }
              return out;
              }

              function filesystem_readFile(path, asLines) {
              var tabstops = Number(preferences.tabstops.value), data;
              if (tabstops === 0) {
              return filesystem.readFile(path, asLines);
              }
              data = filesystem.readFile(path).replace(/\r\n?|\n/g, '\n');
              if (asLines) {
              return detab(data, tabstops).split('\n');
              }
              return detab(data, tabstops);
              }


              var theText = filesystem_readFile(theFilePath, true);
              var ok = JSLINT(theText, optionObject);


              Notes:
              filesystem.readFile(path, asLines) is the standard call used in Yahoo! Widgets
              to read a text file. If asLines is true the function returns an array of
              strings, one string per line, otherwise a single string including end-of-line
              characters

              The detab function converts tabs to the appropriate number of spaces.

              Setting the tabstops option to zero, passes the text unchanged to JSLint for the
              benefit of those who wish to have the standard JSLint behavior.

              The filesystem_readFile function also handles the various types of end-of-line
              character that can be used in BBEdit on the Macintosh, viz CR, CRLF and LF.

              The latest version of Widget Tester can be downloaded from http://tinyurl.com/5unocx .
              It can be unzipped to reveal all of the code.

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