How to deal with trailing spaces on my files

Pre-commit failed here:

[trailing-whitespace] Trim Trailing Whitespace…Failed

I’m rewrriten the code so many times and i dont know what happend.

You can watch the job console here: Job #376848839

And the commit: Commit 47b3175d

Thanks.

Hi
Any research on your side? Tell us
What did you rewrite, exactly?
You can always check previous posts

Please change the post title to something related to the issue you are having. As @roaring-lamport said, there are already existent posts addressing this issue, so make a research in this forum before opening new posts :wink:

1 Like

Of course!. Im search in many sites and the error is for white spaces in somewhere part of code.

I’m rewrited the code, and commit message, in search of a white space.
But i can’t find something

Yeah, im searched someone solution in the forum, but i installed pre-commit in my computer and returned ok in[trailing-whitespace] Trim Trailing Whitespace…Failed ;(.

I will send you a screenshot.

This return in my computer. But in gitlab failed.

Did you commit the changes after pre-commit modified your files?

Yes i do. This is the last commit that i submitted to gitlab.

Try checking you have no ending spaces on every line, e.g. 'line of code ’ instead of ‘line of code’. Check it, even for blank lines and comments.

Yes in my despair i send the code, commitmessage and OTHERS.list in this site: https://www.textfixer.com/tools/remove-white-spaces.php but nothing works

It seems this tools only removes extra whitespaces this way: ‘line of’ + ’ ’ * n + ‘code’ -> 'line of code ', but the documentation doesn’t seem it deletes trailing whitespaces, just takes a sucession of spaces and reduces it to only one space.

I have eventually checked my code over and over again. But i can’t find something.

Try this:

$ pre-commit run --all-files
$ git add -A
$ git commit --no-verify -m "whitespace fix"
$ git rebase -i @~2

replace pick for f in the fix commit, after that:

$ git push origin yourbranch

Check line 41, as an example, this is a blank line, but check the whitespaces on this line. Same on 51.

Ready. i pushed the commit to gitlab. I find a hook that can help me. I’m gonna try.

Git shows trailing whitespace as red blocks, try checking that out (git log -p).
Also make sure the branches and commits match locally vs remote.

Hi there @orange-knight

Maybe is the editor you are using… I had similar problems but they were because once I saved my file (cntrl+s), it automatically added a space to the end of line and also added a new line on my code.
So I would recommend you to search how to remove the trailing whitespace with your editor, that way you don’t have to bother about that anymore…

For example on atom, there is a package named Whitespace and there is an option to remove them:

Oh my god! This exist? fangirl scream Thanks, i gonna try.

Checked out your branch. Seems you have several issues you might look into:

  1. You seem to have Windows line-changes. Git should be able to handle that, though.
  2. You are more than commit ahead of master. That should fail in a different check, but is still worth fixing now, rather than later.
  ~/training $ git log --oneline
    da44dbc4d (HEAD, origin/sebasbeleno) sol(code): #0 codeabbey, 28 (3.74)
    25375f9a8 whitespace fix
    5987c8637 sol(code): #0 codeabbey, 28 (3.74)
    bcb76898f (origin/master, origin/HEAD, master) sol(hack): #0 hack-chall, javascript-4 (easy)
    b3e241a3f sol(code): #0 codefights, smallest (medium)
  1. You are modifying a ton of files, why?
commit 25375f9a83cc7683bacade0055cdb98ebf0cd257
Author: Sebastian Beleño <sebasbeleno15@gmail.com>
Date:   Thu Dec 12 10:23:25 2019 -0500

    whitespace fix

M       .git-hooks/checkstyle/sun_checks.xml
M       .git-hooks/checkstyle/xsl/checkstyle-author.xsl
M       .git-hooks/checkstyle/xsl/checkstyle-csv.xsl
M       .git-hooks/checkstyle/xsl/checkstyle-frames.xsl
M       .git-hooks/checkstyle/xsl/checkstyle-noframes-severity-sorted.xsl
M       .git-hooks/checkstyle/xsl/checkstyle-noframes.xsl
M       COPYRIGHT.txt
M       LICENSE.txt
M       TODO.asc
....
1 Like

Thanks everybody that help me!

For someone that can have the same problem, that i do is:

  1. Save the code in somewhere.
  2. Deleted my branch in remote and local git.
  3. With the master, re-created your branch.
  4. Use this hook for pre-commit: https://gist.github.com/jonatasnona/4131217
  5. Install this extention for VS code: Extention
  6. Check the whitespace’s with the extention.
  7. git push!

Thanks again!.