Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

remove trailing whitespace from Knockout code #260

Merged
merged 13 commits into from

2 participants

@mbest
Collaborator

I have my editor set to remove trailing whitespace, but when I'm working with Knockout code, I turn it off so that I don't "edit" random parts of the code. But if all the code already had the trailing space removed, I wouldn't have to worry about this.

@SteveSanderson

Sure, I'm happy to do this. I propose leaving this to be the last thing done before v2.1.0 is finalized, because otherwise it might lead to more merge conflicts with other outstanding pull requests.

@mbest
Collaborator

Yeah, makes sense to wait.

I was also thinking of having the build script check for any files with trailing spaces. On linux, the grep command can do this well:

cd ..
grep -rl ' $' build spec src | grep -v ".exe$"

And on Windows, findstr:

cd ..
findstr -rsm -c:" $" * |findstr -rv "^.git" |findstr -rv ".exe$"
@mbest mbest referenced this pull request
Closed

2.1 release discussion #338

@SteveSanderson

Great stuff, but is there any chance of factoring the new "check for trailing spaces" logic out into separate scripts in the tools subfolder? Just because the build scripts are now getting big enough to need some management of their own.

Tomorrow I'll go through all the files with trailing spaces and remove those trailing spaces.

@mbest
Collaborator

Great stuff, but is there any chance of factoring the new "check for trailing spaces" logic out into separate scripts in the tools subfolder?

I'll look into doing that.

@SteveSanderson

Thanks for factoring the whitespace checks out. I've now normalised all the files to eliminate trailing whitespace, and along the way, adapted the build scripts so they will actually fail (refusing to build) if you have unwanted whitespace.

Note that I've eliminated trailing whitespace only from lines that aren't pure whitespace. So:

function somefunc() {
    // The following line is not allowed to have trailing whitespace
    var i = 1;
    // But the following blank line is pure whitespace so it doesn't need to be trimmed. Both Sublime Text and VS put in whitespace to match the current indentation level, so we should allow this.

    return i;
}

What do you think? It's ready to merge as far as I'm concerned. Let me know if you prefer me to do the merge.

@mbest
Collaborator

findstr -rsm -c:"[^ ][ ]$" *.js *.html *.css *.bat *.ps1 > build\%OutTrailingSpaceListFile% works for me in Windows. I don't think we need the extra script step.

Collaborator

Actually I needed [^ ][ ][ ]*$ to match more than one space.

@mbest
Collaborator

Both Sublime Text and VS put in whitespace to match the current indentation level, so we should allow this.

As far as I know, all editors that trim trailing white-space do so on blank lines also. Maybe we can allow them, but have the normalization script strip them.

mbest and others added some commits
@SteveSanderson

Ah, turns out I was wrong - sorry! Sublime Text does not use whitespace to match indentation on blank lines by default. Visual Studio is the only editor I know of that does.

With that in mind, shall we just go with the no-trailing-whitespace-anywhere rule, like you originally suggested? I'd prefer to establish just one standard (both for normalisation and for builds) because otherwise the commit log will get polluted by "I ran the normaliser" commits that merely remove whitespace.

I know people who use VS will still submit pull requests that contain whitespace on blank lines, but we can just politely normalise the changes as part of the merge... :)

@SteveSanderson

Well found! I tried about a dozen ways of expressing this regex - none of which were supported by findstr - but I didn't try that one.

Though now if we trim trailing whitespace everywhere, we won't actually need this anyway. Looks like I wasted a lot of time yesterday :(

@SteveSanderson

Ready to merge now as far as I'm concerned. Again, if you prefer me to do the merge, let me know.

@mbest mbest merged commit cbfc4b9 into master
@mbest
Collaborator

Merged. I just found out that you can add w=1 to a commit URL in Github to see only the significant (non whitespace) changes. So here the merge commit showing only the code changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 27, 2012
  1. @mbest
Commits on Apr 11, 2012
  1. @mbest
Commits on Apr 13, 2012
  1. @SteveSanderson
  2. @SteveSanderson
  3. @SteveSanderson

    All files now have trailing linebreak (which is good, because they ge…

    SteveSanderson authored
    …t concatenated together during build)
  4. @SteveSanderson
  5. @SteveSanderson
  6. @SteveSanderson

    Only strip trailing whitespace from lines that aren't purely whitespa…

    SteveSanderson authored
    …ce (as the gaps within an indented block of code contain valid whitespace-only lines)
  7. @SteveSanderson
  8. @SteveSanderson

    Build scripts should allow lines that are purely whitespace (but not …

    SteveSanderson authored
    …non-whitespace with trailing whitespace)
  9. @mbest

    Change check scripts so they work exactly the same. Change normaliseA…

    mbest authored
    …llFiles.ps1 to strip all trailing spaces (even on blank lines).
Commits on Apr 14, 2012
  1. @SteveSanderson

    Amend build checks to disallow trailing whitespace on blank-only line…

    SteveSanderson authored
    …s (so there is now one consistent standard both for normalisation and for build)
  2. @SteveSanderson
Something went wrong with that request. Please try again.