Atom / Github removing end-of-file newline - github

Using Atom 1.14.3, I have whitespace package that handles auto-inserting newlines at the end of files.
Even if I delete the end newline and hit save, it re-adds the newline. This is good.
Whitespace package configuration seems to be okay:
The problem is, when I commit to Github, it says the newline has been removed:
Why is this? Is it an Atom issue, or a potential local github setting issue?
EDIT: somehow, I needed to disable whitespace package, manually add two CRLF at the end of the file, and then commit for Github to pick up the single CRLF at the end of the file.

I think you might be misunderstanding where the newlines are.
Let's look at your two screenshots, and where the newlines are in each.
233 return router;\n
234 };\n
Here we have 234 as the last line in the file. We have a line 235 displayed, but that is because the newline on 234 creates the next line for your editor cursor to be on. If you started typing on 235, you'd be creating more content. But right now, 235 is an empty line (including having no terminating newline).
233 return router;\n
234 };\n
235 \n
This is similar except it also has an empty line 235 that ends with a newline. Now the newline-less empty input line has moved to 236.
When you saved with the whitespace package active, it removed extraneous newlines at the end of the file, leaving only one. As in the first screenshot. However, when you look at the Github diff, things are little different. Github is showing you the file contents, not in an editor. So there is no reason to have the phantom last line for your cursor. Instead, it shows you the simple truth of the matter: line 234 is the last line in the file. Line 235 is now gone.
Let's take a look at the settings for the whitespace package. Specifically the first setting:
Ensure Single Trailing Newline
If the buffer doesn't end with a newline character when it's saved, then append one. If it ends with more than one newline, remove all but one. To disable/enable for a certain language, use syntax-scoped properties in your config.cson.
Here are the first two sentences of the description again, with some emphasis added:
If the buffer doesn't end with a newline character when it's saved, then append one. If it ends with more than one newline, remove all but one.

Related

Is there a way to fix SwiftLint's trailing whitespace violation?

I have a method that has has a closing bracket at line 20, I want my next method to start at line 23 because I want line 22 to have a comment. This will leave line 21 to have the one space between these two methods, but because line 22 is a comment SwiftLint will throw a "Trailing Whitespace Violation". Is there any way to fix this?
Trailing whitespace violation doesn't mean that there is an empty line, but rather that there is some unnecessary whitespace (not linebreaks, but tabs/spaces).
You can automatically fix trailing whitespacing by turning on the relevant feature in Xcode. You can find it in Xcode Preferences: Text Editing/Editing/While editing, turn on both "Automatically trim trailing whitespace" and "Including whitespace-only lines".

How to prevent line breaks (general)

I'm writing a text on C++. But often the line breaks after the first "+", so I get C+
+
This is just an example. How can I prevent line breaking of arbitrary parts in my odt doc?
There is no formatting option at the moment
Use the Unicode Character U+2060. Insert it an every point the line breaks, but it shouldn't. It glues two parts together.
Example for "C++" ( | represents the text cursor )
C|++
Press Ctrl+Shift+U
u will appear on the screen
Type in 2060
Press Enter
Now the line won't break between C and +.
Move cursor: C+|+
repeat process

How do you delete lines with certain keywords in VScode

I have this regular expression to find certain keywords on a line:
.*(word1|word2|word3).*
In the find and replace feature of the latest VSCode it works ok and finds the words but it just blanks the lines leaving big gaps in-between.
I would like to delete the entire line including linefeed.
The find and replace feature doesnt seem to support reg exp in the replace field.
If you want to delete the entire line make your regex find the entire line and include the linefeed as well. Something like:
^.*(word1|word2|word3).*\n?
Then ALT-Enter will select all lines that match and Delete will eliminate them including the lines they occupied.

Regex to delete all empty lines whatsoever?

In Windows 10 I use a text editor (I'd like not to point out a particular one but I usually use Visual Studio Code AKA "VSCODE").
I need a way to delete all blank lines whatsoever only with regex after I matched them with this code:
^\s*$
After I match the lines themselves, how is it possible to delete the lines?
AFAIK, regex only edit lines, not deleting lines or adding lines.
I desire a way to delete all matched (empty).
Hitting "Enter" or "Delete" in the empty "replace" box doesn't delete lines:
You were close. You were missing the new line character in your regex. This worked for me:
^\s*$\n
Without the newline character, you are matching the blank line itself which you then replace with nothing but you've left the newline character so it still leaves an empty line in place.

How to remove trailing whitespace *from selection* in Eclipse

The question is as simple as stated in the title - how to remove the whitespace in Eclipse, but only from the selected lines.
There are a lot of answers on SO how to remove trailing whitespace in Eclipse. Most of them focus on automatically removing it on save and all of them concern removing all of the trailing whitespace in the file.
I want none of these, as I am working on large JS files that are awfully formatted and very frequently committed; removing all the trailing whitespaces in the file would easily cause merge conflicts and a lot of noise from the people.
So I want to select specific parts of the files and fix them, in the way that this is possible with Source -> Format (Alt+Shift+F).
Shift-Ctrl-Right arrow will highlight whitespace to the right until next non-whitespace character (which may be newline). Press delete. If you lose the newline, simply press enter.