On save new line added to end of file. How stop this? 关注
I did a search in the forum for this but did not get any results back. I looked in settings but there are so many I am not sure where to look.
When I save a file, PhpStorm adds a new line to the end of the file. How do I stop this from happening?
Let me add that if there is already a blank line at the end of the file it does not keep adding new lines. If there is NO blank line then when I save the file a new blank line is added. I actually want some files to have no blank line at the end.
Some tip first: If you do not know if some configuration option is available and where it located in Settings window, then use Search box in Settings window (the very first thing on left top corner) -- extremely helpful feature in such situations. If found nothing -- try to use another spelling/naming (sometimes the option can be named differently to what particular person may expect).
Back to your issue -- untick the following option: File | Settings | Editor --> Ensure blank line before end of file on Save
Try searching for "blank line" on Settings screen and see how it works.
You either enable it or disable it, it still adds that line on Windows 7 / Windows 10 and Ubuntu 14 machines. Why is that??
Works just fine here. Don't know other options that could do such thing (unless some another tool/plugin does it).
The only thing I can think of ... 1) do you have .editorconfig files in this project?.. and 2) Do you have EditorConfig Support plugin installed? Settings from such file will override similar option from IDE Settings/Preferences (the nature of such files).
That was it, thank you kindly @Andriy Bazanov!
I was hating Webstorm for a while now for this "hidden bug". Someone commited some editor configuration in our repository and that broke it up.
Thank you kindly!
In PHP Storm 2018.2.5
File | Settings | Editor | General --> Other ---> Ensure line feed at file end on Save
Note that the Editorconfig plugin may override this setting if you .editorconfig file has:
FYI i tried finding this with the search bar in preferences and couldn't find it, that's why I came here. I searched newline, \n, and end of file. I didn't think about searching 'trailing space' or 'blank space'. Might be nice to be able to find it with 'newline' or 'end of file' as search params. would have saved me the search. Thanks for helping me find it though!
There is an entire section about new lines in php, this one is missing.
The setting is unsearchable. In general phpstorm settings are hard to work with..
i tried the same thing, the only thing that really work was edit the .editorconfig file changing the key insert_final_newline to false
So you had it set to TRUE before? In such case it's expected behaviour: settings from .editorconfig file will take over the IDE own settings (the whole nature of such file).
So you either:
They messed with this again and it is still not searchable (not even if you search for the exact text).
Ba Grootjen, the settings entries' names are not indexed as they are but rather by keywords, a query like "save file line break" finds the settings item.
If you want your files to be actual files according to POSIX standards, they need a line ending at the end of the file.
Note, however, that a single newline at the end of the file makes Storm make it look like there is a blank line at the end of the file. Use a hex editor to confirm that there is only a single newline at the end of the file. Maybe a better solution would be a gutter icon or a visual endOfFileNewLine character
This bug is STILL present in Windows. I had both unchecked 'Remove trailing blank lines at the end of saved files' and 'Ensure every saved file ends wit ha line break'. I'm using git-secret and it keeps adding newlines to the end of my secrets which makes them invalid.
A bug? Unlikely TBH.
Do you have .editorconfig in your project (or a folders above it)? Settings from here will override the IDE settings (the nature of such files).
If you have it and it has a rule for new lines at the end of the file then just add a rule to not to add it for your git-secret files.
It's definitely not a bug if a newline is added a the end of files.
Text files only follow the POSIX standard for text files if their very last character before the EOF is an EOL (normally newline) character. Files that do not follow that standard simply are not actually POSIX standard text files.
However, I have to re-enable "follow the standard ffs" setting whenever I reinstall a JetBrains IDE, because of threads like this one.